diff --git a/.gitignore b/.gitignore index e7180d03..bdf6387f 100644 --- a/.gitignore +++ b/.gitignore @@ -233,6 +233,7 @@ _Pvt_Extensions .fake/ /KSFramework/Assets/Plugins/Editor/KEngineEditor /KSFramework/Assets/Plugins/KEngine +/KSFramework/Assets/Plugins/Slua_Managed /KSFramework/Library /KSFramework/Temp /KSFramework/*.csproj diff --git a/Install.bat b/Install.bat index b4cfba5a..c230d285 100644 --- a/Install.bat +++ b/Install.bat @@ -49,13 +49,14 @@ mkdir KSFramework\Assets\SLua\Editor xcopy slua\Assets\SLua\Editor\CustomEditor.cs KSFramework\Assets\SLua\Editor /S/Y/R/I xcopy slua\Assets\SLua\Editor\LuaCodeGen.cs KSFramework\Assets\SLua\Editor /S/Y/R/I +rmdir KSFramework\Assets\Plugins\Slua_Managed mklink /J KSFramework\Assets\Plugins\Slua_Managed slua\Assets\Plugins\Slua_Managed -xcopy slua\Assets\Plugins\Android KSFramework\Assets\Plugins\Android /S/Y/R/I -xcopy slua\Assets\Plugins\iOS KSFramework\Assets\Plugins\iOS /S/Y/R/I -xcopy slua\Assets\Plugins\slua.bundle KSFramework\Assets\Plugins\slua.bundle /S/Y/R/I -xcopy slua\Assets\Plugins\x64 KSFramework\Assets\Plugins\x64 /S/Y/R/I -xcopy slua\Assets\Plugins\x86 KSFramework\Assets\Plugins\x86 /S/Y/R/I +xcopy slua\Assets\Plugins\Android\* KSFramework\Assets\Plugins\Android /S/Y/R/I +xcopy slua\Assets\Plugins\iOS\* KSFramework\Assets\Plugins\iOS /S/Y/R/I +xcopy slua\Assets\Plugins\slua.bundle\* KSFramework\Assets\Plugins\slua.bundle /S/Y/R/I +xcopy slua\Assets\Plugins\x64\* KSFramework\Assets\Plugins\x64 /S/Y/R/I +xcopy slua\Assets\Plugins\x86\* KSFramework\Assets\Plugins\x86 /S/Y/R/I echo Finish! ping -n 5 127.0.0.1>nul diff --git a/Install.sh b/Install.sh new file mode 100644 index 00000000..5537664e --- /dev/null +++ b/Install.sh @@ -0,0 +1,55 @@ +# Submodule update +# git submodule update --recursive +SRC_ASSETS_PATH=$PWD/KEngine/KEngine.UnityProject/Assets +DST_ASSETS_PATH=$PWD/KSFramework/Assets +DST_PLUGIN_PATH=$PWD/KSFramework/Assets/Plugins/KEngine +DST_EDITOR_PATH=$PWD/KSFramework/Assets/Plugins/Editor/KEngineEditor + + +# Resources + +mkdir $DST_ASSETS_PATH/../Product/SettingSource +mkdir $DST_ASSETS_PATH/../Product/Bundles + +# Codes + +echo $SRC_ASSETS_PATH +echo $DST_PLUGIN_PATH + +mkdir $DST_PLUGIN_PATH 2>nul +rm $DST_PLUGIN_PATH/KEngine +ln -s $SRC_ASSETS_PATH/KEngine $DST_PLUGIN_PATH/KEngine +rm $DST_PLUGIN_PATH/KEngine.Lib +ln -s $SRC_ASSETS_PATH/KEngine.Lib $DST_PLUGIN_PATH/KEngine.Lib +rm $DST_PLUGIN_PATH/KEngine.UI +ln -s $SRC_ASSETS_PATH/KEngine.UI $DST_PLUGIN_PATH/KEngine.UI + +mkdir $DST_EDITOR_PATH 2>nul +rm $DST_EDITOR_PATH/KEngine.Editor +ln -s $SRC_ASSETS_PATH/KEngine.Editor/Editor $DST_EDITOR_PATH/KEngine.Editor +rm $DST_EDITOR_PATH/KEngine.EditorTools +ln -s $SRC_ASSETS_PATH/KEngine.EditorTools/Editor $DST_EDITOR_PATH/KEngine.EditorTools +rm $DST_EDITOR_PATH/KEngine.UI.Editor +ln -s $SRC_ASSETS_PATH/KEngine.UI.Editor/Editor $DST_EDITOR_PATH/KEngine.UI.Editor + +mkdir -p KSFramework/Assets/Plugins/libs/ 2>nul +cp -rf $SRC_ASSETS_PATH/Plugins/Android/libs/KEngine.Android.jar KSFramework/Assets/Plugins/Android/libs/KEngine.Android.jar + +# SLua +mkdir KSFramework/Assets/SLua +mkdir KSFramework/Assets/SLua/Resources +mkdir KSFramework/Assets/SLua/Editor +cp -rf slua/Assets/SLua/Editor/CustomEditor.cs KSFramework/Assets/SLua/Editor +cp -rf slua/Assets/SLua/Editor/LuaCodeGen.cs KSFramework/Assets/SLua/Editor + +rm -rf KSFramework/Assets/Plugins/Slua_Managed +ln -s $PWD/slua/Assets/Plugins/Slua_Managed KSFramework/Assets/Plugins/Slua_Managed + +cp -rf slua/Assets/Plugins/Android/* KSFramework/Assets/Plugins/Android +cp -rf slua/Assets/Plugins/iOS/* KSFramework/Assets/Plugins/iOS +cp -rf slua/Assets/Plugins/slua.bundle/* KSFramework/Assets/Plugins/slua.bundle +cp -rf slua/Assets/Plugins/x64/* KSFramework/Assets/Plugins/x64 +cp -rf slua/Assets/Plugins/x86/* KSFramework/Assets/Plugins/x86 + +echo Finish! + diff --git a/KEngine b/KEngine index e8a496a3..a57b64be 160000 --- a/KEngine +++ b/KEngine @@ -1 +1 @@ -Subproject commit e8a496a345d6cba93b9cb1cbce3e78af0944f4a9 +Subproject commit a57b64be0aaf4ca31ad5a7e470c404586ff0cd6d diff --git a/KSFramework/Assets/BundleEditing/UI/Login.unity b/KSFramework/Assets/BundleEditing/UI/Login.unity index a0a636e1..2e0c5d13 100644 --- a/KSFramework/Assets/BundleEditing/UI/Login.unity +++ b/KSFramework/Assets/BundleEditing/UI/Login.unity @@ -13,7 +13,7 @@ SceneSettings: --- !u!104 &2 RenderSettings: m_ObjectHideFlags: 0 - serializedVersion: 6 + serializedVersion: 7 m_Fog: 0 m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1} m_FogMode: 3 @@ -37,12 +37,12 @@ RenderSettings: m_ReflectionIntensity: 1 m_CustomReflection: {fileID: 0} m_Sun: {fileID: 0} + m_IndirectSpecularColor: {r: 0, g: 0, b: 0, a: 1} --- !u!157 &4 LightmapSettings: m_ObjectHideFlags: 0 - serializedVersion: 6 + serializedVersion: 7 m_GIWorkflowMode: 1 - m_LightmapsMode: 1 m_GISettings: serializedVersion: 2 m_BounceScale: 1 @@ -53,17 +53,22 @@ LightmapSettings: m_EnableBakedLightmaps: 1 m_EnableRealtimeLightmaps: 0 m_LightmapEditorSettings: - serializedVersion: 3 + serializedVersion: 4 m_Resolution: 1 m_BakeResolution: 50 m_TextureWidth: 1024 m_TextureHeight: 1024 + m_AO: 0 m_AOMaxDistance: 1 - m_Padding: 2 m_CompAOExponent: 0 + m_CompAOExponentDirect: 0 + m_Padding: 2 m_LightmapParameters: {fileID: 0} + m_LightmapsBakeMode: 1 m_TextureCompression: 0 + m_DirectLightInLightProbes: 1 m_FinalGather: 0 + m_FinalGatherFiltering: 1 m_FinalGatherRayCount: 1024 m_ReflectionCompression: 2 m_LightingDataAsset: {fileID: 0} @@ -307,6 +312,7 @@ GameObject: m_Component: - 224: {fileID: 987455120} - 114: {fileID: 987455124} + - 114: {fileID: 987455125} - 223: {fileID: 987455123} - 114: {fileID: 987455122} - 114: {fileID: 987455121} @@ -402,10 +408,31 @@ MonoBehaviour: m_GameObject: {fileID: 987455119} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 327bf15252499524ca2de7a67ab4f467, type: 3} + m_Script: {fileID: 11500000, guid: 938311ed4b5a34590af2bad889d53090, type: 3} m_Name: m_EditorClassIdentifier: StringArgument: +--- !u!114 &987455125 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 987455119} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 0c01f3f0b88b4448ab1ccfa117a1d57e, type: 3} + m_Name: + m_EditorClassIdentifier: + OutletInfos: + - Name: LoginButton + ComponentType: UnityEngine.UI.Button + Object: {fileID: 1155933765} + - Name: LoginButtonText + ComponentType: UnityEngine.UI.Text + Object: {fileID: 1827155046} + - Name: LoginText + ComponentType: UnityEngine.UI.Text + Object: {fileID: 359997553} --- !u!1 &1155933765 GameObject: m_ObjectHideFlags: 0 @@ -481,7 +508,29 @@ MonoBehaviour: m_TargetGraphic: {fileID: 1155933768} m_OnClick: m_PersistentCalls: - m_Calls: [] + m_Calls: + - m_Target: {fileID: 0} + m_MethodName: + m_Mode: 1 + m_Arguments: + m_ObjectArgument: {fileID: 0} + m_ObjectArgumentAssemblyTypeName: + m_IntArgument: 0 + m_FloatArgument: 0 + m_StringArgument: + m_BoolArgument: 0 + m_CallState: 2 + - m_Target: {fileID: 0} + m_MethodName: + m_Mode: 1 + m_Arguments: + m_ObjectArgument: {fileID: 0} + m_ObjectArgumentAssemblyTypeName: + m_IntArgument: 0 + m_FloatArgument: 0 + m_StringArgument: + m_BoolArgument: 0 + m_CallState: 2 m_TypeName: UnityEngine.UI.Button+ButtonClickedEvent, UnityEngine.UI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null --- !u!114 &1155933768 diff --git a/KSFramework/Assets/BundleResources/UI/Login.prefab b/KSFramework/Assets/BundleResources/UI/Login.prefab index aa15a743..2b2d880f 100644 --- a/KSFramework/Assets/BundleResources/UI/Login.prefab +++ b/KSFramework/Assets/BundleResources/UI/Login.prefab @@ -1,16 +1,27 @@ %YAML 1.1 %TAG !u! tag:unity3d.com,2011: ---- !u!1 &106976 +--- !u!1001 &100100000 +Prefab: + m_ObjectHideFlags: 1 + serializedVersion: 2 + m_Modification: + m_TransformParent: {fileID: 0} + m_Modifications: [] + m_RemovedComponents: [] + m_ParentPrefab: {fileID: 0} + m_RootGameObject: {fileID: 1000014198987880} + m_IsPrefabParent: 1 +--- !u!1 &1000010307772792 GameObject: m_ObjectHideFlags: 0 m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} serializedVersion: 4 m_Component: - - 224: {fileID: 22464694} - - 222: {fileID: 22224656} - - 114: {fileID: 11463572} - - 114: {fileID: 11438486} + - 224: {fileID: 224000011348829866} + - 222: {fileID: 222000012500023156} + - 114: {fileID: 114000013104658846} + - 114: {fileID: 114000012781902564} m_Layer: 5 m_Name: Button m_TagString: Untagged @@ -18,18 +29,16 @@ GameObject: m_NavMeshLayer: 0 m_StaticEditorFlags: 0 m_IsActive: 1 ---- !u!1 &129270 +--- !u!1 &1000010576354794 GameObject: m_ObjectHideFlags: 0 m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} serializedVersion: 4 m_Component: - - 224: {fileID: 22401518} - - 114: {fileID: 11461408} - - 223: {fileID: 22355100} - - 114: {fileID: 11437898} - - 114: {fileID: 11436100} + - 224: {fileID: 224000010610742204} + - 222: {fileID: 222000011712379922} + - 114: {fileID: 114000013513181896} m_Layer: 5 m_Name: Login m_TagString: Untagged @@ -37,16 +46,16 @@ GameObject: m_NavMeshLayer: 0 m_StaticEditorFlags: 0 m_IsActive: 1 ---- !u!1 &165684 +--- !u!1 &1000010806186678 GameObject: m_ObjectHideFlags: 1 m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} serializedVersion: 4 m_Component: - - 224: {fileID: 22417354} - - 222: {fileID: 22249014} - - 114: {fileID: 11472692} + - 224: {fileID: 224000011301457854} + - 222: {fileID: 222000011872257860} + - 114: {fileID: 114000011606801756} m_Layer: 5 m_Name: Text m_TagString: Untagged @@ -54,16 +63,16 @@ GameObject: m_NavMeshLayer: 0 m_StaticEditorFlags: 0 m_IsActive: 1 ---- !u!1 &194846 +--- !u!1 &1000011417177778 GameObject: m_ObjectHideFlags: 0 m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} serializedVersion: 4 m_Component: - - 224: {fileID: 22483410} - - 222: {fileID: 22234462} - - 114: {fileID: 11485386} + - 224: {fileID: 224000010696392646} + - 222: {fileID: 222000012533445440} + - 114: {fileID: 114000013606292142} m_Layer: 5 m_Name: Image m_TagString: Untagged @@ -71,16 +80,19 @@ GameObject: m_NavMeshLayer: 0 m_StaticEditorFlags: 0 m_IsActive: 1 ---- !u!1 &197868 +--- !u!1 &1000014198987880 GameObject: m_ObjectHideFlags: 0 m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} serializedVersion: 4 m_Component: - - 224: {fileID: 22472634} - - 222: {fileID: 22219128} - - 114: {fileID: 11463604} + - 224: {fileID: 224000014217083470} + - 114: {fileID: 114000013858847332} + - 114: {fileID: 114000013557526014} + - 223: {fileID: 223000010132355134} + - 114: {fileID: 114000012023257856} + - 114: {fileID: 114000013074795788} m_Layer: 5 m_Name: Login m_TagString: Untagged @@ -88,28 +100,45 @@ GameObject: m_NavMeshLayer: 0 m_StaticEditorFlags: 0 m_IsActive: 1 ---- !u!114 &11436100 +--- !u!114 &114000011606801756 MonoBehaviour: m_ObjectHideFlags: 1 m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} - m_GameObject: {fileID: 129270} + m_GameObject: {fileID: 1000010806186678} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 1301386320, guid: f5f67c52d1564df4a8936ccd202a3bd8, type: 3} + m_Script: {fileID: 708705254, guid: f5f67c52d1564df4a8936ccd202a3bd8, type: 3} m_Name: m_EditorClassIdentifier: - m_IgnoreReversedGraphics: 1 - m_BlockingObjects: 0 - m_BlockingMask: - serializedVersion: 2 - m_Bits: 4294967295 ---- !u!114 &11437898 + m_Material: {fileID: 0} + m_Color: {r: 0, g: 0, b: 0, a: 1} + m_RaycastTarget: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI, + Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + m_FontData: + m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0} + m_FontSize: 14 + m_FontStyle: 0 + m_BestFit: 0 + m_MinSize: 10 + m_MaxSize: 40 + m_Alignment: 4 + m_AlignByGeometry: 0 + m_RichText: 1 + m_HorizontalOverflow: 0 + m_VerticalOverflow: 0 + m_LineSpacing: 1 + m_Text: Button +--- !u!114 &114000012023257856 MonoBehaviour: m_ObjectHideFlags: 1 m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} - m_GameObject: {fileID: 129270} + m_GameObject: {fileID: 1000014198987880} m_Enabled: 1 m_EditorHideFlags: 0 m_Script: {fileID: 1980459831, guid: f5f67c52d1564df4a8936ccd202a3bd8, type: 3} @@ -125,12 +154,12 @@ MonoBehaviour: m_FallbackScreenDPI: 96 m_DefaultSpriteDPI: 96 m_DynamicPixelsPerUnit: 1 ---- !u!114 &11438486 +--- !u!114 &114000012781902564 MonoBehaviour: m_ObjectHideFlags: 1 m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} - m_GameObject: {fileID: 106976} + m_GameObject: {fileID: 1000010307772792} m_Enabled: 1 m_EditorHideFlags: 0 m_Script: {fileID: 1392445389, guid: f5f67c52d1564df4a8936ccd202a3bd8, type: 3} @@ -160,30 +189,56 @@ MonoBehaviour: m_PressedTrigger: Pressed m_DisabledTrigger: Disabled m_Interactable: 1 - m_TargetGraphic: {fileID: 11463572} + m_TargetGraphic: {fileID: 114000013104658846} m_OnClick: m_PersistentCalls: - m_Calls: [] + m_Calls: + - m_Target: {fileID: 0} + m_MethodName: + m_Mode: 1 + m_Arguments: + m_ObjectArgument: {fileID: 0} + m_ObjectArgumentAssemblyTypeName: + m_IntArgument: 0 + m_FloatArgument: 0 + m_StringArgument: + m_BoolArgument: 0 + m_CallState: 2 + - m_Target: {fileID: 0} + m_MethodName: + m_Mode: 1 + m_Arguments: + m_ObjectArgument: {fileID: 0} + m_ObjectArgumentAssemblyTypeName: + m_IntArgument: 0 + m_FloatArgument: 0 + m_StringArgument: + m_BoolArgument: 0 + m_CallState: 2 m_TypeName: UnityEngine.UI.Button+ButtonClickedEvent, UnityEngine.UI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null ---- !u!114 &11461408 +--- !u!114 &114000013074795788 MonoBehaviour: m_ObjectHideFlags: 1 m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} - m_GameObject: {fileID: 129270} + m_GameObject: {fileID: 1000014198987880} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 327bf15252499524ca2de7a67ab4f467, type: 3} + m_Script: {fileID: 1301386320, guid: f5f67c52d1564df4a8936ccd202a3bd8, type: 3} m_Name: m_EditorClassIdentifier: - StringArgument: ---- !u!114 &11463572 + m_IgnoreReversedGraphics: 1 + m_BlockingObjects: 0 + m_BlockingMask: + serializedVersion: 2 + m_Bits: 4294967295 +--- !u!114 &114000013104658846 MonoBehaviour: m_ObjectHideFlags: 1 m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} - m_GameObject: {fileID: 106976} + m_GameObject: {fileID: 1000010307772792} m_Enabled: 1 m_EditorHideFlags: 0 m_Script: {fileID: -765806418, guid: f5f67c52d1564df4a8936ccd202a3bd8, type: 3} @@ -205,12 +260,12 @@ MonoBehaviour: m_FillAmount: 1 m_FillClockwise: 1 m_FillOrigin: 0 ---- !u!114 &11463604 +--- !u!114 &114000013513181896 MonoBehaviour: m_ObjectHideFlags: 1 m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} - m_GameObject: {fileID: 197868} + m_GameObject: {fileID: 1000010576354794} m_Enabled: 1 m_EditorHideFlags: 0 m_Script: {fileID: 708705254, guid: f5f67c52d1564df4a8936ccd202a3bd8, type: 3} @@ -238,45 +293,33 @@ MonoBehaviour: m_VerticalOverflow: 0 m_LineSpacing: 1 m_Text: Login ---- !u!114 &11472692 +--- !u!114 &114000013557526014 MonoBehaviour: m_ObjectHideFlags: 1 m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} - m_GameObject: {fileID: 165684} + m_GameObject: {fileID: 1000014198987880} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 708705254, guid: f5f67c52d1564df4a8936ccd202a3bd8, type: 3} + m_Script: {fileID: 11500000, guid: 0c01f3f0b88b4448ab1ccfa117a1d57e, type: 3} m_Name: m_EditorClassIdentifier: - m_Material: {fileID: 0} - m_Color: {r: 0, g: 0, b: 0, a: 1} - m_RaycastTarget: 1 - m_OnCullStateChanged: - m_PersistentCalls: - m_Calls: [] - m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI, - Version=1.0.0.0, Culture=neutral, PublicKeyToken=null - m_FontData: - m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0} - m_FontSize: 14 - m_FontStyle: 0 - m_BestFit: 0 - m_MinSize: 10 - m_MaxSize: 40 - m_Alignment: 4 - m_AlignByGeometry: 0 - m_RichText: 1 - m_HorizontalOverflow: 0 - m_VerticalOverflow: 0 - m_LineSpacing: 1 - m_Text: Button ---- !u!114 &11485386 + OutletInfos: + - Name: LoginButton + ComponentType: UnityEngine.UI.Button + Object: {fileID: 1000010307772792} + - Name: LoginButtonText + ComponentType: UnityEngine.UI.Text + Object: {fileID: 1000010806186678} + - Name: LoginText + ComponentType: UnityEngine.UI.Text + Object: {fileID: 1000010576354794} +--- !u!114 &114000013606292142 MonoBehaviour: m_ObjectHideFlags: 1 m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} - m_GameObject: {fileID: 194846} + m_GameObject: {fileID: 1000011417177778} m_Enabled: 1 m_EditorHideFlags: 0 m_Script: {fileID: -765806418, guid: f5f67c52d1564df4a8936ccd202a3bd8, type: 3} @@ -298,36 +341,48 @@ MonoBehaviour: m_FillAmount: 1 m_FillClockwise: 1 m_FillOrigin: 0 ---- !u!222 &22219128 +--- !u!114 &114000013858847332 +MonoBehaviour: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1000014198987880} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 938311ed4b5a34590af2bad889d53090, type: 3} + m_Name: + m_EditorClassIdentifier: + StringArgument: +--- !u!222 &222000011712379922 CanvasRenderer: m_ObjectHideFlags: 1 m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} - m_GameObject: {fileID: 197868} ---- !u!222 &22224656 + m_GameObject: {fileID: 1000010576354794} +--- !u!222 &222000011872257860 CanvasRenderer: m_ObjectHideFlags: 1 m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} - m_GameObject: {fileID: 106976} ---- !u!222 &22234462 + m_GameObject: {fileID: 1000010806186678} +--- !u!222 &222000012500023156 CanvasRenderer: m_ObjectHideFlags: 1 m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} - m_GameObject: {fileID: 194846} ---- !u!222 &22249014 + m_GameObject: {fileID: 1000010307772792} +--- !u!222 &222000012533445440 CanvasRenderer: m_ObjectHideFlags: 1 m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} - m_GameObject: {fileID: 165684} ---- !u!223 &22355100 + m_GameObject: {fileID: 1000011417177778} +--- !u!223 &223000010132355134 Canvas: m_ObjectHideFlags: 1 m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} - m_GameObject: {fileID: 129270} + m_GameObject: {fileID: 1000014198987880} m_Enabled: 1 serializedVersion: 2 m_RenderMode: 0 @@ -341,108 +396,97 @@ Canvas: m_SortingLayerID: 0 m_SortingOrder: 0 m_TargetDisplay: 0 ---- !u!224 &22401518 +--- !u!224 &224000010610742204 RectTransform: m_ObjectHideFlags: 1 m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} - m_GameObject: {fileID: 129270} + m_GameObject: {fileID: 1000010576354794} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalPosition: {x: 0, y: 0, z: 0} - m_LocalScale: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} - m_Children: - - {fileID: 22472634} - - {fileID: 22464694} - - {fileID: 22483410} - m_Father: {fileID: 0} + m_Children: [] + m_Father: {fileID: 224000014217083470} m_RootOrder: 0 - m_AnchorMin: {x: 0, y: 0} - m_AnchorMax: {x: 0, y: 0} - m_AnchoredPosition: {x: 0, y: 0} - m_SizeDelta: {x: 0, y: 0} - m_Pivot: {x: 0, y: 0} ---- !u!224 &22417354 + m_AnchorMin: {x: 0.5, y: 0.5} + m_AnchorMax: {x: 0.5, y: 0.5} + m_AnchoredPosition: {x: -132.55, y: 116} + m_SizeDelta: {x: 1156, y: 104} + m_Pivot: {x: 0.38533935, y: 0.41678068} +--- !u!224 &224000010696392646 RectTransform: m_ObjectHideFlags: 1 m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} - m_GameObject: {fileID: 165684} + m_GameObject: {fileID: 1000011417177778} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_Children: [] - m_Father: {fileID: 22464694} + m_Father: {fileID: 224000014217083470} + m_RootOrder: 2 + m_AnchorMin: {x: 0.5, y: 0.5} + m_AnchorMax: {x: 0.5, y: 0.5} + m_AnchoredPosition: {x: -283, y: 38} + m_SizeDelta: {x: 92.7, y: 147.4} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!224 &224000011301457854 +RectTransform: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1000010806186678} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_Children: [] + m_Father: {fileID: 224000011348829866} m_RootOrder: 0 m_AnchorMin: {x: 0, y: 0} m_AnchorMax: {x: 1, y: 1} m_AnchoredPosition: {x: 0, y: 0} m_SizeDelta: {x: 0, y: 0} m_Pivot: {x: 0.5, y: 0.5} ---- !u!224 &22464694 +--- !u!224 &224000011348829866 RectTransform: m_ObjectHideFlags: 1 m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} - m_GameObject: {fileID: 106976} + m_GameObject: {fileID: 1000010307772792} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_Children: - - {fileID: 22417354} - m_Father: {fileID: 22401518} + - {fileID: 224000011301457854} + m_Father: {fileID: 224000014217083470} m_RootOrder: 1 m_AnchorMin: {x: 0.5, y: 0.5} m_AnchorMax: {x: 0.5, y: 0.5} m_AnchoredPosition: {x: -0.00036621, y: -78.5} m_SizeDelta: {x: 160, y: 30} m_Pivot: {x: 0.5, y: 0.5} ---- !u!224 &22472634 +--- !u!224 &224000014217083470 RectTransform: m_ObjectHideFlags: 1 m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} - m_GameObject: {fileID: 197868} + m_GameObject: {fileID: 1000014198987880} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalPosition: {x: 0, y: 0, z: 0} - m_LocalScale: {x: 1, y: 1, z: 1} + m_LocalScale: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} - m_Children: [] - m_Father: {fileID: 22401518} + m_Children: + - {fileID: 224000010610742204} + - {fileID: 224000011348829866} + - {fileID: 224000010696392646} + m_Father: {fileID: 0} m_RootOrder: 0 - m_AnchorMin: {x: 0.5, y: 0.5} - m_AnchorMax: {x: 0.5, y: 0.5} - m_AnchoredPosition: {x: -132.55, y: 116} - m_SizeDelta: {x: 1156, y: 104} - m_Pivot: {x: 0.38533935, y: 0.41678068} ---- !u!224 &22483410 -RectTransform: - m_ObjectHideFlags: 1 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 100100000} - m_GameObject: {fileID: 194846} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 0} - m_LocalScale: {x: 1, y: 1, z: 1} - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} - m_Children: [] - m_Father: {fileID: 22401518} - m_RootOrder: 2 - m_AnchorMin: {x: 0.5, y: 0.5} - m_AnchorMax: {x: 0.5, y: 0.5} - m_AnchoredPosition: {x: -283, y: 38} - m_SizeDelta: {x: 92.7, y: 147.4} - m_Pivot: {x: 0.5, y: 0.5} ---- !u!1001 &100100000 -Prefab: - m_ObjectHideFlags: 1 - serializedVersion: 2 - m_Modification: - m_TransformParent: {fileID: 0} - m_Modifications: [] - m_RemovedComponents: [] - m_ParentPrefab: {fileID: 0} - m_RootGameObject: {fileID: 129270} - m_IsPrefabParent: 1 + m_AnchorMin: {x: 0, y: 0} + m_AnchorMax: {x: 0, y: 0} + m_AnchoredPosition: {x: 0, y: 0} + m_SizeDelta: {x: 0, y: 0} + m_Pivot: {x: 0, y: 0} diff --git a/KSFramework/Assets/BundleResources/UI/Login.prefab.meta b/KSFramework/Assets/BundleResources/UI/Login.prefab.meta index f94c344e..73a6ca22 100644 --- a/KSFramework/Assets/BundleResources/UI/Login.prefab.meta +++ b/KSFramework/Assets/BundleResources/UI/Login.prefab.meta @@ -1,6 +1,6 @@ fileFormatVersion: 2 guid: 5ac626607f7db7447bb046f85cd59e4b -timeCreated: 1470658439 +timeCreated: 1472370807 licenseType: Pro NativeFormatImporter: userData: diff --git a/KSFramework/Assets/Code/Game.cs b/KSFramework/Assets/Code/Game.cs index 0065d2bc..0592a95c 100644 --- a/KSFramework/Assets/Code/Game.cs +++ b/KSFramework/Assets/Code/Game.cs @@ -53,7 +53,7 @@ protected override IList CreateModules() /// Before Init Modules, coroutine /// /// - public override IEnumerator OnBeforeInitModules() + public override IEnumerator OnBeforeInit() { // Do Nothing yield break; @@ -63,7 +63,7 @@ public override IEnumerator OnBeforeInitModules() /// After Init Modules, coroutine /// /// - public override IEnumerator OnFinishInitModules() + public override IEnumerator OnGameStart() { // Print AppConfigs Log.Info("======================================= Read Settings from C# ================================="); diff --git a/KSFramework/Assets/Plugins/Contents.meta b/KSFramework/Assets/Plugins/Contents.meta new file mode 100644 index 00000000..8cbaa0d6 --- /dev/null +++ b/KSFramework/Assets/Plugins/Contents.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: c274db93687b7be4f90bb2b7d25d7ca6 +folderAsset: yes +timeCreated: 1472434440 +licenseType: Pro +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/KSFramework/Assets/Plugins/Contents/MacOS.meta b/KSFramework/Assets/Plugins/Contents/MacOS.meta new file mode 100644 index 00000000..091b9c64 --- /dev/null +++ b/KSFramework/Assets/Plugins/Contents/MacOS.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 501b8fb31a44d0c4d844f26f0d45b0b4 +folderAsset: yes +timeCreated: 1472434440 +licenseType: Pro +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/KSFramework/Assets/Plugins/Editor/KEngineEditor.meta b/KSFramework/Assets/Plugins/Editor/KEngineEditor.meta index 7e18298d..f88e8595 100644 --- a/KSFramework/Assets/Plugins/Editor/KEngineEditor.meta +++ b/KSFramework/Assets/Plugins/Editor/KEngineEditor.meta @@ -1,5 +1,9 @@ fileFormatVersion: 2 -guid: 4ca0f348a92d961428589b06400cd454 +guid: 727944e4b464a49eca5dc5ca0b61552a folderAsset: yes +timeCreated: 1472322821 +licenseType: Pro DefaultImporter: userData: + assetBundleName: + assetBundleVariant: diff --git a/KSFramework/Assets/Plugins/KEngine.meta b/KSFramework/Assets/Plugins/KEngine.meta index a6b8bc2d..4cc6403e 100644 --- a/KSFramework/Assets/Plugins/KEngine.meta +++ b/KSFramework/Assets/Plugins/KEngine.meta @@ -1,5 +1,9 @@ fileFormatVersion: 2 -guid: 97eb868aa070b114ead2bde98705aba0 +guid: c4d0bc2dc9c894bd1a7f7377986313d9 folderAsset: yes +timeCreated: 1472322821 +licenseType: Pro DefaultImporter: userData: + assetBundleName: + assetBundleVariant: diff --git a/KSFramework/Assets/Plugins/KSFramework/Editor/KSFrameworkEditor.cs b/KSFramework/Assets/Plugins/KSFramework/Editor/KSFrameworkEditor.cs index 2afda063..332b1614 100644 --- a/KSFramework/Assets/Plugins/KSFramework/Editor/KSFrameworkEditor.cs +++ b/KSFramework/Assets/Plugins/KSFramework/Editor/KSFrameworkEditor.cs @@ -100,7 +100,7 @@ public static void AutoMakeUILuaScripts() var luaPath = AppEngine.GetConfig("KSFramework.Lua", "LuaPath"); Debug.Log("Find UI from current scenes, LuaScriptPath: " + luaPath); - var windowAssets = GameObject.FindObjectsOfType(); + var windowAssets = GameObject.FindObjectsOfType(); if (windowAssets.Length > 0) { foreach (var windowAsset in windowAssets) diff --git a/KSFramework/Assets/Plugins/KSFramework/KSFrameworkInfo.cs b/KSFramework/Assets/Plugins/KSFramework/KSFrameworkInfo.cs index 9416145a..e2ef1ddf 100644 --- a/KSFramework/Assets/Plugins/KSFramework/KSFrameworkInfo.cs +++ b/KSFramework/Assets/Plugins/KSFramework/KSFrameworkInfo.cs @@ -7,5 +7,5 @@ [assembly: AssemblyCopyright("Copyright @ Kelly<23110388@qq.com> 2015-2016")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] -[assembly: AssemblyVersion("0.9.*")] -namespace KSFramework { public class KSFrameworkInfo { public static readonly string Version = "0.9.*"; } } +[assembly: AssemblyVersion("0.11.*")] +namespace KSFramework { public class KSFrameworkInfo { public static readonly string Version = "0.11.*"; } } diff --git a/KSFramework/Assets/Plugins/KSFramework/KSGame.cs b/KSFramework/Assets/Plugins/KSFramework/KSGame.cs index 09df30cc..b7e19b26 100644 --- a/KSFramework/Assets/Plugins/KSFramework/KSGame.cs +++ b/KSFramework/Assets/Plugins/KSFramework/KSGame.cs @@ -74,12 +74,12 @@ protected virtual void Awake() /// Before KEngine init modules /// /// - public abstract IEnumerator OnBeforeInitModules(); + public abstract IEnumerator OnBeforeInit(); /// /// After KEngine inited all module, make the game start! /// /// - public abstract IEnumerator OnFinishInitModules(); + public abstract IEnumerator OnGameStart(); } } diff --git a/KSFramework/Assets/Plugins/KSFramework/Modules/LuaModule/LuaBehaviour.cs b/KSFramework/Assets/Plugins/KSFramework/Modules/LuaModule/LuaBehaviour.cs index a0ae3935..d27dcad4 100644 --- a/KSFramework/Assets/Plugins/KSFramework/Modules/LuaModule/LuaBehaviour.cs +++ b/KSFramework/Assets/Plugins/KSFramework/Modules/LuaModule/LuaBehaviour.cs @@ -63,7 +63,8 @@ public object CallLuaFunction(string function, params object[] args) if (!CacheMode) Reload(); if (CacheTable == null) - return null; + throw new Exception(string.Format("{0}: cannot get table!", LuaPath)); + var retFunc = CacheTable[function]; if (retFunc != null) { diff --git a/KSFramework/Assets/Plugins/KSFramework/Modules/UI/Editor/UILuaOutletEditor.cs b/KSFramework/Assets/Plugins/KSFramework/Modules/UI/Editor/UILuaOutletEditor.cs new file mode 100644 index 00000000..d84f28a6 --- /dev/null +++ b/KSFramework/Assets/Plugins/KSFramework/Modules/UI/Editor/UILuaOutletEditor.cs @@ -0,0 +1,151 @@ +using UnityEngine; +using System.Collections; +using System.Collections.Generic; +using UnityEditor; +using KSFramework; + +[InitializeOnLoad] +[CustomEditor (typeof(UILuaOutlet))] +public class UILuaOutletEditor : Editor +{ + /// + /// mark all Game objects that has Outlet, for GUIhierarchyWindow mark + /// + static Dictionary _outletObjects = new Dictionary (); + + static UILuaOutletEditor () + { + EditorApplication.hierarchyWindowItemOnGUI += HierarchyItemCB; + UIWindowAssetEditor.CustomInspectorGUIAfter += (KEngine.UI.UIWindowAsset target) => { + if (target.gameObject.GetComponent () == null) { + if (GUILayout.Button ("Add UILuaOutlet")) { + target.gameObject.AddComponent (); + + } + } + }; + } + + private static void HierarchyItemCB (int instanceid, Rect selectionrect) + { + var obj = EditorUtility.InstanceIDToObject (instanceid) as GameObject; + if (obj != null) { + if (_outletObjects.ContainsKey (obj)) { + Rect r = new Rect (selectionrect); + r.x = r.width - 80; + r.width = 80; + var style = new GUIStyle (); + style.normal.textColor = Color.green; + style.hover.textColor = Color.cyan; + GUI.Label (r, string.Format ("=>'{0}'", _outletObjects [obj]), style); + } + } + } + + GUIStyle GreenFont; + GUIStyle RedFont; + + private HashSet _cachedPropertyNames = new HashSet (); + + void OnEnable () + { + GreenFont = new GUIStyle (); + GreenFont.fontStyle = FontStyle.Bold; + GreenFont.fontSize = 11; + GreenFont.normal.textColor = Color.green; + RedFont = new GUIStyle (); + RedFont.fontStyle = FontStyle.Bold; + RedFont.fontSize = 11; + RedFont.normal.textColor = Color.red; + } + + public override void OnInspectorGUI () + { + _cachedPropertyNames.Clear (); + + EditorGUI.BeginChangeCheck (); + + var outlet = target as UILuaOutlet; + + if (outlet.OutletInfos == null || outlet.OutletInfos.Count == 0) { + if (GUILayout.Button ("Add New Outlet")) { + if (outlet.OutletInfos == null) + outlet.OutletInfos = new List (); + + Undo.RecordObject (target, "Add OutletInfo"); + outlet.OutletInfos.Add (new UILuaOutlet.OutletInfo ()); + } + + } else { + + + // outlet ui edit + + for (var j = outlet.OutletInfos.Count - 1; j >= 0; j--) { + var currentTypeIndex = -1; + var outletInfo = outlet.OutletInfos [j]; + string[] typesOptions = new string[0]; + + var isValid = outletInfo.Object != null && !_cachedPropertyNames.Contains (outletInfo.Name); + // check duplicate property name + _cachedPropertyNames.Add (outletInfo.Name); + + if (outletInfo.Object != null) { + if (outletInfo.Object is GameObject) { + + + currentTypeIndex = 0;// give it default + var gameObj = outletInfo.Object as GameObject; + var components = gameObj.GetComponents (); + + + + _outletObjects [gameObj] = outletInfo.Name; + + typesOptions = new string[components.Length]; + for (var i = 0; i < components.Length; i++) { + var com = components [i]; + var typeName = typesOptions [i] = com.GetType ().FullName; + if (typeName == outletInfo.ComponentType) { + currentTypeIndex = i; + } + } + + } + + } + + + EditorGUILayout.Separator (); + EditorGUILayout.BeginHorizontal (); + EditorGUILayout.LabelField (string.Format ("Lua Property: '{0}'", outletInfo.Name), isValid ? GreenFont : RedFont); + EditorGUILayout.Space (); + if (GUILayout.Button ("+")) { + Undo.RecordObject (target, "Insert OutletInfo"); + outlet.OutletInfos.Insert (j, new UILuaOutlet.OutletInfo ()); + } + if (GUILayout.Button ("-")) { + + Undo.RecordObject (target, "Remove OutletInfo"); + outlet.OutletInfos.RemoveAt (j); + } + EditorGUILayout.EndHorizontal (); + + outletInfo.Name = EditorGUILayout.TextField ("Name:", outletInfo.Name); + outletInfo.Object = EditorGUILayout.ObjectField ("Object:", outletInfo.Object, typeof(UnityEngine.Object), true); + + if (currentTypeIndex >= 0) { + var typeIndex = EditorGUILayout.Popup ("Component:", currentTypeIndex, typesOptions); + outletInfo.ComponentType = typesOptions [typeIndex].ToString (); + + } + } + } + //base.OnInspectorGUI (); + if (EditorGUI.EndChangeCheck ()) { + Undo.RecordObject (target, "GUI Change Check"); + } + } + + +} diff --git a/KSFramework/Assets/Plugins/Slua_Managed/LuaDLLWrapper.cs.meta b/KSFramework/Assets/Plugins/KSFramework/Modules/UI/Editor/UILuaOutletEditor.cs.meta similarity index 75% rename from KSFramework/Assets/Plugins/Slua_Managed/LuaDLLWrapper.cs.meta rename to KSFramework/Assets/Plugins/KSFramework/Modules/UI/Editor/UILuaOutletEditor.cs.meta index 7e2ad870..62cf503d 100644 --- a/KSFramework/Assets/Plugins/Slua_Managed/LuaDLLWrapper.cs.meta +++ b/KSFramework/Assets/Plugins/KSFramework/Modules/UI/Editor/UILuaOutletEditor.cs.meta @@ -1,6 +1,6 @@ fileFormatVersion: 2 -guid: f424e2219e43bc547848ec3c1f6500ea -timeCreated: 1428479694 +guid: e1a240ffb1a8c4539a3af090ae970da3 +timeCreated: 1472323245 licenseType: Pro MonoImporter: serializedVersion: 2 diff --git a/KSFramework/Assets/Plugins/KSFramework/Modules/UI/LuaUIController.cs b/KSFramework/Assets/Plugins/KSFramework/Modules/UI/LuaUIController.cs index ee481707..f9d35684 100644 --- a/KSFramework/Assets/Plugins/KSFramework/Modules/UI/LuaUIController.cs +++ b/KSFramework/Assets/Plugins/KSFramework/Modules/UI/LuaUIController.cs @@ -9,144 +9,157 @@ namespace KSFramework { - /// - /// 自动根据UIName和UITemplateName,寻找适合的Lua脚本执行 - /// - public class LuaUIController : KEngine.UI.UIController - { - /// - /// 是否开启缓存模式,默认true,首次执行将把执行结果table存起来;在非缓存模式下,也可以通过编辑器的Reload来进行强制刷新缓存 - /// 对实时性重载要求高的,可以把开关设置成false,长期都进行Lua脚本重载,理论上会消耗额外的性能用于语法解析 - /// 该值调用频繁,就不放ini了 - /// - public static bool CacheMode = true; - - /// - /// 缓存的LuaTable - /// - private LuaTable _luaTable; - - /// - /// 一般编辑器模式下用于reload时用,记录上一次OnOpen的参数 - /// - public object[] LastOnOpenArgs { get; private set; } - - public override void OnInit() - { - base.OnInit(); - - if (!CheckInitScript(true)) return; - } - - /// - /// 调用Lua:OnOpen函数 - /// - /// - public override void OnOpen(params object[] args) - { - // 编辑器模式下,记录 - LastOnOpenArgs = args; - - base.OnOpen(args); - if (!CheckInitScript()) return; - - var onOpenFuncObj = _luaTable["OnOpen"]; - if (onOpenFuncObj == null) - { - Log.LogError("Not Exists `OnOpen` in lua: {0}", UITemplateName); - return; - } - - var newArgs = new object[args.Length + 1]; - newArgs[0] = _luaTable; - for (var i = 0; i < args.Length; i++) - { - newArgs[i + 1] = args[i]; - } - - (onOpenFuncObj as LuaFunction).call(newArgs); - } - - /// - /// Try to load script and init. - /// Script will be cached, - /// But in development, script cache can be clear, which will be load and init in the next time - /// - /// 开发阶段经常要使用Lua热重载,热重载过后,要确保OnInit重新执行 - /// - bool CheckInitScript(bool showWarn = false) - { - // 有缓存的lua,根据开关判定是否重新加载 - if (_luaTable != null && CacheMode) - return true; - - var relPath = string.Format("UI/UI{0}", UITemplateName); - - if (!KSGame.Instance.LuaModule.HasScript(relPath)) - { - if (showWarn) - Log.LogWarning("Not found UI Lua Script: {0}", relPath); - return false; - } - - var scriptResult = KSGame.Instance.LuaModule.CallScript(relPath); - Debuger.Assert(scriptResult is LuaTable, "{0} Script Must Return Lua Table with functions!", UITemplateName); - - _luaTable = scriptResult as LuaTable; - - var newFuncObj = _luaTable["New"]; // if a New function exist, new a table! - if (newFuncObj != null) - { - var newTableObj = (newFuncObj as LuaFunction).call(this); - _luaTable = newTableObj as LuaTable; - } - - var luaInitObj = _luaTable["OnInit"]; - Debuger.Assert(luaInitObj is LuaFunction, "Must have OnInit function - {0}", UIName); - - (luaInitObj as LuaFunction).call(_luaTable, this); - - return true; - } - - public UnityEngine.Object GetControl(string typeName, string uri, Transform findTrans) - { - return GetControl(typeName, uri, findTrans); - } - - public UnityEngine.Object GetControl(string typeName, string uri) - { - return GetControl(typeName, uri, null, true); - } - public UnityEngine.Object GetControl(string typeName, string uri, Transform findTrans, bool isLog) - { - if (findTrans == null) - findTrans = transform; - - Transform trans = findTrans.Find(uri); - if (trans == null) - { - if (isLog) - Log.LogError("Get UI<{0}> Control Error: " + uri, this); - return null; - } - - if (typeName == "GameObject") - return trans.gameObject; - - return trans.GetComponent(typeName); - } - - /// - /// 清理Lua脚本缓存,下次执行时将重新加载Lua - /// - public void ReloadLua() - { - if (_luaTable != null) - { - _luaTable.Dispose(); - _luaTable = null; - } - } - } + /// + /// 自动根据UIName和UITemplateName,寻找适合的Lua脚本执行 + /// + public class LuaUIController : KEngine.UI.UIController + { + /// + /// 是否开启缓存模式,默认true,首次执行将把执行结果table存起来;在非缓存模式下,也可以通过编辑器的Reload来进行强制刷新缓存 + /// 对实时性重载要求高的,可以把开关设置成false,长期都进行Lua脚本重载,理论上会消耗额外的性能用于语法解析 + /// 该值调用频繁,就不放ini了 + /// + public static bool CacheMode = true; + + /// + /// 缓存的LuaTable + /// + private LuaTable _luaTable; + + /// + /// 一般编辑器模式下用于reload时用,记录上一次OnOpen的参数 + /// + public object[] LastOnOpenArgs { get; private set; } + + public override void OnInit () + { + base.OnInit (); + + if (!CheckInitScript (true)) + return; + } + + /// + /// 调用Lua:OnOpen函数 + /// + /// + public override void OnOpen (params object[] args) + { + // 编辑器模式下,记录 + LastOnOpenArgs = args; + + base.OnOpen (args); + if (!CheckInitScript ()) + return; + + var onOpenFuncObj = _luaTable ["OnOpen"]; + if (onOpenFuncObj == null) { + Log.LogError ("Not Exists `OnOpen` in lua: {0}", UITemplateName); + return; + } + + var newArgs = new object[args.Length + 1]; + newArgs [0] = _luaTable; + for (var i = 0; i < args.Length; i++) { + newArgs [i + 1] = args [i]; + } + + (onOpenFuncObj as LuaFunction).call (newArgs); + } + + /// + /// Try to load script and init. + /// Script will be cached, + /// But in development, script cache can be clear, which will be load and init in the next time + /// + /// 开发阶段经常要使用Lua热重载,热重载过后,要确保OnInit重新执行 + /// + bool CheckInitScript (bool showWarn = false) + { + // 有缓存的lua,根据开关判定是否重新加载 + if (_luaTable != null && CacheMode) + return true; + + var relPath = string.Format ("UI/{0}/{0}", UITemplateName); + + if (!KSGame.Instance.LuaModule.HasScript (relPath)) { + if (showWarn) + Log.LogWarning ("Not found UI Lua Script: {0}", relPath); + return false; + } + + var scriptResult = KSGame.Instance.LuaModule.CallScript (relPath); + Debuger.Assert (scriptResult is LuaTable, "{0} Script Must Return Lua Table with functions!", UITemplateName); + + _luaTable = scriptResult as LuaTable; + + var newFuncObj = _luaTable ["New"]; // if a New function exist, new a table! + if (newFuncObj != null) { + var newTableObj = (newFuncObj as LuaFunction).call (this); + _luaTable = newTableObj as LuaTable; + } + + var outlet = this.GetComponent (); + if (outlet != null) { + for (var i = 0; i < outlet.OutletInfos.Count; i++) { + var outletInfo = outlet.OutletInfos [i]; + + var gameObj = outletInfo.Object as GameObject; + + if (gameObj != null) + _luaTable [outletInfo.Name] = gameObj.GetComponent (outletInfo.ComponentType); + else + _luaTable [outletInfo.Name] = outletInfo.Object; + } + + } + + + var luaInitObj = _luaTable ["OnInit"]; + Debuger.Assert (luaInitObj is LuaFunction, "Must have OnInit function - {0}", UIName); + + (luaInitObj as LuaFunction).call (_luaTable, this); + + return true; + } + + public UnityEngine.Object GetControl (string typeName, string uri, Transform findTrans) + { + return GetControl (typeName, uri, findTrans); + } + + public UnityEngine.Object GetControl (string typeName, string uri) + { + return GetControl (typeName, uri, null, true); + } + + public UnityEngine.Object GetControl (string typeName, string uri, Transform findTrans, bool isLog) + { + if (findTrans == null) + findTrans = transform; + + Transform trans = findTrans.Find (uri); + if (trans == null) { + if (isLog) + Log.LogError ("Get UI<{0}> Control Error: " + uri, this); + return null; + } + + if (typeName == "GameObject") + return trans.gameObject; + + return trans.GetComponent (typeName); + } + + /// + /// 清理Lua脚本缓存,下次执行时将重新加载Lua + /// + public void ReloadLua () + { + if (_luaTable != null) { + _luaTable.Dispose (); + _luaTable = null; + } + } + } } diff --git a/KSFramework/Assets/Plugins/KSFramework/Modules/UI/UILuaOutlet.cs b/KSFramework/Assets/Plugins/KSFramework/Modules/UI/UILuaOutlet.cs new file mode 100644 index 00000000..c2d0d6a1 --- /dev/null +++ b/KSFramework/Assets/Plugins/KSFramework/Modules/UI/UILuaOutlet.cs @@ -0,0 +1,61 @@ +#region Copyright (c) 2015 KEngine / Kelly , All rights reserved. + +// KEngine - Toolset and framework for Unity3D +// =================================== +// +// Filename: SettingModuleEditor.cs +// Date: 2015/12/03 +// Author: Kelly +// Email: 23110388@qq.com +// Github: https://github.com/mr-kelly/KEngine +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3.0 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library. + +#endregion +using UnityEngine; +using System.Collections; +using System.Collections.Generic; + +namespace KSFramework +{ + [RequireComponent(typeof(KEngine.UI.UIWindowAsset))] + [DisallowMultipleComponent] + public class UILuaOutlet : MonoBehaviour + { + /// Outlet info, serialize + /// + [System.Serializable] + public class OutletInfo + { + /// + /// Lua Property Name + /// + public string Name; + + /// + /// Component type 's full name (with namespace) + /// + public string ComponentType; + + /// + /// UI Control Object + /// + public UnityEngine.Object Object; + } + /// + /// Serialized outlet infos + /// + public List OutletInfos = new List(); + } +} diff --git a/KSFramework/Assets/Plugins/Slua_Managed/Lua3rdMeta.cs.meta b/KSFramework/Assets/Plugins/KSFramework/Modules/UI/UILuaOutlet.cs.meta similarity index 69% rename from KSFramework/Assets/Plugins/Slua_Managed/Lua3rdMeta.cs.meta rename to KSFramework/Assets/Plugins/KSFramework/Modules/UI/UILuaOutlet.cs.meta index 066e3350..6492ff68 100644 --- a/KSFramework/Assets/Plugins/Slua_Managed/Lua3rdMeta.cs.meta +++ b/KSFramework/Assets/Plugins/KSFramework/Modules/UI/UILuaOutlet.cs.meta @@ -1,7 +1,7 @@ fileFormatVersion: 2 -guid: b51a3b5f40c08405ca2dfb572d3558c0 -timeCreated: 1451443061 -licenseType: Free +guid: 0c01f3f0b88b4448ab1ccfa117a1d57e +timeCreated: 1472323229 +licenseType: Pro MonoImporter: serializedVersion: 2 defaultReferences: [] diff --git a/KSFramework/Assets/Plugins/Slua_Managed.meta b/KSFramework/Assets/Plugins/Slua_Managed.meta index 80ddd117..94a90ff1 100644 --- a/KSFramework/Assets/Plugins/Slua_Managed.meta +++ b/KSFramework/Assets/Plugins/Slua_Managed.meta @@ -1,5 +1,6 @@ fileFormatVersion: 2 guid: 82f4cef799e5e0f4f9177b4ca66970ae -folderAsset: yes DefaultImporter: userData: + assetBundleName: + assetBundleVariant: diff --git a/KSFramework/Assets/Plugins/Slua_Managed/Coroutine.cs b/KSFramework/Assets/Plugins/Slua_Managed/Coroutine.cs deleted file mode 100644 index 05492aee..00000000 --- a/KSFramework/Assets/Plugins/Slua_Managed/Coroutine.cs +++ /dev/null @@ -1,113 +0,0 @@ -// The MIT License (MIT) - -// Copyright 2015 Siney/Pangweiwei siney@yeah.net -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -#if !SLUA_STANDALONE -namespace SLua -{ - using UnityEngine; - using System.Collections; - using LuaInterface; - using SLua; - using System; - - public class LuaCoroutine : LuaObject - { - - static MonoBehaviour mb; - - static public void reg(IntPtr l, MonoBehaviour m) - { - mb = m; - reg(l, Yieldk, "UnityEngine"); - - string yield = -@" -local Yield = UnityEngine.Yieldk - -uCoroutine = uCoroutine or {} - -uCoroutine.create = function(x) - - local co = coroutine.create(x) - coroutine.resume(co) - return co - -end - -uCoroutine.yield = function(x) - - local co, ismain = coroutine.running() - if ismain then error('Can not yield in main thread') end - - if type(x) == 'thread' and coroutine.status(x) ~= 'dead' then - repeat - Yield(nil, function() coroutine.resume(co) end) - coroutine.yield() - until coroutine.status(x) == 'dead' - else - Yield(x, function() coroutine.resume(co) end) - coroutine.yield() - end - -end - --- backward compatibility of older versions -UnityEngine.Yield = uCoroutine.yield -"; - LuaState.get(l).doString(yield); - } - - [MonoPInvokeCallback(typeof(LuaCSFunction))] - static public int Yieldk(IntPtr l) - { - try - { - if (LuaDLL.lua_pushthread(l) == 1) - { - return error(l, "should put Yield call into lua coroutine."); - } - object y = checkObj(l, 1); - LuaFunction f; - checkType(l, 2, out f); - - mb.StartCoroutine(yieldReturn(y, f)); - pushValue(l, true); - return 1; - } - catch (Exception e) - { - return error(l, e); - } - } - - static public IEnumerator yieldReturn(object y, LuaFunction f) - { - if (y is IEnumerator) - yield return mb.StartCoroutine((IEnumerator)y); - else - yield return y; - f.call(); - } - - } -} -#endif diff --git a/KSFramework/Assets/Plugins/Slua_Managed/Coroutine.cs.meta b/KSFramework/Assets/Plugins/Slua_Managed/Coroutine.cs.meta deleted file mode 100644 index 39a41c6a..00000000 --- a/KSFramework/Assets/Plugins/Slua_Managed/Coroutine.cs.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 4b8788d2fe23d5449963f2c4c5cbc21f -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: diff --git a/KSFramework/Assets/Plugins/Slua_Managed/Debugger.meta b/KSFramework/Assets/Plugins/Slua_Managed/Debugger.meta deleted file mode 100644 index 32d34b42..00000000 --- a/KSFramework/Assets/Plugins/Slua_Managed/Debugger.meta +++ /dev/null @@ -1,5 +0,0 @@ -fileFormatVersion: 2 -guid: fc85fcebd14d1c645890114658899fb5 -folderAsset: yes -DefaultImporter: - userData: diff --git a/KSFramework/Assets/Plugins/Slua_Managed/Helper.cs b/KSFramework/Assets/Plugins/Slua_Managed/Helper.cs deleted file mode 100644 index c9568c92..00000000 --- a/KSFramework/Assets/Plugins/Slua_Managed/Helper.cs +++ /dev/null @@ -1,390 +0,0 @@ -// The MIT License (MIT) - -// Copyright 2015 Siney/Pangweiwei siney@yeah.net -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -namespace SLua -{ - using System.Collections; - using System; - using LuaInterface; - using System.Reflection; - - class Helper : LuaObject - { - - static string classfunc = @" -local getmetatable = getmetatable -local function Class(base,static,instance) - - local mt = getmetatable(base) - - local class = static or {} - setmetatable(class, - { - __index = base, - __call = function(...) - local r = mt.__call(...) - local ret = instance or {} - - local ins_ret = setmetatable( - { - __base = r, - }, - - { - __index = function(t, k) - local ret_field - ret_field = ret[k] - if nil == ret_field then - ret_field = r[k] - end - - return ret_field - end, - - __newindex = function(t,k,v) - if not pcall(function() r[k]=v end) then - rawset(t,k,v) - end - end, - }) - - if ret.ctor then - ret.ctor(ins_ret, ...) - end - - return ins_ret - end, - } - ) - return class -end -return Class -"; - - [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))] - static public int _iter(IntPtr l) - { - object obj = checkObj(l, LuaDLL.lua_upvalueindex(1)); - IEnumerator it = (IEnumerator)obj; - if (it.MoveNext()) - { - pushVar(l, it.Current); - return 1; - } - else - { - if (obj is IDisposable) - (obj as IDisposable).Dispose(); - } - return 0; - } - - [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))] - static public int iter(IntPtr l) - { - object o = checkObj(l, 1); - if (o is IEnumerable) - { - IEnumerable e = o as IEnumerable; - IEnumerator iter = e.GetEnumerator(); - pushValue(l, true); - pushLightObject(l, iter); - LuaDLL.lua_pushcclosure(l, _iter, 1); - return 2; - } - return error(l,"passed in object isn't enumerable"); - } - - /// - /// Create standard System.Action - /// - /// - /// - [MonoPInvokeCallbackAttribute(typeof (LuaCSFunction))] - public static int CreateAction(IntPtr l) - { - try - { - - LuaFunction func; - checkType(l, 1, out func); - var action = new Action(() => - { - func.call(); - - }); - pushValue(l, true); - pushVar(l, action); - return 2; - } - catch (Exception e) - { - return error(l, e); - } - - } - - [MonoPInvokeCallbackAttribute(typeof (LuaCSFunction))] - static public int CreateClass(IntPtr l) - { - try - { - string cls; - checkType(l, 1, out cls); - Type t = LuaObject.FindType(cls); - if (t == null) - { - return error(l, string.Format("Can't find {0} to create", cls)); - } - - ConstructorInfo[] cis = t.GetConstructors(); - ConstructorInfo target = null; - for (int n = 0; n < cis.Length; n++) - { - ConstructorInfo ci = cis[n]; - if (matchType(l, LuaDLL.lua_gettop(l), 2, ci.GetParameters())) - { - target = ci; - break; - } - } - - if (target != null) - { - ParameterInfo[] pis = target.GetParameters(); - object[] args = new object[pis.Length]; - for (int n = 0; n < pis.Length; n++) - args[n] = changeType(checkVar(l, n + 2), pis[n].ParameterType); - - object ret = target.Invoke(args); - pushValue(l, true); - pushVar(l, ret); - return 2; - } - pushValue(l, true); - return 1; - } - catch (Exception e) - { - return error(l,e); - } - } - - - - - [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))] - static public int GetClass(IntPtr l) - { - try - { - string cls; - checkType(l, 1, out cls); - Type t = LuaObject.FindType(cls); - if (t == null) - { - return error(l, "Can't find {0} to create", cls); - } - - LuaClassObject co = new LuaClassObject(t); - pushValue(l, true); - LuaObject.pushObject(l,co); - return 2; - } - catch (Exception e) - { - return error(l, e); - } - } - - //convert lua binary string to c# byte[] - [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))] - static public int ToBytes(IntPtr l){ - try{ - byte[] bytes = null; - checkBinaryString(l,1,out bytes); - pushValue(l,true); - LuaObject.pushObject(l,bytes); - return 2; - - }catch(System.Exception e){ - return error(l, e); - } - } - - [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))] - static public new int ToString(IntPtr l) - { - try - { - object o = checkObj(l, 1); - if (o == null) - { - pushValue(l, true); - LuaDLL.lua_pushnil(l); - return 2; - } - - pushValue(l, true); - if (o is byte[]) - { - byte[] b = (byte[])o; - LuaDLL.lua_pushlstring(l, b, b.Length); - } - else - { - pushValue(l, o.ToString()); - } - return 2; - } - catch (Exception e) - { - return error(l, e); - } - } - - [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))] - static public int MakeArray(IntPtr l) - { - try - { - Type t; - checkType (l,1,out t); - LuaDLL.luaL_checktype(l, 2, LuaTypes.LUA_TTABLE); - int n = LuaDLL.lua_rawlen(l, 2); - Array array=Array.CreateInstance(t,n); - for (int k = 0; k < n; k++) - { - LuaDLL.lua_rawgeti(l, 2, k + 1); - var obj = checkVar(l, -1); - array.SetValue(changeType(obj, t), k); - LuaDLL.lua_pop(l, 1); - } - pushValue(l, true); - pushValue(l, array); - return 2; - } - catch (Exception e) - { - return error(l, e); - } - } - - [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))] - static public int As(IntPtr l) - { - try - { - if (!isTypeTable(l, 2)) - { - return error(l, "No matched type of param 2"); - } - string meta = LuaDLL.lua_tostring(l, -1); - LuaDLL.luaL_getmetatable(l, meta); - LuaDLL.lua_setmetatable(l, 1); - pushValue(l, true); - LuaDLL.lua_pushvalue(l, 1); - return 2; - } - catch (Exception e) - { - return error(l, e); - } - } - - [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))] - static public int IsNull(IntPtr l) - { - try - { - LuaTypes t = LuaDLL.lua_type(l, 1); - pushValue(l, true); - - if (t == LuaTypes.LUA_TNIL) - { - pushValue(l, true); - } - // LUA_TUSERDATA or LUA_TTABLE(Class inherited from Unity Native) - else if (t == LuaTypes.LUA_TUSERDATA || isLuaClass(l, 1)) - { - object o = checkObj(l, 1); -#if !SLUA_STANDALONE - if( o is UnityEngine.Object ) - { - pushValue(l, ((UnityEngine.Object)o)==null); - } - else -#endif - pushValue(l, o.Equals(null)); - } - else - pushValue(l, false); - - return 2; - } - catch (Exception e) - { - return error(l, e); - } - } - - static LuaOut luaOut = new LuaOut(); - [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))] - static public int get_out(IntPtr l) - { - pushValue(l, true); - pushLightObject(l, luaOut); - return 2; - } - - [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))] - static public int get_version(IntPtr l) - { - pushValue(l, true); - pushValue(l, VersionNumber); - return 2; - } - - static public void reg(IntPtr l) - { - getTypeTable(l, "Slua"); - addMember(l, CreateAction, false); - addMember(l, CreateClass, false); - addMember(l, GetClass, false); - addMember(l, iter, false); - addMember(l, ToString, false); - addMember(l, As, false); - addMember(l, IsNull, false); - addMember(l, MakeArray, false); - addMember(l, ToBytes, false); - addMember(l, "out", get_out, null, false); - addMember(l, "version", get_version, null, false); - - LuaFunction func = LuaState.get(l).doString(classfunc) as LuaFunction; - func.push(l); - LuaDLL.lua_setfield(l, -3, "Class"); - - - createTypeMetatable(l, null, typeof(Helper)); - } - } -} diff --git a/KSFramework/Assets/Plugins/Slua_Managed/Helper.cs.meta b/KSFramework/Assets/Plugins/Slua_Managed/Helper.cs.meta deleted file mode 100644 index df6e226a..00000000 --- a/KSFramework/Assets/Plugins/Slua_Managed/Helper.cs.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 79a808d57285e484caa6df1514a0f3c0 -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: diff --git a/KSFramework/Assets/Plugins/Slua_Managed/Logger.cs b/KSFramework/Assets/Plugins/Slua_Managed/Logger.cs deleted file mode 100644 index 8769fb2f..00000000 --- a/KSFramework/Assets/Plugins/Slua_Managed/Logger.cs +++ /dev/null @@ -1,41 +0,0 @@ - - -using System; - -namespace SLua -{ - - /// - /// A bridge between UnityEngine.Debug.LogXXX and standalone.LogXXX - /// - internal class Logger - { - public static void Log(string msg) - { -#if !SLUA_STANDALONE - UnityEngine.Debug.Log(msg); -#else - Console.WriteLine(msg); -#endif - } - public static void LogError(string msg) - { -#if !SLUA_STANDALONE - UnityEngine.Debug.LogError(msg); -#else - Console.WriteLine(msg); -#endif - } - - public static void LogWarning(string msg) - { -#if !SLUA_STANDALONE - UnityEngine.Debug.LogWarning(msg); -#else - Console.WriteLine(msg); -#endif - } - } - - -} \ No newline at end of file diff --git a/KSFramework/Assets/Plugins/Slua_Managed/Logger.cs.meta b/KSFramework/Assets/Plugins/Slua_Managed/Logger.cs.meta deleted file mode 100644 index f29ccc13..00000000 --- a/KSFramework/Assets/Plugins/Slua_Managed/Logger.cs.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: ef0ab90919648f047bdecb8eee9a5b83 -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: diff --git a/KSFramework/Assets/Plugins/Slua_Managed/Lua3rdDLL.cs b/KSFramework/Assets/Plugins/Slua_Managed/Lua3rdDLL.cs deleted file mode 100644 index f8572fa9..00000000 --- a/KSFramework/Assets/Plugins/Slua_Managed/Lua3rdDLL.cs +++ /dev/null @@ -1,68 +0,0 @@ -using System.Collections.Generic; -using LuaInterface; -using System; -using System.IO; -using System.Linq; -using System.Reflection; -#if !SLUA_STANDALONE -using UnityEngine; -#endif - -namespace SLua{ - public static class Lua3rdDLL{ - static Dictionary DLLRegFuncs = new Dictionary(); - - static Lua3rdDLL(){ - // LuaSocketDLL.Reg(DLLRegFuncs); - } - - public static void open(IntPtr L){ - var typenames = Lua3rdMeta.Instance.typesWithAttribtues; - var assemblys = AppDomain.CurrentDomain.GetAssemblies(); - Assembly assembly = null; - foreach(var ass in assemblys){ - if(ass.GetName().Name == "Assembly-CSharp"){ - assembly = ass; - break; - } - } - if(assembly != null){ - foreach(var typename in typenames){ - var type = assembly.GetType(typename); - var methods = type.GetMethods(BindingFlags.Static|BindingFlags.Public); - foreach(var method in methods){ - var attr = System.Attribute.GetCustomAttribute(method,typeof(LualibRegAttribute)) as LualibRegAttribute; - if(attr != null){ - var csfunc = Delegate.CreateDelegate(typeof(LuaCSFunction),method) as LuaCSFunction; - DLLRegFuncs.Add(attr.luaName,csfunc); - } - } - } - } - - if(DLLRegFuncs.Count == 0){ - return; - } - - LuaDLL.lua_getglobal(L, "package"); - LuaDLL.lua_getfield(L, -1, "preload"); - foreach (KeyValuePair pair in DLLRegFuncs) { - LuaDLL.lua_pushcfunction (L, pair.Value); - LuaDLL.lua_setfield(L, -2, pair.Key); - } - - LuaDLL.lua_settop(L, 0); - } - - - [AttributeUsage(AttributeTargets.Method)] - public class LualibRegAttribute:System.Attribute{ - - public string luaName; - public LualibRegAttribute(string luaName){ - this.luaName = luaName; - } - } - } - -} \ No newline at end of file diff --git a/KSFramework/Assets/Plugins/Slua_Managed/Lua3rdDLL.cs.meta b/KSFramework/Assets/Plugins/Slua_Managed/Lua3rdDLL.cs.meta deleted file mode 100644 index 68c75698..00000000 --- a/KSFramework/Assets/Plugins/Slua_Managed/Lua3rdDLL.cs.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: b87097bdd644c4646891b1b3514f4c53 -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: diff --git a/KSFramework/Assets/Plugins/Slua_Managed/Lua3rdMeta.cs b/KSFramework/Assets/Plugins/Slua_Managed/Lua3rdMeta.cs deleted file mode 100644 index 479c548e..00000000 --- a/KSFramework/Assets/Plugins/Slua_Managed/Lua3rdMeta.cs +++ /dev/null @@ -1,78 +0,0 @@ -using System.Collections.Generic; -using LuaInterface; -using System; -using System.Linq; -using System.Reflection; -#if !SLUA_STANDALONE -using UnityEngine; -#endif -using System.IO; - -namespace SLua{ - - public class Lua3rdMeta - #if !SLUA_STANDALONE - :ScriptableObject - #endif - { - /// - ///Cache class types here those contain 3rd dll attribute. - /// - public List typesWithAttribtues = new List(); - - void OnEnable(){ - #if !SLUA_STANDALONE - this.hideFlags = HideFlags.NotEditable; - #endif - } - #if UNITY_EDITOR - - public void ReBuildTypes(){ - typesWithAttribtues.Clear(); - Assembly assembly = null; - foreach(var assem in AppDomain.CurrentDomain.GetAssemblies()){ - if(assem.GetName().Name == "Assembly-CSharp"){ - assembly = assem; - break; - } - } - if(assembly != null){ - var types = assembly.GetExportedTypes(); - foreach(var type in types){ - var methods = type.GetMethods(BindingFlags.Public|BindingFlags.Static); - foreach(var method in methods){ - if(method.IsDefined(typeof(Lua3rdDLL.LualibRegAttribute),false)){ - typesWithAttribtues.Add(type.FullName); - break; - } - } - } - } - } - - #endif - private static Lua3rdMeta _instance=null; - public static Lua3rdMeta Instance{ - get{ - #if !SLUA_STANDALONE - if(_instance == null){ - _instance = Resources.Load("lua3rdmeta"); - } - - #if UNITY_EDITOR - if(_instance == null){ - _instance = ScriptableObject.CreateInstance(); - string path = "Assets/Slua/Meta/Resources"; - if(!Directory.Exists(path)){ - Directory.CreateDirectory(path); - } - UnityEditor.AssetDatabase.CreateAsset(_instance,Path.Combine(path,"lua3rdmeta.asset")); - } - - #endif - #endif - return _instance; - } - } - } -} diff --git a/KSFramework/Assets/Plugins/Slua_Managed/LuaArray.cs b/KSFramework/Assets/Plugins/Slua_Managed/LuaArray.cs deleted file mode 100644 index 07eca434..00000000 --- a/KSFramework/Assets/Plugins/Slua_Managed/LuaArray.cs +++ /dev/null @@ -1,158 +0,0 @@ -// The MIT License (MIT) - -// Copyright 2015 Siney/Pangweiwei siney@yeah.net -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - - -namespace SLua -{ -#if !SLUA_STANDALONE - using UnityEngine; -#endif - using System.Collections; - using System.Collections.Generic; - using System; - using LuaInterface; - using System.Reflection; - using System.Runtime.InteropServices; - - class LuaArray : LuaObject - { - - - static int toTable(IntPtr l,Array o) - { - - if (o == null) - { - LuaDLL.lua_pushnil(l); - return 1; - } - LuaDLL.lua_createtable(l, o.Length, 0); - for (int n = 0; n < o.Length; n++) - { - pushVar(l, o.GetValue(n)); - LuaDLL.lua_rawseti(l, -2, n + 1); - } - return 1; - } - - static int length(IntPtr l,Array a) - { - pushValue(l, a.Length); - return 1; - } - - [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))] - static public int len(IntPtr l) - { - Array a = (Array)checkSelf(l); - pushValue(l, a.Length); - return 1; - } - - delegate int ArrayPropFunction(IntPtr l, Array a); - - static Dictionary propMethod = new Dictionary(); - [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))] - static public int luaIndex(IntPtr l) - { - try - { - Array a=(Array)checkSelf(l); - if (LuaDLL.lua_type(l, 2) == LuaTypes.LUA_TSTRING) - { - string mn; - checkType(l, 2, out mn); - ArrayPropFunction fun; - if (propMethod.TryGetValue(mn, out fun)) - { - pushValue(l, true); - return fun(l, a) + 1; - } - else - throw new Exception("Can't find property named " + mn); - } - else - { - int i; - checkType(l, 2, out i); - assert(i>0,"index base 1"); - pushValue(l, true); - pushVar(l, a.GetValue(i-1)); - return 2; - } - } - catch (Exception e) - { - return error(l, e); - } - } - - [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))] - static public int luaNewIndex(IntPtr l) - { - try - { - Array a = (Array)checkSelf(l); - int i; - checkType(l, 2, out i); - assert(i>0,"index base 1"); - object o=checkVar(l, 3); - Type et = a.GetType().GetElementType(); - a.SetValue(changeType(o,et), i-1); - return ok(l); - } - catch (Exception e) - { - return error(l, e); - } - } - - [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))] - static public int tostring(IntPtr l) - { - Array a = (Array)checkSelf(l); - pushValue(l, string.Format("Array<{0}>",a.GetType().GetElementType().Name)); - return 1; - } - - static new public void init(IntPtr l) - { - - propMethod["Table"] = toTable; - propMethod["Length"] = length; - - LuaDLL.lua_createtable(l, 0, 5); - pushValue(l, luaIndex); - LuaDLL.lua_setfield(l, -2, "__index"); - pushValue(l, luaNewIndex); - LuaDLL.lua_setfield(l, -2, "__newindex"); - LuaDLL.lua_pushcfunction(l, lua_gc); - LuaDLL.lua_setfield(l, -2, "__gc"); - LuaDLL.lua_pushcfunction(l, tostring); - LuaDLL.lua_setfield(l, -2, "__tostring"); - LuaDLL.lua_pushcfunction(l, len); - LuaDLL.lua_setfield(l, -2, "__len"); - - LuaDLL.lua_setfield(l, LuaIndexes.LUA_REGISTRYINDEX, "LuaArray"); - } - } -} diff --git a/KSFramework/Assets/Plugins/Slua_Managed/LuaArray.cs.meta b/KSFramework/Assets/Plugins/Slua_Managed/LuaArray.cs.meta deleted file mode 100644 index d7d84350..00000000 --- a/KSFramework/Assets/Plugins/Slua_Managed/LuaArray.cs.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 7195878f2fbc1d346ba311cc09c9b7c6 -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: diff --git a/KSFramework/Assets/Plugins/Slua_Managed/LuaDLL.cs b/KSFramework/Assets/Plugins/Slua_Managed/LuaDLL.cs deleted file mode 100644 index daf0d234..00000000 --- a/KSFramework/Assets/Plugins/Slua_Managed/LuaDLL.cs +++ /dev/null @@ -1,704 +0,0 @@ -using System; -using System.Runtime.InteropServices; - -namespace LuaInterface -{ -#pragma warning disable 414 - public class MonoPInvokeCallbackAttribute : System.Attribute - { - private Type type; - public MonoPInvokeCallbackAttribute(Type t) - { - type = t; - } - } -#pragma warning restore 414 - - public enum LuaTypes : int - { - LUA_TNONE = -1, - LUA_TNIL = 0, - LUA_TBOOLEAN = 1, - LUA_TLIGHTUSERDATA = 2, - LUA_TNUMBER = 3, - LUA_TSTRING = 4, - LUA_TTABLE = 5, - LUA_TFUNCTION = 6, - LUA_TUSERDATA = 7, - LUA_TTHREAD = 8, - } - - public enum LuaGCOptions - { - LUA_GCSTOP = 0, - LUA_GCRESTART = 1, - LUA_GCCOLLECT = 2, - LUA_GCCOUNT = 3, - LUA_GCCOUNTB = 4, - LUA_GCSTEP = 5, - LUA_GCSETPAUSE = 6, - LUA_GCSETSTEPMUL = 7, - } - - public enum LuaThreadStatus : int - { - LUA_YIELD = 1, - LUA_ERRRUN = 2, - LUA_ERRSYNTAX = 3, - LUA_ERRMEM = 4, - LUA_ERRERR = 5, - } - - public sealed class LuaIndexes - { -#if LUA_5_3 - // for lua5.3 - public static int LUA_REGISTRYINDEX = -1000000 - 1000; -#else - // for lua5.1 or luajit - public static int LUA_REGISTRYINDEX = -10000; - public static int LUA_GLOBALSINDEX = -10002; -#endif - } - - [StructLayout(LayoutKind.Sequential)] - public struct ReaderInfo - { - public String chunkData; - public bool finished; - } - -#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate int LuaCSFunction(IntPtr luaState); -#else - public delegate int LuaCSFunction(IntPtr luaState); -#endif - - public delegate string LuaChunkReader(IntPtr luaState, ref ReaderInfo data, ref uint size); - - public delegate int LuaFunctionCallback(IntPtr luaState); - public class LuaDLL - { - public static int LUA_MULTRET = -1; -#if UNITY_IPHONE && !UNITY_EDITOR - const string LUADLL = "__Internal"; -#else - const string LUADLL = "slua"; -#endif - - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern void luaS_openextlibs(IntPtr L); - - // Thread Funcs - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern int lua_tothread(IntPtr L, int index); - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern void lua_xmove(IntPtr from, IntPtr to, int n); - - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr lua_newthread(IntPtr L); - - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern int lua_status(IntPtr L); - - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern int lua_pushthread(IntPtr L); - - - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern int lua_gc(IntPtr luaState, LuaGCOptions what, int data); - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr lua_typename(IntPtr luaState, int type); - public static string lua_typenamestr(IntPtr luaState, LuaTypes type) - { - IntPtr p = lua_typename(luaState, (int)type); - return Marshal.PtrToStringAnsi(p); - } - public static string luaL_typename(IntPtr luaState, int stackPos) - { - return LuaDLL.lua_typenamestr(luaState, LuaDLL.lua_type(luaState, stackPos)); - } - - public static bool lua_isfunction(IntPtr luaState, int stackPos) - { - return lua_type(luaState, stackPos) == LuaTypes.LUA_TFUNCTION; - } - - public static bool lua_islightuserdata(IntPtr luaState, int stackPos) - { - return lua_type(luaState, stackPos) == LuaTypes.LUA_TLIGHTUSERDATA; - } - - public static bool lua_istable(IntPtr luaState, int stackPos) - { - return lua_type(luaState, stackPos) == LuaTypes.LUA_TTABLE; - } - - public static bool lua_isthread(IntPtr luaState, int stackPos) - { - return lua_type(luaState, stackPos) == LuaTypes.LUA_TTHREAD; - } - - [Obsolete] - public static void luaL_error(IntPtr luaState, string message) - { - //LuaDLL.lua_pushstring(luaState, message); - //LuaDLL.lua_error(luaState); - } - - [Obsolete] - public static void luaL_error(IntPtr luaState, string fmt, params object[] args) - { - //string str = string.Format(fmt, args); - //luaL_error(luaState, str); - } - - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern string luaL_gsub(IntPtr luaState, string str, string pattern, string replacement); - - - - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern int lua_isuserdata(IntPtr luaState, int stackPos); - - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern int lua_rawequal(IntPtr luaState, int stackPos1, int stackPos2); - - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern void lua_setfield(IntPtr luaState, int stackPos, string name); - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern int luaL_callmeta(IntPtr luaState, int stackPos, string name); - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr luaL_newstate(); - - - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern void lua_close(IntPtr luaState); - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern void luaL_openlibs(IntPtr luaState); - - - - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern int luaL_loadstring(IntPtr luaState, string chunk); - public static int luaL_dostring(IntPtr luaState, string chunk) - { - int result = LuaDLL.luaL_loadstring(luaState, chunk); - if (result != 0) - return result; - - return LuaDLL.lua_pcall(luaState, 0, -1, 0); - } - public static int lua_dostring(IntPtr luaState, string chunk) - { - return LuaDLL.luaL_dostring(luaState, chunk); - } - - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern void lua_createtable(IntPtr luaState, int narr, int nrec); - public static void lua_newtable(IntPtr luaState) - { - LuaDLL.lua_createtable(luaState, 0, 0); - } - -#if LUA_5_3 - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern void lua_getglobal(IntPtr luaState, string name); - - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern void lua_setglobal(IntPtr luaState, string name); - - public static void lua_insert(IntPtr luaState, int newTop) - { - lua_rotate(luaState, newTop, 1); - } - - public static void lua_pushglobaltable(IntPtr l) - { - lua_rawgeti(l, LuaIndexes.LUA_REGISTRYINDEX, 2); - } - - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern int lua_rotate(IntPtr luaState, int index, int n); - - public static int lua_rawlen(IntPtr luaState, int stackPos) - { - return LuaDLLWrapper.luaS_rawlen(luaState, stackPos); - } - - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern int luaL_loadbufferx(IntPtr luaState, byte[] buff, int size, string name, IntPtr x); - - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern int lua_callk(IntPtr luaState, int nArgs, int nResults,int ctx,IntPtr k); - - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern int lua_pcallk(IntPtr luaState, int nArgs, int nResults, int errfunc,int ctx,IntPtr k); - - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern int luaS_pcall(IntPtr luaState, int nArgs, int nResults, int errfunc); - - public static int lua_call(IntPtr luaState, int nArgs, int nResults) - { - return lua_callk(luaState, nArgs, nResults, 0, IntPtr.Zero); - } - - public static int lua_pcall(IntPtr luaState, int nArgs, int nResults, int errfunc) - { - return luaS_pcall(luaState, nArgs, nResults, errfunc); - } - - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern double lua_tonumberx(IntPtr luaState, int index, IntPtr x); - public static double lua_tonumber(IntPtr luaState, int index) - { - return lua_tonumberx(luaState, index, IntPtr.Zero); - } - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern Int64 lua_tointegerx(IntPtr luaState, int index,IntPtr x); - public static int lua_tointeger(IntPtr luaState, int index) - { - return (int)lua_tointegerx(luaState, index, IntPtr.Zero); - } - - - public static int luaL_loadbuffer(IntPtr luaState, byte[] buff, int size, string name) - { - return luaL_loadbufferx(luaState, buff, size, name, IntPtr.Zero); - } - - public static void lua_remove(IntPtr l, int idx) - { - lua_rotate(l, (idx), -1); - lua_pop(l, 1); - } - - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern void lua_rawgeti(IntPtr luaState, int tableIndex, Int64 index); - - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern void lua_rawseti(IntPtr luaState, int tableIndex, Int64 index); - - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern void lua_pushinteger(IntPtr luaState, Int64 i); - - public static Int64 luaL_checkinteger(IntPtr luaState, int stackPos) { - luaL_checktype(luaState, stackPos, LuaTypes.LUA_TNUMBER); - return lua_tointegerx(luaState, stackPos, IntPtr.Zero); - } - - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern int luaS_yield(IntPtr luaState,int nrets); - - public static int lua_yield(IntPtr luaState,int nrets) { - return luaS_yield(luaState,nrets); - } - - - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern int lua_resume(IntPtr L, IntPtr from, int narg); - - public static void lua_replace(IntPtr luaState, int index) { - lua_copy(luaState, -1, (index)); - lua_pop(luaState, 1); - } - - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern void lua_copy(IntPtr luaState,int from,int toidx); - - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern int lua_isinteger(IntPtr luaState, int p); - - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern int lua_compare(IntPtr luaState, int index1, int index2, int op); - - public static int lua_equal(IntPtr luaState, int index1, int index2) - { - return lua_compare(luaState, index1, index2, 0); - } - -#else - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern int lua_resume(IntPtr L, int narg); - - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern int lua_lessthan(IntPtr luaState, int stackPos1, int stackPos2); - - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern void lua_getfenv(IntPtr luaState, int stackPos); - - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern int lua_yield(IntPtr L, int nresults); - - public static void lua_getglobal(IntPtr luaState, string name) - { - LuaDLL.lua_pushstring(luaState, name); - LuaDLL.lua_gettable(luaState, LuaIndexes.LUA_GLOBALSINDEX); - } - - public static void lua_setglobal(IntPtr luaState, string name) - { - LuaDLL.lua_pushstring(luaState, name); - LuaDLL.lua_insert(luaState, -2); - LuaDLL.lua_settable(luaState, LuaIndexes.LUA_GLOBALSINDEX); - } - - public static void lua_pushglobaltable(IntPtr l) - { - LuaDLL.lua_pushvalue(l, LuaIndexes.LUA_GLOBALSINDEX); - } - - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern void lua_insert(IntPtr luaState, int newTop); - - public static int lua_rawlen(IntPtr luaState, int stackPos) - { - return LuaDLLWrapper.luaS_objlen(luaState, stackPos); - } - - public static int lua_strlen(IntPtr luaState, int stackPos) - { - return lua_rawlen(luaState, stackPos); - } - - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern void lua_call(IntPtr luaState, int nArgs, int nResults); - - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern int lua_pcall(IntPtr luaState, int nArgs, int nResults, int errfunc); - - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern double lua_tonumber(IntPtr luaState, int index); - - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern int lua_tointeger(IntPtr luaState, int index); - - public static int luaL_loadbuffer(IntPtr luaState, byte[] buff, int size, string name) - { - return LuaDLLWrapper.luaLS_loadbuffer(luaState, buff, size, name); - } - - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern void lua_remove(IntPtr luaState, int index); - - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern void lua_rawgeti(IntPtr luaState, int tableIndex, int index); - - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern void lua_rawseti(IntPtr luaState, int tableIndex, int index); - - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern void lua_pushinteger(IntPtr luaState, IntPtr i); - - public static void lua_pushinteger(IntPtr luaState, int i) - { - lua_pushinteger(luaState, (IntPtr)i); - } - - public static int luaL_checkinteger(IntPtr luaState, int stackPos) - { - luaL_checktype(luaState, stackPos, LuaTypes.LUA_TNUMBER); - return lua_tointeger(luaState, stackPos); - } - - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern void lua_replace(IntPtr luaState, int index); - - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern int lua_setfenv(IntPtr luaState, int stackPos); - - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern int lua_equal(IntPtr luaState, int index1, int index2); - - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern int luaL_loadfile(IntPtr luaState, string filename); -#endif - - - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern void lua_settop(IntPtr luaState, int newTop); - public static void lua_pop(IntPtr luaState, int amount) - { - LuaDLL.lua_settop(luaState, -(amount) - 1); - } - - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern void lua_gettable(IntPtr luaState, int index); - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern void lua_rawget(IntPtr luaState, int index); - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern void lua_settable(IntPtr luaState, int index); - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern void lua_rawset(IntPtr luaState, int index); - -#if LUA_5_3 - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern void lua_setmetatable(IntPtr luaState, int objIndex); -#else - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern int lua_setmetatable(IntPtr luaState, int objIndex); -#endif - - - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern int lua_getmetatable(IntPtr luaState, int objIndex); - - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern void lua_pushvalue(IntPtr luaState, int index); - - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern int lua_gettop(IntPtr luaState); - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern LuaTypes lua_type(IntPtr luaState, int index); - public static bool lua_isnil(IntPtr luaState, int index) - { - return (LuaDLL.lua_type(luaState, index) == LuaTypes.LUA_TNIL); - } - - public static bool lua_isnumber(IntPtr luaState, int index) - { - return LuaDLLWrapper.lua_isnumber(luaState, index) > 0; - } - public static bool lua_isboolean(IntPtr luaState, int index) - { - return LuaDLL.lua_type(luaState, index) == LuaTypes.LUA_TBOOLEAN; - } - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern int luaL_ref(IntPtr luaState, int registryIndex); - - - public static void lua_getref(IntPtr luaState, int reference) - { - LuaDLL.lua_rawgeti(luaState, LuaIndexes.LUA_REGISTRYINDEX, reference); - } - - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern void luaL_unref(IntPtr luaState, int registryIndex, int reference); - public static void lua_unref(IntPtr luaState, int reference) - { - LuaDLL.luaL_unref(luaState, LuaIndexes.LUA_REGISTRYINDEX, reference); - } - - public static bool lua_isstring(IntPtr luaState, int index) - { - return LuaDLLWrapper.lua_isstring(luaState, index) > 0; - } - - public static bool lua_iscfunction(IntPtr luaState, int index) - { - return LuaDLLWrapper.lua_iscfunction(luaState, index) > 0; - } - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern void lua_pushnil(IntPtr luaState); - - public static void luaL_checktype(IntPtr luaState, int p, LuaTypes t) - { - LuaTypes ct = LuaDLL.lua_type(luaState, p); - if (ct != t) - { - throw new Exception(string.Format("arg {0} expect {1}, got {2}", p, lua_typenamestr(luaState, t), lua_typenamestr(luaState, ct))); - } - } - - public static void lua_pushcfunction(IntPtr luaState, LuaCSFunction function) - { -#if SLUA_STANDALONE - // Add all LuaCSFunction or they will be GC collected! (problem at windows, .net framework 4.5, `CallbackOnCollectedDelegated` exception) - GCHandle.Alloc(function); -#endif - IntPtr fn = Marshal.GetFunctionPointerForDelegate(function); - lua_pushcclosure(luaState, fn, 0); - } - - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr lua_tocfunction(IntPtr luaState, int index); - - - public static bool lua_toboolean(IntPtr luaState, int index) - { - return LuaDLLWrapper.lua_toboolean(luaState, index) > 0; - } - - - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr luaS_tolstring32(IntPtr luaState, int index, out int strLen); - - public static string lua_tostring(IntPtr luaState, int index) - { - int strlen; - - IntPtr str = luaS_tolstring32(luaState, index, out strlen); // fix il2cpp 64 bit - - if (str != IntPtr.Zero) - { - return Marshal.PtrToStringAnsi(str, strlen); - } - return null; - } - - public static byte[] lua_tobytes(IntPtr luaState, int index) - { - int strlen; - - IntPtr str = luaS_tolstring32(luaState, index, out strlen); // fix il2cpp 64 bit - - if (str != IntPtr.Zero) - { - byte[] bytes = new byte[strlen]; - Marshal.Copy(str, bytes,0,strlen); - return bytes; - } - return null; - } - - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr lua_atpanic(IntPtr luaState, LuaCSFunction panicf); - - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern void lua_pushnumber(IntPtr luaState, double number); - - public static void lua_pushboolean(IntPtr luaState, bool value) - { - LuaDLLWrapper.lua_pushboolean(luaState, value ? 1 : 0); - } - - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern void lua_pushstring(IntPtr luaState, string str); - - public static void lua_pushlstring(IntPtr luaState, byte[] str, int size) - { - LuaDLLWrapper.luaS_pushlstring(luaState, str, size); - } - - - - - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern int luaL_newmetatable(IntPtr luaState, string meta); - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern void lua_getfield(IntPtr luaState, int stackPos, string meta); - public static void luaL_getmetatable(IntPtr luaState, string meta) - { - LuaDLL.lua_getfield(luaState, LuaIndexes.LUA_REGISTRYINDEX, meta); - } - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr luaL_checkudata(IntPtr luaState, int stackPos, string meta); - - public static bool luaL_getmetafield(IntPtr luaState, int stackPos, string field) - { - return LuaDLLWrapper.luaL_getmetafield(luaState, stackPos, field) > 0; - } - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern int lua_load(IntPtr luaState, LuaChunkReader chunkReader, ref ReaderInfo data, string chunkName); - - - - - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern int lua_error(IntPtr luaState); - - public static bool lua_checkstack(IntPtr luaState, int extra) - { - return LuaDLLWrapper.lua_checkstack(luaState, extra) > 0; - } - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern int lua_next(IntPtr luaState, int index); - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern void lua_pushlightuserdata(IntPtr luaState, IntPtr udata); - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern void luaL_where(IntPtr luaState, int level); - - public static double luaL_checknumber(IntPtr luaState, int stackPos) - { - luaL_checktype(luaState, stackPos, LuaTypes.LUA_TNUMBER); - return lua_tonumber(luaState, stackPos); - } - - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern void lua_concat(IntPtr luaState, int n); - - - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern void luaS_newuserdata(IntPtr luaState, int val); - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern int luaS_rawnetobj(IntPtr luaState, int obj); - - - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr lua_touserdata(IntPtr luaState, int index); - - public static int lua_absindex(IntPtr luaState, int index) - { - return index > 0 ? index : lua_gettop(luaState) + index + 1; - } - - public static int lua_upvalueindex(int i) - { -#if LUA_5_3 - return LuaIndexes.LUA_REGISTRYINDEX - i; -#else - return LuaIndexes.LUA_GLOBALSINDEX - i; -#endif - } - - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern void lua_pushcclosure(IntPtr l, IntPtr f, int nup); - - public static void lua_pushcclosure(IntPtr l, LuaCSFunction f, int nup) - { -#if SLUA_STANDALONE - // Add all LuaCSFunction or they will be GC collected! (problem at windows, .net framework 4.5, `CallbackOnCollectedDelegated` exception) - GCHandle.Alloc(f); -#endif - IntPtr fn = Marshal.GetFunctionPointerForDelegate(f); - lua_pushcclosure(l, fn, nup); - } - - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern int luaS_checkVector2(IntPtr l, int p, out float x, out float y); - - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern int luaS_checkVector3(IntPtr l, int p, out float x, out float y, out float z); - - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern int luaS_checkVector4(IntPtr l, int p, out float x, out float y, out float z, out float w); - - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern int luaS_checkQuaternion(IntPtr l, int p, out float x, out float y, out float z, out float w); - - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern int luaS_checkColor(IntPtr l, int p, out float x, out float y, out float z, out float w); - - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern void luaS_pushVector2(IntPtr l, float x, float y); - - - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern void luaS_pushVector3(IntPtr l, float x, float y, float z); - - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern void luaS_pushVector4(IntPtr l, float x, float y, float z, float w); - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern void luaS_pushQuaternion(IntPtr l, float x, float y, float z, float w); - - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern void luaS_pushColor(IntPtr l, float x, float y, float z, float w); - - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern void luaS_setDataVec(IntPtr l, int p, float x, float y, float z, float w); - - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern int luaS_checkluatype(IntPtr l, int p, string t); - - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern int luaS_pushobject(IntPtr l, int index, string t, bool gco, int cref); - - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern int luaS_getcacheud(IntPtr l, int index, int cref); - - - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern int luaS_subclassof(IntPtr l, int index, string t); - } -} diff --git a/KSFramework/Assets/Plugins/Slua_Managed/LuaDLL.cs.meta b/KSFramework/Assets/Plugins/Slua_Managed/LuaDLL.cs.meta deleted file mode 100644 index 0b5620ea..00000000 --- a/KSFramework/Assets/Plugins/Slua_Managed/LuaDLL.cs.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 65ffd36d393c7be4eaf8adaf63805a23 -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: diff --git a/KSFramework/Assets/Plugins/Slua_Managed/LuaDLLWrapper.cs b/KSFramework/Assets/Plugins/Slua_Managed/LuaDLLWrapper.cs deleted file mode 100644 index 031c455f..00000000 --- a/KSFramework/Assets/Plugins/Slua_Managed/LuaDLLWrapper.cs +++ /dev/null @@ -1,102 +0,0 @@ -namespace LuaInterface -{ - using System; - using System.Runtime.InteropServices; - using System.Reflection; - using System.Collections; - using System.Text; - using System.Security; - - - - /** Modify Record: - - lua_xmove: return void - //lua_gc: LuaDLLWrapper: enum->int。 - - lua_objlen:   lua 5.1: luaS_objlen size_t->int - lua_rawlen: lua 5.3: luaS_rawlen size_t->int - - lua_setmetatable: lua 5.1 return int - lua 5.3 return void - - //lua_type: LuaDLLWrapper: return int->enum - lua_isnumber:  LuaDLLWrapper: return bool->int - lua_isstring: LuaDLLWrapper: return bool->int - lua_iscfunction: LuaDLLWrapper: return bool->int - - lua_call: 5.1 return int->void - - lua_toboolean: LuaDLLWrapper: return bool->int - - lua_atpanic: return void->intptr - - lua_pushboolean: LuaDLLWrapper: bool ->int - lua_pushlstring: LuaDLLWrapper: luaS_pushlstring. size_t->int - - luaL_getmetafield: LuaDLLWrapper: return bool->int - luaL_loadbuffe: LuaDLLWrapper luaLS_loadbuffer size_t CharSet - - lua_error: return void->int - lua_checkstack:  LuaDLLWrapper return bool->int - - - **/ - - public class LuaDLLWrapper - { - -#if UNITY_IPHONE && !UNITY_EDITOR - const string LUADLL = "__Internal"; -#else - const string LUADLL = "slua"; -#endif - -#if LUA_5_3 - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern int luaS_rawlen(IntPtr luaState, int index); -#else - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern int luaS_objlen(IntPtr luaState, int stackPos); -#endif - - - //[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - //public static extern int lua_gc(IntPtr luaState, int what, int data); - - //[DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)] - //public static extern int lua_type(IntPtr luaState, int index); - - [DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)] - public static extern int lua_isnumber(IntPtr luaState, int index); - - - [DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)] - public static extern int lua_isstring(IntPtr luaState, int index); - - [DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)] - public static extern int lua_iscfunction(IntPtr luaState, int index); - - [DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)] - public static extern int lua_toboolean(IntPtr luaState, int index); - - - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern void lua_pushboolean(IntPtr luaState, int value); - - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern void luaS_pushlstring(IntPtr luaState, byte[] str, int size); - - - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern int luaL_getmetafield(IntPtr luaState, int stackPos, string field); - - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern int luaLS_loadbuffer(IntPtr luaState, byte[] buff, int size, string name); - - [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - public static extern int lua_checkstack(IntPtr luaState, int extra); - } - - -} diff --git a/KSFramework/Assets/Plugins/Slua_Managed/LuaObject.cs b/KSFramework/Assets/Plugins/Slua_Managed/LuaObject.cs deleted file mode 100644 index cfd6b9ad..00000000 --- a/KSFramework/Assets/Plugins/Slua_Managed/LuaObject.cs +++ /dev/null @@ -1,1473 +0,0 @@ -// The MIT License (MIT) - -// Copyright 2015 Siney/Pangweiwei siney@yeah.net -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -namespace SLua -{ - -#if !SLUA_STANDALONE - using UnityEngine; -#endif - using System.Collections; - using System.Collections.Generic; - using System; - using LuaInterface; - using System.Reflection; - using System.Runtime.InteropServices; - - [AttributeUsage(AttributeTargets.Class | AttributeTargets.Enum | AttributeTargets.Struct)] - public class CustomLuaClassAttribute : System.Attribute - { - public CustomLuaClassAttribute() - { - // - } - } - - public class DoNotToLuaAttribute : System.Attribute - { - public DoNotToLuaAttribute() - { - // - } - } - - public class LuaBinderAttribute : System.Attribute - { - public int order; - public LuaBinderAttribute(int order) - { - this.order = order; - } - } - - [AttributeUsage(AttributeTargets.Method)] - public class StaticExportAttribute : System.Attribute - { - public StaticExportAttribute() - { - // - } - } - - public class LuaOut { } - - public partial class LuaObject - { - - static protected LuaCSFunction lua_gc = new LuaCSFunction(luaGC); - static protected LuaCSFunction lua_add = new LuaCSFunction(luaAdd); - static protected LuaCSFunction lua_sub = new LuaCSFunction(luaSub); - static protected LuaCSFunction lua_mul = new LuaCSFunction(luaMul); - static protected LuaCSFunction lua_div = new LuaCSFunction(luaDiv); - static protected LuaCSFunction lua_unm = new LuaCSFunction(luaUnm); - static protected LuaCSFunction lua_eq = new LuaCSFunction(luaEq); - static protected LuaCSFunction lua_lt = new LuaCSFunction(luaLt); - static protected LuaCSFunction lua_le = new LuaCSFunction(luaLe); - static protected LuaCSFunction lua_tostring = new LuaCSFunction(ToString); - const string DelgateTable = "__LuaDelegate"; - - static protected LuaFunction newindex_func; - static protected LuaFunction index_func; - - delegate void PushVarDelegate(IntPtr l, object o); - static Dictionary typePushMap = new Dictionary(); - - internal const int VersionNumber = 0x1011; - - public static void init(IntPtr l) - { - string newindexfun = @" - -local getmetatable=getmetatable -local rawget=rawget -local error=error -local type=type -local function newindex(ud,k,v) - local t=getmetatable(ud) - repeat - local h=rawget(t,k) - if h then - if h[2] then - h[2](ud,v) - return - else - error('property '..k..' is read only') - end - end - t=rawget(t,'__parent') - until t==nil - error('can not find '..k) -end - -return newindex -"; - - string indexfun = @" -local type=type -local error=error -local rawget=rawget -local getmetatable=getmetatable -local function index(ud,k) - local t=getmetatable(ud) - repeat - local fun=rawget(t,k) - local tp=type(fun) - if tp=='function' then - return fun - elseif tp=='table' then - local f=fun[1] - if f then - return f(ud) - else - error('property '..k..' is write only') - end - end - t = rawget(t,'__parent') - until t==nil - error('Can not find '..k) -end - -return index -"; - LuaState L = LuaState.get(l); - newindex_func = (LuaFunction)L.doString(newindexfun); - index_func = (LuaFunction)L.doString(indexfun); - - // object method - LuaDLL.lua_createtable(l, 0, 4); - addMember(l, ToString); - addMember(l, GetHashCode); - addMember(l, Equals); - addMember (l, GetType); - LuaDLL.lua_setfield(l, LuaIndexes.LUA_REGISTRYINDEX, "__luabaseobject"); - - LuaArray.init(l); - LuaVarObject.init(l); - - LuaDLL.lua_newtable(l); - LuaDLL.lua_setglobal(l, DelgateTable); - - - setupPushVar(); - } - - [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))] - static public int ToString(IntPtr l) - { - try - { - object obj = checkVar(l, 1); - pushValue(l, true); - pushValue(l, obj.ToString()); - return 2; - } - catch (Exception e) - { - return error(l, e); - } - } - - [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))] - static public int GetHashCode(IntPtr l) - { - try - { - object obj = checkVar(l, 1); - pushValue(l, true); - pushValue(l, obj.GetHashCode()); - return 2; - } - catch (Exception e) - { - return error(l, e); - } - } - - [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))] - static public int Equals(IntPtr l) - { - try - { - object obj = checkVar(l, 1); - object other = checkVar(l, 2); - pushValue(l, true); - pushValue(l, obj.Equals(other)); - return 2; - } - catch (Exception e) - { - return error(l, e); - } - } - - [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))] - static public int GetType(IntPtr l) - { - try - { - object obj = checkVar(l, 1); - pushValue(l, true); - pushObject(l, obj.GetType()); - return 2; - } - catch (Exception e) - { - return error(l, e); - } - } - - static void setupPushVar() - { - typePushMap[typeof(float)] = (IntPtr L, object o) => - { - LuaDLL.lua_pushnumber(L, (float)o); - }; - typePushMap[typeof(double)] = (IntPtr L, object o) => - { - LuaDLL.lua_pushnumber(L, (double)o); - }; - - typePushMap[typeof(int)] = - (IntPtr L, object o) => - { - LuaDLL.lua_pushinteger(L, (int)o); - }; - - typePushMap[typeof(uint)] = - (IntPtr L, object o) => - { - LuaDLL.lua_pushnumber(L, Convert.ToUInt32(o)); - }; - - typePushMap[typeof(short)] = - (IntPtr L, object o) => - { - LuaDLL.lua_pushinteger(L, (short)o); - }; - - typePushMap[typeof(ushort)] = - (IntPtr L, object o) => - { - LuaDLL.lua_pushinteger(L, (ushort)o); - }; - - typePushMap[typeof(sbyte)] = - (IntPtr L, object o) => - { - LuaDLL.lua_pushinteger(L, (sbyte)o); - }; - - typePushMap[typeof(byte)] = - (IntPtr L, object o) => - { - LuaDLL.lua_pushinteger(L, (byte)o); - }; - - - typePushMap[typeof(Int64)] = - typePushMap[typeof(UInt64)] = - (IntPtr L, object o) => - { -#if LUA_5_3 - LuaDLL.lua_pushinteger(L, (long)o); -#else - LuaDLL.lua_pushnumber(L, System.Convert.ToDouble(o)); -#endif - }; - - typePushMap[typeof(string)] = (IntPtr L, object o) => - { - LuaDLL.lua_pushstring(L, (string)o); - }; - - typePushMap[typeof(bool)] = (IntPtr L, object o) => - { - LuaDLL.lua_pushboolean(L, (bool)o); - }; - - typePushMap[typeof(LuaTable)] = - typePushMap[typeof(LuaFunction)] = - typePushMap[typeof(LuaThread)] = - (IntPtr L, object o) => - { - ((LuaVar)o).push(L); - }; -#if !SLUA_STANDALONE - typePushMap[typeof(Vector3)] = (IntPtr L, object o) => - { - pushValue(L, (Vector3)o); - }; - - typePushMap[typeof(Vector2)] = (IntPtr L, object o) => - { - pushValue(L, (Vector2)o); - }; - - typePushMap[typeof(Vector4)] = (IntPtr L, object o) => - { - pushValue(L, (Vector4)o); - }; - - typePushMap[typeof(Quaternion)] = (IntPtr L, object o) => - { - pushValue(L, (Quaternion)o); - }; - - typePushMap[typeof(Color)] = (IntPtr L, object o) => - { - pushValue(L, (Color)o); - }; -#endif - - typePushMap[typeof(LuaCSFunction)] = (IntPtr L, object o) => - { - pushValue(L, (LuaCSFunction)o); - }; - } - - static int getOpFunction(IntPtr l, string f, string tip) - { - int err = pushTry(l); - checkLuaObject(l, 1); - - while (!LuaDLL.lua_isnil(l, -1)) - { - LuaDLL.lua_getfield(l, -1, f); - if (!LuaDLL.lua_isnil(l, -1)) - { - LuaDLL.lua_remove(l, -2); - break; - } - LuaDLL.lua_pop(l, 1); //pop nil - LuaDLL.lua_getfield(l, -1, "__parent"); - LuaDLL.lua_remove(l, -2); //pop base - } - - if (LuaDLL.lua_isnil(l, -1)) - { - LuaDLL.lua_pop(l, 1); - throw new Exception(string.Format("No {0} operator", tip)); - } - return err; - } - - static int luaOp(IntPtr l, string f, string tip) - { - int err = getOpFunction(l, f, tip); - LuaDLL.lua_pushvalue(l, 1); - LuaDLL.lua_pushvalue(l, 2); - if (LuaDLL.lua_pcall(l, 2, 1, err) != 0) - LuaDLL.lua_pop(l, 1); - LuaDLL.lua_remove(l, err); - pushValue(l, true); - LuaDLL.lua_insert(l, -2); - return 2; - } - - - static int luaUnaryOp(IntPtr l, string f, string tip) - { - int err = getOpFunction(l, f, tip); - LuaDLL.lua_pushvalue(l, 1); - if (LuaDLL.lua_pcall(l, 1, 1, err) != 0) - LuaDLL.lua_pop(l, 1); - LuaDLL.lua_remove(l, err); - pushValue(l, true); - LuaDLL.lua_insert(l, -2); - return 2; - } - - [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))] - static public int luaAdd(IntPtr l) - { - try - { - return luaOp(l, "op_Addition", "add"); - } - catch(Exception e) - { - return error(l, e); - } - } - - [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))] - static public int luaSub(IntPtr l) - { - try - { - return luaOp(l, "op_Subtraction", "sub"); - } - catch (Exception e) - { - return error(l, e); - } - } - - [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))] - static public int luaMul(IntPtr l) - { - try - { - return luaOp(l, "op_Multiply", "mul"); - } - catch (Exception e) - { - return error(l, e); - } - } - - [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))] - static public int luaDiv(IntPtr l) - { - try - { - return luaOp(l, "op_Division", "div"); - } - catch (Exception e) - { - return error(l, e); - } - } - - [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))] - static public int luaUnm(IntPtr l) - { - try - { - return luaUnaryOp(l, "op_UnaryNegation", "unm"); - } - catch (Exception e) - { - return error(l, e); - } - } - - [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))] - static public int luaEq(IntPtr l) - { - try - { - return luaOp(l, "op_Equality", "eq"); - } - catch (Exception e) - { - return error(l, e); - } - } - - [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))] - static public int luaLt(IntPtr l) - { - try - { - return luaOp(l, "op_LessThan", "lt"); - } - catch (Exception e) - { - return error(l, e); - } - } - - [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))] - static public int luaLe(IntPtr l) - { - try - { - return luaOp(l, "op_LessThanOrEqual", "le"); - } - catch (Exception e) - { - return error(l, e); - } - } - - public static void getEnumTable(IntPtr l, string t) - { - newTypeTable(l, t); - } - - public static void getTypeTable(IntPtr l, string t) - { - newTypeTable(l, t); - // for static - LuaDLL.lua_newtable(l); - // for instance - LuaDLL.lua_newtable(l); - } - - public static void newTypeTable(IntPtr l, string name) - { - string[] subt = name.Split('.'); - - LuaDLL.lua_pushglobaltable(l); - - foreach(string t in subt) - { - LuaDLL.lua_pushstring(l, t); - LuaDLL.lua_rawget(l, -2); - if (LuaDLL.lua_isnil(l, -1)) - { - LuaDLL.lua_pop(l, 1); - LuaDLL.lua_createtable(l, 0, 0); - LuaDLL.lua_pushstring(l, t); - LuaDLL.lua_pushvalue(l, -2); - LuaDLL.lua_rawset(l, -4); - } - LuaDLL.lua_remove(l, -2); - } - } - - public static void createTypeMetatable(IntPtr l, Type self) - { - createTypeMetatable(l, null, self, null); - } - - public static void createTypeMetatable(IntPtr l, LuaCSFunction con, Type self) - { - createTypeMetatable(l, con, self, null); - } - - static void checkMethodValid(LuaCSFunction f) - { -#if UNITY_EDITOR - if (f != null && !Attribute.IsDefined(f.Method, typeof(MonoPInvokeCallbackAttribute))) - { - Logger.LogError(string.Format("MonoPInvokeCallbackAttribute not defined for LuaCSFunction {0}.", f.Method)); - } -#endif - } - - public static void createTypeMetatable(IntPtr l, LuaCSFunction con, Type self, Type parent) - { - checkMethodValid(con); - - // set parent - if (parent != null && parent != typeof(object) && parent != typeof(ValueType)) - { - LuaDLL.lua_pushstring(l, "__parent"); - LuaDLL.luaL_getmetatable(l, ObjectCache.getAQName(parent)); - LuaDLL.lua_rawset(l, -3); - - LuaDLL.lua_pushstring(l, "__parent"); - LuaDLL.luaL_getmetatable(l, parent.FullName); - LuaDLL.lua_rawset(l, -4); - } - else - { - LuaDLL.lua_pushstring(l, "__parent"); - LuaDLL.luaL_getmetatable(l, "__luabaseobject"); - LuaDLL.lua_rawset(l, -3); - } - - completeInstanceMeta(l, self); - completeTypeMeta(l, con, self); - - LuaDLL.lua_pop(l, 1); // pop type Table - } - - static void completeTypeMeta(IntPtr l, LuaCSFunction con, Type self) - { - - LuaDLL.lua_pushstring(l, ObjectCache.getAQName(self)); - LuaDLL.lua_setfield(l, -3, "__fullname"); - - index_func.push(l); - LuaDLL.lua_setfield(l, -2, "__index"); - - newindex_func.push(l); - LuaDLL.lua_setfield(l, -2, "__newindex"); - - if (con == null) con = noConstructor; - - pushValue(l, con); - LuaDLL.lua_setfield(l, -2, "__call"); - - LuaDLL.lua_pushcfunction(l, typeToString); - LuaDLL.lua_setfield(l, -2, "__tostring"); - - LuaDLL.lua_pushvalue(l, -1); - LuaDLL.lua_setmetatable(l, -3); - - LuaDLL.lua_setfield(l, LuaIndexes.LUA_REGISTRYINDEX, self.FullName); - } - - private static void completeInstanceMeta(IntPtr l, Type self) - { - LuaDLL.lua_pushstring(l, "__typename"); - LuaDLL.lua_pushstring(l, self.Name); - LuaDLL.lua_rawset(l, -3); - - // for instance - index_func.push(l); - LuaDLL.lua_setfield(l, -2, "__index"); - - newindex_func.push(l); - LuaDLL.lua_setfield(l, -2, "__newindex"); - - pushValue(l, lua_add); - LuaDLL.lua_setfield(l, -2, "__add"); - pushValue(l, lua_sub); - LuaDLL.lua_setfield(l, -2, "__sub"); - pushValue(l, lua_mul); - LuaDLL.lua_setfield(l, -2, "__mul"); - pushValue(l, lua_div); - LuaDLL.lua_setfield(l, -2, "__div"); - pushValue(l, lua_unm); - LuaDLL.lua_setfield(l, -2, "__unm"); - pushValue(l, lua_eq); - LuaDLL.lua_setfield(l, -2, "__eq"); - pushValue(l, lua_le); - LuaDLL.lua_setfield(l, -2, "__le"); - pushValue(l, lua_lt); - LuaDLL.lua_setfield(l, -2, "__lt"); - pushValue(l, lua_tostring); - LuaDLL.lua_setfield(l, -2, "__tostring"); - - LuaDLL.lua_pushcfunction(l, lua_gc); - LuaDLL.lua_setfield(l, -2, "__gc"); - - if (self.IsValueType && isImplByLua(self)) - { - LuaDLL.lua_pushvalue(l, -1); - LuaDLL.lua_setglobal(l, self.FullName + ".Instance"); - } - LuaDLL.lua_setfield(l, LuaIndexes.LUA_REGISTRYINDEX, ObjectCache.getAQName(self)); - } - - - public static bool isImplByLua(Type t) - { -#if !SLUA_STANDALONE - return t == typeof(Color) - || t == typeof(Vector2) - || t == typeof(Vector3) - || t == typeof(Vector4) - || t == typeof(Quaternion); -#else - return false; -#endif - } - - - public static void reg(IntPtr l, LuaCSFunction func, string ns) - { - checkMethodValid(func); - - newTypeTable(l, ns); - pushValue(l, func); - LuaDLL.lua_setfield(l, -2, func.Method.Name); - LuaDLL.lua_pop(l, 1); - } - - protected static void addMember(IntPtr l, LuaCSFunction func) - { - checkMethodValid(func); - - pushValue(l, func); - string name = func.Method.Name; - if (name.EndsWith("_s")) - { - name = name.Substring(0, name.Length - 2); - LuaDLL.lua_setfield(l, -3, name); - } - else - LuaDLL.lua_setfield(l, -2, name); - } - - protected static void addMember(IntPtr l, LuaCSFunction func, bool instance) - { - checkMethodValid(func); - - pushValue(l, func); - string name = func.Method.Name; - LuaDLL.lua_setfield(l, instance ? -2 : -3, name); - } - - protected static void addMember(IntPtr l, string name, LuaCSFunction get, LuaCSFunction set, bool instance) - { - checkMethodValid(get); - checkMethodValid(set); - - int t = instance ? -2 : -3; - - LuaDLL.lua_createtable(l, 2, 0); - if (get == null) - LuaDLL.lua_pushnil(l); - else - pushValue(l, get); - LuaDLL.lua_rawseti(l, -2, 1); - - if (set == null) - LuaDLL.lua_pushnil(l); - else - pushValue(l, set); - LuaDLL.lua_rawseti(l, -2, 2); - - LuaDLL.lua_setfield(l, t, name); - } - - protected static void addMember(IntPtr l, int v, string name) - { - LuaDLL.lua_pushinteger(l, v); - LuaDLL.lua_setfield(l, -2, name); - } - - [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))] - static public int luaGC(IntPtr l) - { - int index = LuaDLL.luaS_rawnetobj(l, 1); - if (index > 0) - { - ObjectCache t = ObjectCache.get(l); - t.gc(index); - } - return 0; - } -#if !SLUA_STANDALONE - static internal void gc(IntPtr l,int p,UnityEngine.Object o) - { - // set ud's metatable is nil avoid gc again - LuaDLL.lua_pushnil(l); - LuaDLL.lua_setmetatable(l, p); - - ObjectCache t = ObjectCache.get(l); - t.gc(o); - } -#endif - - static public void checkLuaObject(IntPtr l, int p) - { - LuaDLL.lua_getmetatable(l, p); - if (LuaDLL.lua_isnil(l, -1)) - { - LuaDLL.lua_pop(l, 1); - throw new Exception("expect luaobject as first argument"); - } - } - - public static void pushObject(IntPtr l, object o) - { - ObjectCache oc = ObjectCache.get(l); - oc.push(l, o); - } - - public static void pushObject(IntPtr l, Array o) - { - ObjectCache oc = ObjectCache.get(l); - oc.push(l, o); - } - - // lightobj is non-exported object used for re-get from c#, not for lua - public static void pushLightObject(IntPtr l, object t) - { - ObjectCache oc = ObjectCache.get(l); - oc.push(l, t, false); - } - - public static int pushTry(IntPtr l) - { - if (!LuaState.get(l).isMainThread()) - { - Logger.LogError("Can't call lua function in bg thread"); - return 0; - } - - LuaDLL.lua_pushcfunction(l, LuaState.errorFunc); - return LuaDLL.lua_gettop(l); - } - - - public static bool matchType(IntPtr l, int p, LuaTypes lt, Type t) - { - if (t == typeof(object)) - { - return true; - } - else if (t == typeof(Type) && isTypeTable(l, p)) - { - return true; - } - else if (t == typeof(char[]) || t==typeof(byte[])) - { - return lt == LuaTypes.LUA_TSTRING; - } - - switch (lt) - { - case LuaTypes.LUA_TNIL: - return !t.IsValueType && !t.IsPrimitive; - case LuaTypes.LUA_TNUMBER: -#if LUA_5_3 - if (LuaDLL.lua_isinteger(l, p) > 0) - return (t.IsPrimitive && t != typeof(float) && t != typeof(double)) || t.IsEnum; - else - return t == typeof(float) || t == typeof(double); -#else - return t.IsPrimitive || t.IsEnum; -#endif - case LuaTypes.LUA_TUSERDATA: - object o = checkObj(l, p); - Type ot = o.GetType(); - return ot == t || ot.IsSubclassOf(t); - case LuaTypes.LUA_TSTRING: - return t == typeof(string); - case LuaTypes.LUA_TBOOLEAN: - return t == typeof(bool); - case LuaTypes.LUA_TTABLE: - { - if (t == typeof(LuaTable) || t.IsArray) - return true; - else if (t.IsValueType) - return true;//luaTypeCheck(l, p, t.Name); - else if (LuaDLL.luaS_subclassof(l, p, t.Name) == 1) - return true; - else - return false; - } - case LuaTypes.LUA_TFUNCTION: - return t == typeof(LuaFunction) || t.BaseType == typeof(MulticastDelegate); - case LuaTypes.LUA_TTHREAD: - return t == typeof(LuaThread); - - } - return false; - } - - public static bool isTypeTable(IntPtr l, int p) - { - if (LuaDLL.lua_type(l, p) != LuaTypes.LUA_TTABLE) - return false; - LuaDLL.lua_pushstring(l, "__fullname"); - LuaDLL.lua_rawget(l, p); - if (LuaDLL.lua_isnil(l, -1)) - { - LuaDLL.lua_pop(l, 1); - return false; - } - return true; - } - - public static bool isLuaClass(IntPtr l, int p) - { - return LuaDLL.luaS_subclassof(l, p, null) == 1; - } - - static bool isLuaValueType(IntPtr l, int p) - { - return LuaDLL.luaS_checkluatype(l, p, null) == 1; - } - - public static bool matchType(IntPtr l, int p, Type t1) - { - LuaTypes t = LuaDLL.lua_type(l, p); - return matchType(l, p, t, t1); - } - - public static bool matchType(IntPtr l, int total, int from, Type t1) - { - if (total - from + 1 != 1) - return false; - - return matchType(l, from, t1); - } - - public static bool matchType(IntPtr l, int total, int from, Type t1, Type t2) - { - if (total - from + 1 != 2) - return false; - - return matchType(l, from, t1) && matchType(l, from + 1, t2); - } - - public static bool matchType(IntPtr l, int total, int from, Type t1, Type t2, Type t3) - { - if (total - from + 1 != 3) - return false; - - return matchType(l, from, t1) && matchType(l, from + 1, t2) && matchType(l, from + 2, t3); - } - - public static bool matchType(IntPtr l, int total, int from, Type t1, Type t2, Type t3, Type t4) - { - if (total - from + 1 != 4) - return false; - - return matchType(l, from, t1) && matchType(l, from + 1, t2) && matchType(l, from + 2, t3) && matchType(l, from + 3, t4); - } - - public static bool matchType(IntPtr l, int total, int from, Type t1, Type t2, Type t3, Type t4, Type t5) - { - if (total - from + 1 != 5) - return false; - - return matchType(l, from, t1) && matchType(l, from + 1, t2) && matchType(l, from + 2, t3) && matchType(l, from + 3, t4) - && matchType(l, from + 4, t5); - } - - public static bool matchType - (IntPtr l, int total, int from, Type t1, Type t2, Type t3, Type t4, Type t5,Type t6) - { - if (total - from + 1 != 6) - return false; - - return matchType(l, from, t1) && matchType(l, from + 1, t2) && matchType(l, from + 2, t3) && matchType(l, from + 3, t4) - && matchType(l, from + 4, t5) - && matchType(l, from + 5, t6); - } - - public static bool matchType - (IntPtr l, int total, int from, Type t1, Type t2, Type t3, Type t4, Type t5,Type t6,Type t7) - { - if (total - from + 1 != 7) - return false; - - return matchType(l, from, t1) && matchType(l, from + 1, t2) && matchType(l, from + 2, t3) && matchType(l, from + 3, t4) - && matchType(l, from + 4, t5) - && matchType(l, from + 5, t6) - && matchType(l, from + 6, t7); - } - - public static bool matchType - (IntPtr l, int total, int from, Type t1, Type t2, Type t3, Type t4, Type t5,Type t6,Type t7,Type t8) - { - if (total - from + 1 != 8) - return false; - - return matchType(l, from, t1) && matchType(l, from + 1, t2) && matchType(l, from + 2, t3) && matchType(l, from + 3, t4) - && matchType(l, from + 4, t5) - && matchType(l, from + 5, t6) - && matchType(l, from + 6, t7) - && matchType(l, from + 7, t8); - } - - - public static bool matchType - (IntPtr l, int total, int from, Type t1, Type t2, Type t3, Type t4, Type t5,Type t6,Type t7,Type t8,Type t9) - { - if (total - from + 1 != 9) - return false; - - return matchType(l, from, t1) && matchType(l, from + 1, t2) && matchType(l, from + 2, t3) && matchType(l, from + 3, t4) - && matchType(l, from + 4, t5) - && matchType(l, from + 5, t6) - && matchType(l, from + 6, t7) - && matchType(l, from + 7, t8) - && matchType(l, from + 8, t9); - } - - public static bool matchType - (IntPtr l, int total, int from, Type t1, Type t2, Type t3, Type t4, Type t5,Type t6,Type t7,Type t8,Type t9,Type t10) - { - if (total - from + 1 != 10) - return false; - - return matchType(l, from, t1) && matchType(l, from + 1, t2) && matchType(l, from + 2, t3) && matchType(l, from + 3, t4) - && matchType(l, from + 4, t5) - && matchType(l, from + 5, t6) - && matchType(l, from + 6, t7) - && matchType(l, from + 7, t8) - && matchType(l, from + 8, t9) - && matchType(l, from + 9, t10); - } - - public static bool matchType(IntPtr l, int total, int from, params Type[] t) - { - if (total - from + 1 != t.Length) - return false; - - for (int i = 0; i < t.Length; ++i) - { - if (!matchType(l, from + i, t[i])) - return false; - } - - return true; - } - - public static bool matchType(IntPtr l, int total, int from, ParameterInfo[] pars) - { - if (total - from + 1 != pars.Length) - return false; - - for (int n = 0; n < pars.Length; n++) - { - int p = n + from; - LuaTypes t = LuaDLL.lua_type(l, p); - if (!matchType(l, p, t, pars[n].ParameterType)) - return false; - } - return true; - } - - static public bool luaTypeCheck(IntPtr l, int p, string t) - { - return LuaDLL.luaS_checkluatype(l, p, t) != 0; - } - - static LuaDelegate newDelegate(IntPtr l, int p) - { - LuaState state = LuaState.get(l); - - LuaDLL.lua_pushvalue(l, p); // push function - - int fref = LuaDLL.luaL_ref(l, LuaIndexes.LUA_REGISTRYINDEX); // new ref function - LuaDelegate f = new LuaDelegate(l, fref); - LuaDLL.lua_pushvalue(l, p); - LuaDLL.lua_pushinteger(l, fref); - LuaDLL.lua_settable(l, -3); // __LuaDelegate[func]= fref - state.delgateMap[fref] = f; - return f; - } - - static public void removeDelgate(IntPtr l, int r) - { - LuaDLL.lua_getglobal(l, DelgateTable); - LuaDLL.lua_getref(l, r); // push key - LuaDLL.lua_pushnil(l); // push nil value - LuaDLL.lua_settable(l, -3); // remove function from __LuaDelegate table - LuaDLL.lua_pop(l, 1); // pop __LuaDelegate - } - - static public object checkObj(IntPtr l, int p) - { - ObjectCache oc = ObjectCache.get(l); - return oc.get(l, p); - } - - static public bool checkArray(IntPtr l, int p, out T[] ta) - { - if (LuaDLL.lua_type(l, p) == LuaTypes.LUA_TTABLE) - { - int n = LuaDLL.lua_rawlen(l, p); - ta = new T[n]; - for (int k = 0; k < n; k++) - { - LuaDLL.lua_rawgeti(l, p, k + 1); - ta[k]=(T)Convert.ChangeType(checkVar(l, -1),typeof(T)); - LuaDLL.lua_pop(l, 1); - } - return true; - } - else - { - Array array = checkObj(l, p) as Array; - ta = array as T[]; - return ta!=null; - } - } - - static public bool checkParams(IntPtr l, int p, out T[] pars) where T:class - { - int top = LuaDLL.lua_gettop(l); - if (top - p >= 0) - { - pars = new T[top - p + 1]; - for (int n = p, k = 0; n <= top; n++, k++) - { - checkType(l, n, out pars[k]); - } - return true; - } - pars = new T[0]; - return true; - } - - static public bool checkValueParams(IntPtr l, int p, out T[] pars) where T : struct - { - int top = LuaDLL.lua_gettop(l); - if (top - p >= 0) - { - pars = new T[top - p + 1]; - for (int n = p, k = 0; n <= top; n++, k++) - { - checkValueType(l, n, out pars[k]); - } - return true; - } - pars = new T[0]; - return true; - } - - static public bool checkParams(IntPtr l, int p, out float[] pars) - { - int top = LuaDLL.lua_gettop(l); - if (top - p >= 0) - { - pars = new float[top - p + 1]; - for (int n = p, k = 0; n <= top; n++, k++) - { - checkType(l, n, out pars[k]); - } - return true; - } - pars = new float[0]; - return true; - } - - static public bool checkParams(IntPtr l, int p, out int[] pars) - { - int top = LuaDLL.lua_gettop(l); - if (top - p >= 0) - { - pars = new int[top - p + 1]; - for (int n = p, k = 0; n <= top; n++, k++) - { - checkType(l, n, out pars[k]); - } - return true; - } - pars = new int[0]; - return true; - } - - - - static public bool checkParams(IntPtr l, int p, out string[] pars) - { - int top = LuaDLL.lua_gettop(l); - if (top - p >= 0) - { - pars = new string[top - p + 1]; - for (int n = p, k = 0; n <= top; n++, k++) - { - checkType(l, n, out pars[k]); - } - return true; - } - pars = new string[0]; - return true; - } - - static public bool checkParams(IntPtr l, int p, out char[] pars) - { - LuaDLL.luaL_checktype(l, p, LuaTypes.LUA_TSTRING); - string s; - checkType(l, p, out s); - pars = s.ToCharArray(); - return true; - } - - static public object checkVar(IntPtr l, int p, Type t) - { - object obj = checkVar(l, p); - try - { - if (t.IsEnum) - { - // double to int - var number = Convert.ChangeType(obj, typeof(int)); - return Enum.ToObject(t, number); - } - - return obj == null ? null : Convert.ChangeType(obj, t); - } - catch(Exception e) { - throw new Exception(string.Format("parameter {0} expected {1}, got {2}, exception: {3}", p, t.Name, obj == null ? "null" : obj.GetType().Name, e.Message)); - } - } - - static public object checkVar(IntPtr l, int p) - { - LuaTypes type = LuaDLL.lua_type(l, p); - switch (type) - { - case LuaTypes.LUA_TNUMBER: - { - return LuaDLL.lua_tonumber(l, p); - } - case LuaTypes.LUA_TSTRING: - { - return LuaDLL.lua_tostring(l, p); - } - case LuaTypes.LUA_TBOOLEAN: - { - return LuaDLL.lua_toboolean(l, p); - } - case LuaTypes.LUA_TFUNCTION: - { - LuaFunction v; - LuaObject.checkType(l, p, out v); - return v; - } - case LuaTypes.LUA_TTABLE: - { - if (isLuaValueType(l, p)) - { -#if !SLUA_STANDALONE - if (luaTypeCheck(l, p, "Vector2")) - { - Vector2 v; - checkType(l, p, out v); - return v; - } - else if (luaTypeCheck(l, p, "Vector3")) - { - Vector3 v; - checkType(l, p, out v); - return v; - } - else if (luaTypeCheck(l, p, "Vector4")) - { - Vector4 v; - checkType(l, p, out v); - return v; - } - else if (luaTypeCheck(l, p, "Quaternion")) - { - Quaternion v; - checkType(l, p, out v); - return v; - } - else if (luaTypeCheck(l, p, "Color")) - { - Color c; - checkType(l, p, out c); - return c; - } -#endif - Logger.LogError("unknown lua value type"); - return null; - } - else if (isLuaClass(l, p)) - { - return checkObj(l, p); - } - else - { - LuaTable v; - checkType(l,p,out v); - return v; - } - } - case LuaTypes.LUA_TUSERDATA: - return LuaObject.checkObj(l, p); - case LuaTypes.LUA_TTHREAD: - { - LuaThread lt; - LuaObject.checkType(l, p, out lt); - return lt; - } - default: - return null; - } - } - - - public static void pushValue(IntPtr l, object o) - { - pushVar(l, o); - } - - public static void pushValue(IntPtr l, Array a) - { - pushObject(l, a); - } - - public static void pushVar(IntPtr l, object o) - { - if (o == null) - { - LuaDLL.lua_pushnil(l); - return; - } - - - Type t = o.GetType(); - - - PushVarDelegate push; - if (typePushMap.TryGetValue(t, out push)) - push(l, o); - else if (t.IsEnum) - { - pushEnum(l, Convert.ToInt32(o)); - } - else if (t.IsArray) - pushObject(l, (Array)o); - else - pushObject(l, o); - - } - - - - public static T checkSelf(IntPtr l) - { - object o = checkObj(l, 1); - if (o != null) - { - return (T)o; - } - throw new Exception("arg 1 expect self, but get null"); - } - - public static object checkSelf(IntPtr l) - { - object o = checkObj(l, 1); - if (o == null) - throw new Exception("expect self, but get null"); - return o; - } - - public static void setBack(IntPtr l, object o) - { - ObjectCache t = ObjectCache.get(l); - t.setBack(l, 1, o); - } - -#if !SLUA_STANDALONE - public static void setBack(IntPtr l, Vector3 v) - { - LuaDLL.luaS_setDataVec(l, 1, v.x, v.y, v.z, float.NaN); - } - - public static void setBack(IntPtr l, Vector2 v) - { - LuaDLL.luaS_setDataVec(l, 1, v.x, v.y, float.NaN, float.NaN); - } - - public static void setBack(IntPtr l, Vector4 v) - { - LuaDLL.luaS_setDataVec(l, 1, v.x, v.y, v.z, v.w); - } - - public static void setBack(IntPtr l, Quaternion v) - { - LuaDLL.luaS_setDataVec(l, 1, v.x, v.y, v.z, v.w); - } - - public static void setBack(IntPtr l, Color v) - { - LuaDLL.luaS_setDataVec(l, 1, v.r, v.g, v.b, v.a); - } -#endif - - public static int extractFunction(IntPtr l, int p) - { - int op = 0; - LuaTypes t = LuaDLL.lua_type(l, p); - switch (t) - { - case LuaTypes.LUA_TNIL: - case LuaTypes.LUA_TUSERDATA: - op = 0; - break; - - case LuaTypes.LUA_TTABLE: - - LuaDLL.lua_rawgeti(l, p, 1); - LuaDLL.lua_pushstring(l, "+="); - if (LuaDLL.lua_rawequal(l, -1, -2) == 1) - op = 1; - else - op = 2; - - LuaDLL.lua_pop(l, 2); - LuaDLL.lua_rawgeti(l, p, 2); - break; - case LuaTypes.LUA_TFUNCTION: - LuaDLL.lua_pushvalue(l, p); - break; - default: - throw new Exception("expect valid Delegate"); - } - return op; - } - - - [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))] - static public int noConstructor(IntPtr l) - { - return error(l, "Can't new this object"); - } - - [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))] - static public int typeToString(IntPtr l) - { - LuaDLL.lua_pushstring (l, "__fullname"); - LuaDLL.lua_rawget (l, -2); - return 1; - } - - static public int error(IntPtr l,Exception e) - { - LuaDLL.lua_pushboolean(l, false); - LuaDLL.lua_pushstring(l, e.ToString()); - return 2; - } - - static public int error(IntPtr l, string err) - { - LuaDLL.lua_pushboolean(l, false); - LuaDLL.lua_pushstring(l, err); - return 2; - } - - static public int error(IntPtr l, string err, params object[] args) - { - err = string.Format(err, args); - LuaDLL.lua_pushboolean(l, false); - LuaDLL.lua_pushstring(l, err); - return 2; - } - - static public int ok(IntPtr l) - { - LuaDLL.lua_pushboolean(l, true); - return 1; - } - - static public int ok(IntPtr l, int retCount) - { - LuaDLL.lua_pushboolean(l, true); - LuaDLL.lua_insert(l, -(retCount + 1)); - return retCount + 1; - } - - static public void assert(bool cond,string err) { - if(!cond) throw new Exception(err); - } - - /// - /// Change Type, alternative for Convert.ChangeType, but has exception handling - /// change fail, return origin value directly, useful for some LuaVarObject value assign - /// - /// - /// - /// - static public object changeType(object obj, Type t) - { - if (t == typeof (object)) return obj; - if (obj.GetType() == t) return obj; - - try - { - return Convert.ChangeType(obj, t); - } - catch - { - return obj; - } - } - } - -} diff --git a/KSFramework/Assets/Plugins/Slua_Managed/LuaObject.cs.meta b/KSFramework/Assets/Plugins/Slua_Managed/LuaObject.cs.meta deleted file mode 100644 index 739dcd16..00000000 --- a/KSFramework/Assets/Plugins/Slua_Managed/LuaObject.cs.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: c3e10330570bc6e499fd43003c34a514 -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: diff --git a/KSFramework/Assets/Plugins/Slua_Managed/LuaObject_basetype.cs b/KSFramework/Assets/Plugins/Slua_Managed/LuaObject_basetype.cs deleted file mode 100644 index 0dd4c142..00000000 --- a/KSFramework/Assets/Plugins/Slua_Managed/LuaObject_basetype.cs +++ /dev/null @@ -1,532 +0,0 @@ -// The MIT License (MIT) - -// Copyright 2015 Siney/Pangweiwei siney@yeah.net -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -using System.Collections; -using System.Collections.Generic; -using System; -using LuaInterface; -using System.Reflection; -using System.Runtime.InteropServices; -namespace SLua -{ - -/* https://msdn.microsoft.com/zh-cn/library/s1ax56ch.aspx - * - * null LUA_TNIL - * Value Types: - * enum - * struct: - * Numeric types: - * Integral Types: LUA_TNUMBER - * sbyte = SByte - * byte = Byte - * char = Char - * short = Int16 - * ushort = UInt16 - * int = Int32 - * uint = UInt32 - * long = Int64 - * ulong = UInt64 - * Floating-Point Types: LUA_TNUMBER - * float = Single - * double = Double - * bool = Boolean LUA_TBOOLEAN - * User defined structs LUA_TTABLE(Vector...) || non_cached@LUA_TUSERDATA - * Reference Types: - * string LUA_TSTRING - * delegate LUA_TFUNCTION - * class、System.Type LUA_TTABLE || cached@LUA_TUSERDATA - * object cached@LUA_TUSERDATA - * char[] LUA_TSTRING - * T[] LUA_TTABLE limit support - * interface, dynamic unsupport - * IntPtr LUA_TLIGHTUSERDATA - * - * - * every type should implement: - * public static bool checkType(IntPtr l, int p, out T v) - * public static void pushValue(IntPtr l, T v) - * -*/ - public partial class LuaObject - { -#region enum - static public bool checkEnum(IntPtr l, int p, out T o) where T : struct - { - int i = (int) LuaDLL.luaL_checkinteger (l, p); - o = (T)Enum.ToObject(typeof(T), i); - - return true; - } - - public static void pushEnum(IntPtr l, int e) - { - pushValue(l, e); - } -#endregion - -#region Integral Types - #region sbyte - public static bool checkType(IntPtr l, int p, out sbyte v) - { - v = (sbyte)LuaDLL.luaL_checkinteger(l, p); - return true; - } - - public static void pushValue(IntPtr l, sbyte v) - { - LuaDLL.lua_pushinteger(l, v); - } - - #endregion - - #region byte - static public bool checkType(IntPtr l, int p, out byte v) - { - v = (byte)LuaDLL.luaL_checkinteger(l, p); - return true; - } - - public static void pushValue(IntPtr l, byte i) - { - LuaDLL.lua_pushinteger(l, i); - } - - // why doesn't have a checkArray function accept lua string? - // I think you should did a Buffer class to wrap byte[] pass/accept between mono and lua vm - #endregion - - #region char - static public bool checkType(IntPtr l, int p,out char c) - { - c = (char)LuaDLL.luaL_checkinteger(l, p); - return true; - } - - public static void pushValue(IntPtr l, char v) - { - LuaDLL.lua_pushinteger(l, v); - } - - static public bool checkArray(IntPtr l, int p, out char[] pars) - { - LuaDLL.luaL_checktype(l, p, LuaTypes.LUA_TSTRING); - string s; - checkType(l, p, out s); - pars = s.ToCharArray(); - return true; - } - #endregion - - #region short - static public bool checkType(IntPtr l, int p, out short v) - { - v = (short)LuaDLL.luaL_checkinteger(l, p); - return true; - } - - public static void pushValue(IntPtr l, short i) - { - LuaDLL.lua_pushinteger(l, i); - } - #endregion - - #region ushort - static public bool checkType(IntPtr l, int p, out ushort v) - { - v = (ushort)LuaDLL.luaL_checkinteger(l, p); - return true; - } - - public static void pushValue(IntPtr l, ushort v) - { - LuaDLL.lua_pushinteger(l, v); - } - - #endregion - - #region int - static public bool checkType(IntPtr l, int p, out int v) - { - v = (int)LuaDLL.luaL_checkinteger(l, p); - return true; - } - - public static void pushValue(IntPtr l, int i) - { - LuaDLL.lua_pushinteger(l, i); - } - - #endregion - - #region uint - static public bool checkType(IntPtr l, int p, out uint v) - { - v = (uint)LuaDLL.luaL_checkinteger(l, p); - return true; - } - - public static void pushValue(IntPtr l, uint o) - { - LuaDLL.lua_pushnumber(l, o); - } - #endregion - - #region long - static public bool checkType(IntPtr l, int p, out long v) - { -#if LUA_5_3 - v = (long)LuaDLL.luaL_checkinteger(l, p); -#else - v = (long)LuaDLL.luaL_checknumber(l, p); -#endif - return true; - } - - public static void pushValue(IntPtr l, long i) - { -#if LUA_5_3 - LuaDLL.lua_pushinteger(l,i); -#else - LuaDLL.lua_pushnumber(l, i); -#endif - } - - #endregion - - #region ulong - static public bool checkType(IntPtr l, int p, out ulong v) - { -#if LUA_5_3 - v = (ulong)LuaDLL.luaL_checkinteger(l, p); -#else - v = (ulong)LuaDLL.luaL_checknumber(l, p); -#endif - return true; - } - - public static void pushValue(IntPtr l, ulong o) - { - #if LUA_5_3 - LuaDLL.lua_pushinteger(l, (long)o); - #else - LuaDLL.lua_pushnumber(l, o); - #endif - } - #endregion - - -#endregion - -#region Floating-Point Types - #region float - public static bool checkType(IntPtr l, int p, out float v) - { - v = (float)LuaDLL.luaL_checknumber(l, p); - return true; - } - - public static void pushValue(IntPtr l, float o) - { - LuaDLL.lua_pushnumber(l, o); - } - - #endregion - - #region double - static public bool checkType(IntPtr l, int p, out double v) - { - v = LuaDLL.luaL_checknumber(l, p); - return true; - } - - public static void pushValue(IntPtr l, double d) - { - LuaDLL.lua_pushnumber(l, d); - } - - #endregion -#endregion - - #region bool - static public bool checkType(IntPtr l, int p, out bool v) - { - LuaDLL.luaL_checktype(l, p, LuaTypes.LUA_TBOOLEAN); - v = LuaDLL.lua_toboolean(l, p); - return true; - } - - public static void pushValue(IntPtr l, bool b) - { - LuaDLL.lua_pushboolean(l, b); - } - - #endregion - - #region string - static public bool checkType(IntPtr l, int p, out string v) - { - if(LuaDLL.lua_isuserdata(l,p)>0) - { - object o = checkObj(l, p); - if (o is string) - { - v = o as string; - return true; - } - } - else if (LuaDLL.lua_isstring(l, p)) - { - v = LuaDLL.lua_tostring(l, p); - return true; - } - - v = null; - return false; - } - - static public bool checkBinaryString(IntPtr l,int p,out byte[] bytes){ - if(LuaDLL.lua_isstring(l,p)){ - bytes = LuaDLL.lua_tobytes(l, p); - return true; - } - bytes = null; - return false; - } - - public static void pushValue(IntPtr l, string s) - { - LuaDLL.lua_pushstring(l, s); - } - - - #endregion - - #region IntPtr - static public bool checkType(IntPtr l, int p, out IntPtr v) - { - v = LuaDLL.lua_touserdata(l, p); - return true; - } - #endregion - - #region LuaType - static public bool checkType(IntPtr l, int p, out LuaDelegate f) - { - LuaState state = LuaState.get(l); - - p = LuaDLL.lua_absindex(l, p); - LuaDLL.luaL_checktype(l, p, LuaTypes.LUA_TFUNCTION); - - LuaDLL.lua_getglobal(l, DelgateTable); - LuaDLL.lua_pushvalue(l, p); - LuaDLL.lua_gettable(l, -2); // find function in __LuaDelegate table - if (LuaDLL.lua_isnil(l, -1)) - { // not found - LuaDLL.lua_pop(l, 1); // pop nil - f = newDelegate(l, p); - } - else - { - int fref = LuaDLL.lua_tointeger(l, -1); - LuaDLL.lua_pop(l, 1); // pop ref value; - f = state.delgateMap[fref]; - if (f == null) - { - f = newDelegate(l, p); - } - } - LuaDLL.lua_pop(l, 1); // pop DelgateTable - return true; - } - - static public bool checkType(IntPtr l, int p, out LuaThread lt) - { - if (LuaDLL.lua_isnil(l, p)) - { - lt = null; - return true; - } - LuaDLL.luaL_checktype(l, p, LuaTypes.LUA_TTHREAD); - LuaDLL.lua_pushvalue(l, p); - int fref = LuaDLL.luaL_ref(l, LuaIndexes.LUA_REGISTRYINDEX); - lt = new LuaThread(l, fref); - return true; - } - - static public bool checkType(IntPtr l, int p, out LuaFunction f) - { - if (LuaDLL.lua_isnil(l, p)) - { - f = null; - return true; - } - LuaDLL.luaL_checktype(l, p, LuaTypes.LUA_TFUNCTION); - LuaDLL.lua_pushvalue(l, p); - int fref = LuaDLL.luaL_ref(l, LuaIndexes.LUA_REGISTRYINDEX); - f = new LuaFunction(l, fref); - return true; - } - - static public bool checkType(IntPtr l, int p, out LuaTable t) - { - if (LuaDLL.lua_isnil(l, p)) - { - t = null; - return true; - } - LuaDLL.luaL_checktype(l, p, LuaTypes.LUA_TTABLE); - LuaDLL.lua_pushvalue(l, p); - int fref = LuaDLL.luaL_ref(l, LuaIndexes.LUA_REGISTRYINDEX); - t = new LuaTable(l, fref); - return true; - } - - public static void pushValue(IntPtr l, LuaCSFunction f) - { - LuaState.pushcsfunction (l, f); - } - - public static void pushValue(IntPtr l, LuaTable t) - { - if (t == null) - LuaDLL.lua_pushnil(l); - else - t.push(l); - } - #endregion - - #region Type - private static Type MonoType = typeof(Type).GetType(); - - public static Type FindType(string qualifiedTypeName) - { - Type t = Type.GetType(qualifiedTypeName); - - if (t != null) - { - return t; - } - else - { - Assembly[] Assemblies = AppDomain.CurrentDomain.GetAssemblies(); - for (int n = 0; n < Assemblies.Length;n++ ) - { - Assembly asm = Assemblies[n]; - t = asm.GetType(qualifiedTypeName); - if (t != null) - return t; - } - return null; - } - } - - - static public bool checkType(IntPtr l, int p, out Type t) - { - string tname = null; - LuaTypes lt = LuaDLL.lua_type(l, p); - switch (lt) - { - case LuaTypes.LUA_TUSERDATA: - object o = checkObj(l, p); - if (o.GetType() != MonoType) - throw new Exception(string.Format("{0} expect Type, got {1}", p, o.GetType().Name)); - t = (Type)o; - return true; - case LuaTypes.LUA_TTABLE: - LuaDLL.lua_pushstring(l, "__type"); - LuaDLL.lua_rawget(l, p); - if (!LuaDLL.lua_isnil(l, -1)) - { - t = (Type)checkObj(l, -1); - LuaDLL.lua_pop(l, 1); - return true; - } - else - { - LuaDLL.lua_pushstring(l, "__fullname"); - LuaDLL.lua_rawget(l, p); - tname = LuaDLL.lua_tostring(l, -1); - LuaDLL.lua_pop(l, 2); - } - break; - - case LuaTypes.LUA_TSTRING: - checkType(l, p, out tname); - break; - } - - if (tname == null) - throw new Exception("expect string or type table"); - - t = LuaObject.FindType(tname); - if (t != null && lt==LuaTypes.LUA_TTABLE) - { - LuaDLL.lua_pushstring(l, "__type"); - pushLightObject(l, t); - LuaDLL.lua_rawset(l, p); - } - return t != null; - } - #endregion - - #region struct - static public bool checkValueType(IntPtr l, int p, out T v) where T:struct - { - v = (T) checkObj(l, p); - return true; - } - #endregion - - static public bool checkNullable(IntPtr l, int p, out Nullable v) where T : struct - { - if (LuaDLL.lua_isnil(l, p)) - v = null; - else - { - object o=checkVar(l, p, typeof(T)); - if (o == null) v = null; - else v = new Nullable((T)o); - } - return true; - } - - #region object - static public bool checkType(IntPtr l, int p, out T o) where T:class - { - object obj = checkVar(l, p); - if (obj == null) - { - o = null; - return true; - } - - o = obj as T; - if (o == null) - throw new Exception(string.Format("arg {0} is not type of {1}", p, typeof(T).Name)); - - return true; - } - #endregion - } -} diff --git a/KSFramework/Assets/Plugins/Slua_Managed/LuaObject_basetype.cs.meta b/KSFramework/Assets/Plugins/Slua_Managed/LuaObject_basetype.cs.meta deleted file mode 100644 index ed200eb9..00000000 --- a/KSFramework/Assets/Plugins/Slua_Managed/LuaObject_basetype.cs.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: a0acddae4da724dcab4ad4ee0c0a97ca -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: diff --git a/KSFramework/Assets/Plugins/Slua_Managed/LuaObject_overload.cs b/KSFramework/Assets/Plugins/Slua_Managed/LuaObject_overload.cs deleted file mode 100644 index fadf840d..00000000 --- a/KSFramework/Assets/Plugins/Slua_Managed/LuaObject_overload.cs +++ /dev/null @@ -1,168 +0,0 @@ -// The MIT License (MIT) - -// Copyright 2015 Siney/Pangweiwei siney@yeah.net -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - - -#if !SLUA_STANDALONE -namespace SLua -{ - using UnityEngine; - using System.Collections; - using System.Collections.Generic; - using System; - using LuaInterface; - using System.Reflection; - using System.Runtime.InteropServices; - - public partial class LuaObject - { - - static public bool checkType(IntPtr l, int p, out Vector4 v) - { - float x, y, z, w; - if(LuaDLL.luaS_checkVector4(l, p, out x, out y, out z, out w)!=0) - throw new Exception(string.Format("Invalid vector4 argument at {0}", p)); - v = new Vector4(x, y, z, w); - return true; - } - - - static public bool checkType(IntPtr l, int p, out Vector3 v) - { - float x, y, z; - if(LuaDLL.luaS_checkVector3(l, p, out x, out y, out z)!=0) - throw new Exception(string.Format("Invalid vector3 argument at {0}", p)); - v = new Vector3(x, y, z); - return true; - } - - static public bool checkType(IntPtr l, int p, out Vector2 v) - { - float x, y; - if(LuaDLL.luaS_checkVector2(l, p, out x, out y)!=0) - throw new Exception(string.Format("Invalid vector2 argument at {0}", p)); - v = new Vector2(x, y); - return true; - } - - static public bool checkType(IntPtr l, int p, out Quaternion q) - { - float x, y, z, w; - if(LuaDLL.luaS_checkQuaternion(l, p, out x, out y, out z, out w)!=0) - throw new Exception(string.Format("Invalid quaternion argument at {0}", p)); - q = new Quaternion(x, y, z, w); - return true; - } - - static public bool checkType(IntPtr l, int p, out Color c) - { - float x, y, z, w; - if (LuaDLL.luaS_checkColor(l, p, out x, out y, out z, out w) != 0) - throw new Exception(string.Format("Invalid color argument at {0}", p)); - c = new Color(x, y, z, w); - return true; - } - - static public bool checkType(IntPtr l, int p, out LayerMask lm) - { - int v; - checkType(l, p, out v); - lm = v; - return true; - } - - static public bool checkParams(IntPtr l, int p, out Vector2[] pars) - { - int top = LuaDLL.lua_gettop(l); - if (top - p >= 0) - { - pars = new Vector2[top - p + 1]; - for (int n = p, k = 0; n <= top; n++, k++) - { - checkType(l, n, out pars[k]); - } - return true; - } - pars = new Vector2[0]; - return true; - } - - public static void pushValue(IntPtr l, RaycastHit2D r) - { - pushObject(l, r); - } - - public static void pushValue(IntPtr l, RaycastHit r) - { - pushObject(l, r); - } - - public static void pushValue(IntPtr l, UnityEngine.AnimationState o) - { - if (o == null) - LuaDLL.lua_pushnil(l); - else - pushObject(l, o); - } - - public static void pushValue(IntPtr l, UnityEngine.Object o) - { - if (o == null) - LuaDLL.lua_pushnil(l); - else - pushObject(l, o); - } - - public static void pushValue(IntPtr l, Quaternion o) - { - LuaDLL.luaS_pushQuaternion(l, o.x, o.y, o.z, o.w); - } - - public static void pushValue(IntPtr l, Vector2 o) - { - LuaDLL.luaS_pushVector2(l, o.x, o.y); - } - - - - public static void pushValue(IntPtr l, Vector3 o) - { - LuaDLL.luaS_pushVector3(l, o.x, o.y, o.z); - } - - - - public static void pushValue(IntPtr l, Vector4 o) - { - LuaDLL.luaS_pushVector4(l, o.x, o.y, o.z, o.w); - } - - public static void pushValue(IntPtr l, Color o) - { - LuaDLL.luaS_pushColor(l, o.r, o.g, o.b, o.a); - } - - public static void pushValue(IntPtr l, Color32 c32) { - pushObject(l, c32); - } - } -} -#endif \ No newline at end of file diff --git a/KSFramework/Assets/Plugins/Slua_Managed/LuaObject_overload.cs.meta b/KSFramework/Assets/Plugins/Slua_Managed/LuaObject_overload.cs.meta deleted file mode 100644 index 9bcc569a..00000000 --- a/KSFramework/Assets/Plugins/Slua_Managed/LuaObject_overload.cs.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 67c9d7596571b7d46b0cae425f7f0a29 -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: diff --git a/KSFramework/Assets/Plugins/Slua_Managed/LuaState.cs b/KSFramework/Assets/Plugins/Slua_Managed/LuaState.cs deleted file mode 100644 index 47923488..00000000 --- a/KSFramework/Assets/Plugins/Slua_Managed/LuaState.cs +++ /dev/null @@ -1,1178 +0,0 @@ -// The MIT License (MIT) - -// Copyright 2015 Siney/Pangweiwei siney@yeah.net -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - - - -namespace SLua -{ - using System; - using System.Collections.Generic; - using System.Collections; - using LuaInterface; - using System.IO; - using System.Text; - using System.Runtime.InteropServices; -#if !SLUA_STANDALONE - using UnityEngine; -#endif - abstract public class LuaVar : IDisposable - { - protected LuaState state = null; - protected int valueref = 0; - - - - public IntPtr L - { - get - { - return state.L; - } - } - - public int Ref - { - get - { - return valueref; - } - } - - public LuaVar() - { - state = null; - } - - public LuaVar(LuaState l, int r) - { - state = l; - valueref = r; - } - - public LuaVar(IntPtr l, int r) - { - state = LuaState.get(l); - valueref = r; - } - - ~LuaVar() - { - Dispose(false); - } - - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } - - public virtual void Dispose(bool disposeManagedResources) - { - if (valueref != 0) - { - LuaState.UnRefAction act = (IntPtr l, int r) => - { - LuaDLL.lua_unref(l, r); - }; - state.gcRef(act, valueref); - valueref = 0; - } - } - - public void push(IntPtr l) - { - LuaDLL.lua_getref(l, valueref); - } - - public override int GetHashCode() - { - return base.GetHashCode(); - } - - public override bool Equals(object obj) - { - if (obj is LuaVar) - { - return this == (LuaVar)obj; - } - return false; - } - - public static bool operator ==(LuaVar x, LuaVar y) - { - if ((object)x == null || (object)y == null) - return (object)x == (object)y; - - return Equals(x, y) == 1; - } - - public static bool operator !=(LuaVar x, LuaVar y) - { - if ((object)x == null || (object)y == null) - return (object)x != (object)y; - - return Equals(x, y) != 1; - } - - static int Equals(LuaVar x, LuaVar y) - { - x.push(x.L); - y.push(x.L); - int ok = LuaDLL.lua_equal(x.L, -1, -2); - LuaDLL.lua_pop(x.L, 2); - return ok; - } - } - - public class LuaThread : LuaVar - { - public LuaThread(IntPtr l, int r) - : base(l, r) - { } - } - - public class LuaDelegate : LuaFunction - { - public object d; - - public LuaDelegate(IntPtr l, int r) - : base(l, r) - { - } - - public override void Dispose(bool disposeManagedResources) - { - if (valueref != 0) - { - LuaState.UnRefAction act = (IntPtr l, int r) => - { - LuaObject.removeDelgate(l, r); - LuaDLL.lua_unref(l, r); - }; - state.gcRef(act, valueref); - valueref = 0; - } - - } - - } - - public class LuaFunction : LuaVar - { - public LuaFunction(LuaState l, int r) - : base(l, r) - { - } - - public LuaFunction(IntPtr l, int r) - : base(l, r) - { - } - - public bool pcall(int nArgs, int errfunc) - { - - if (!state.isMainThread()) - { - Logger.LogError("Can't call lua function in bg thread"); - return false; - } - - LuaDLL.lua_getref(L, valueref); - - if (!LuaDLL.lua_isfunction(L, -1)) - { - LuaDLL.lua_pop(L, 1); - throw new Exception("Call invalid function."); - } - - LuaDLL.lua_insert(L, -nArgs - 1); - if (LuaDLL.lua_pcall(L, nArgs, -1, errfunc) != 0) - { - LuaDLL.lua_pop(L, 1); - return false; - } - return true; - } - - bool innerCall(int nArgs, int errfunc) - { - bool ret = pcall(nArgs, errfunc); - LuaDLL.lua_remove(L, errfunc); - return ret; - } - - - public object call() - { - int error = LuaObject.pushTry(state.L); - if (innerCall(0, error)) - { - return state.topObjects(error - 1); - } - return null; - } - - public object call(params object[] args) - { - int error = LuaObject.pushTry(state.L); - - for (int n = 0; args != null && n < args.Length; n++) - { - LuaObject.pushVar(L, args[n]); - } - - if (innerCall(args != null ? args.Length : 0, error)) - { - return state.topObjects(error - 1); - } - - return null; - } - - public object call(object a1) - { - int error = LuaObject.pushTry(state.L); - - LuaObject.pushVar(state.L, a1); - if (innerCall(1, error)) - { - return state.topObjects(error - 1); - } - - - return null; - } - - public object call(object a1, object a2) - { - int error = LuaObject.pushTry(state.L); - - LuaObject.pushVar(state.L, a1); - LuaObject.pushVar(state.L, a2); - if (innerCall(2, error)) - { - return state.topObjects(error - 1); - } - return null; - } - - public object call(object a1, object a2, object a3) - { - int error = LuaObject.pushTry(state.L); - - LuaObject.pushVar(state.L, a1); - LuaObject.pushVar(state.L, a2); - LuaObject.pushVar(state.L, a3); - if (innerCall(3, error)) - { - return state.topObjects(error - 1); - } - return null; - } - - // you can add call method with specific type rather than object type to avoid gc alloc, like - // public object call(int a1,float a2,string a3,object a4) - - // using specific type to avoid type boxing/unboxing - } - - public class LuaTable : LuaVar, IEnumerable - { - - - public struct TablePair - { - public object key; - public object value; - } - public LuaTable(IntPtr l, int r) - : base(l, r) - { - } - - public LuaTable(LuaState l, int r) - : base(l, r) - { - } - - public LuaTable(LuaState state) - : base(state, 0) - { - - LuaDLL.lua_newtable(L); - valueref = LuaDLL.luaL_ref(L, LuaIndexes.LUA_REGISTRYINDEX); - } - public object this[string key] - { - get - { - return state.getObject(valueref, key); - } - - set - { - state.setObject(valueref, key, value); - } - } - - public object this[int index] - { - get - { - return state.getObject(valueref, index); - } - - set - { - state.setObject(valueref, index, value); - } - } - - public object invoke(string func, params object[] args) - { - LuaFunction f = (LuaFunction)this[func]; - if (f != null) - { - return f.call(args); - } - throw new Exception(string.Format("Can't find {0} function", func)); - } - - public int length() - { - int n = LuaDLL.lua_gettop(L); - push(L); - int l = LuaDLL.lua_rawlen(L, -1); - LuaDLL.lua_settop(L, n); - return l; - } - - public class Enumerator : IEnumerator, IDisposable - { - LuaTable t; - int indext = -1; - TablePair current = new TablePair(); - int iterPhase = 0; - - public Enumerator(LuaTable table) - { - t = table; - Reset(); - } - - public bool MoveNext() - { - if (indext < 0) - return false; - - if (iterPhase == 0) - { - LuaDLL.lua_pushnil(t.L); - iterPhase = 1; - } - else - LuaDLL.lua_pop(t.L, 1); - - bool ret = LuaDLL.lua_next(t.L, indext) > 0; - if (!ret) iterPhase = 2; - - return ret; - } - - public void Reset() - { - LuaDLL.lua_getref(t.L, t.Ref); - indext = LuaDLL.lua_gettop(t.L); - } - - public void Dispose() - { - if (iterPhase == 1) - LuaDLL.lua_pop(t.L, 2); - - LuaDLL.lua_remove(t.L, indext); - } - - public TablePair Current - { - get - { - current.key = LuaObject.checkVar(t.L, -2); - current.value = LuaObject.checkVar(t.L, -1); - return current; - } - } - - object IEnumerator.Current - { - get - { - return Current; - } - } - } - - public IEnumerator GetEnumerator() - { - return new LuaTable.Enumerator(this); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - - } - - - - - - public class LuaState : IDisposable - { - IntPtr l_; - int mainThread = 0; - internal WeakDictionary delgateMap = new WeakDictionary(); - - public IntPtr L - { - get - { - - if (!isMainThread()) - { - Logger.LogError("Can't access lua in bg thread"); - throw new Exception("Can't access lua in bg thread"); - } - - if (l_ == IntPtr.Zero) - { - Logger.LogError("LuaState had been destroyed, can't used yet"); - throw new Exception("LuaState had been destroyed, can't used yet"); - } - - return l_; - } - set - { - l_ = value; - } - } - - public IntPtr handle - { - get - { - return L; - } - } - - public delegate byte[] LoaderDelegate(string fn); - public delegate void OutputDelegate(string msg); - - static public LoaderDelegate loaderDelegate; - static public OutputDelegate logDelegate; - static public OutputDelegate errorDelegate; - - - public delegate void UnRefAction(IntPtr l, int r); - struct UnrefPair - { - public UnRefAction act; - public int r; - } - Queue refQueue; - public int PCallCSFunctionRef = 0; - - - public static LuaState main; - static Dictionary statemap = new Dictionary(); - static IntPtr oldptr = IntPtr.Zero; - static LuaState oldstate = null; - static public LuaCSFunction errorFunc = new LuaCSFunction(errorReport); - - public bool isMainThread() - { - return System.Threading.Thread.CurrentThread.ManagedThreadId == mainThread; - } - - static public LuaState get(IntPtr l) - { - if (l == oldptr) - return oldstate; - - LuaState ls; - if (statemap.TryGetValue(l, out ls)) - { - oldptr = l; - oldstate = ls; - return ls; - } - - LuaDLL.lua_getglobal(l, "__main_state"); - if (LuaDLL.lua_isnil(l, -1)) - { - LuaDLL.lua_pop(l, 1); - return null; - } - - IntPtr nl = LuaDLL.lua_touserdata(l, -1); - LuaDLL.lua_pop(l, 1); - if (nl != l) - return get(nl); - return null; - } - - public LuaState() - { - mainThread = System.Threading.Thread.CurrentThread.ManagedThreadId; - - L = LuaDLL.luaL_newstate(); - statemap[L] = this; - if (main == null) main = this; - - refQueue = new Queue(); - ObjectCache.make(L); - - LuaDLL.lua_atpanic(L, panicCallback); - - LuaDLL.luaL_openlibs(L); - - string PCallCSFunction = @" -local assert = assert -local function check(ok,...) - assert(ok, ...) - return ... -end -return function(cs_func) - return function(...) - return check(cs_func(...)) - end -end -"; - - LuaDLL.lua_dostring(L, PCallCSFunction); - PCallCSFunctionRef = LuaDLL.luaL_ref(L, LuaIndexes.LUA_REGISTRYINDEX); - - pcall(L, init); - } - - [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))] - static int init(IntPtr L) - { - LuaDLL.lua_pushlightuserdata(L, L); - LuaDLL.lua_setglobal(L, "__main_state"); - - LuaDLL.lua_pushcfunction(L, print); - LuaDLL.lua_setglobal(L, "print"); - - LuaDLL.lua_pushcfunction(L, pcall); - LuaDLL.lua_setglobal(L, "pcall"); - - pushcsfunction(L, import); - LuaDLL.lua_setglobal(L, "import"); - - - string resumefunc = @" -local resume = coroutine.resume -local function check(co, ok, err, ...) - if not ok then UnityEngine.Debug.LogError(debug.traceback(co,err)) end - return ok, err, ... -end -coroutine.resume=function(co,...) - return check(co, resume(co,...)) -end -"; - - // overload resume function for report error - LuaState.get(L).doString(resumefunc); - -#if UNITY_ANDROID - // fix android performance drop with JIT on according to luajit mailist post - LuaState.get(L).doString("if jit then require('jit.opt').start('sizemcode=256','maxmcode=256') for i=1,1000 do end end"); -#endif - - pushcsfunction(L, dofile); - LuaDLL.lua_setglobal(L, "dofile"); - - pushcsfunction(L, loadfile); - LuaDLL.lua_setglobal(L, "loadfile"); - - pushcsfunction(L, loader); - int loaderFunc = LuaDLL.lua_gettop(L); - - LuaDLL.lua_getglobal(L, "package"); -#if LUA_5_3 - LuaDLL.lua_getfield(L, -1, "searchers"); -#else - LuaDLL.lua_getfield(L, -1, "loaders"); -#endif - int loaderTable = LuaDLL.lua_gettop(L); - - // Shift table elements right - for (int e = LuaDLL.lua_rawlen(L, loaderTable) + 1; e > 2; e--) - { - LuaDLL.lua_rawgeti(L, loaderTable, e - 1); - LuaDLL.lua_rawseti(L, loaderTable, e); - } - LuaDLL.lua_pushvalue(L, loaderFunc); - LuaDLL.lua_rawseti(L, loaderTable, 2); - LuaDLL.lua_settop(L, 0); - return 0; - } - - public void Close() - { - if (L != IntPtr.Zero) - { - if (LuaState.main == this) - { - Logger.Log("Finalizing Lua State."); - // be careful, if you close lua vm, make sure you don't use lua state again, - // comment this line as default for avoid unexpected crash. - LuaDLL.lua_close(L); - - ObjectCache.del(L); - ObjectCache.clear(); - - statemap.Clear(); - oldptr = IntPtr.Zero; - oldstate = null; - L = IntPtr.Zero; - - LuaState.main = null; - } - } - } - - public void Dispose() - { - Dispose(true); - System.GC.Collect(); - System.GC.WaitForPendingFinalizers(); - } - - public virtual void Dispose(bool dispose) - { - if (dispose) - { - Close(); - } - } - - [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))] - public static int errorReport(IntPtr L) - { - LuaDLL.lua_getglobal(L, "debug"); - LuaDLL.lua_getfield(L, -1, "traceback"); - LuaDLL.lua_pushvalue(L, 1); - LuaDLL.lua_pushnumber(L, 2); - LuaDLL.lua_call(L, 2, 1); - LuaDLL.lua_remove(L, -2); - Logger.LogError(LuaDLL.lua_tostring(L, -1)); - if (errorDelegate != null) - { - errorDelegate(LuaDLL.lua_tostring(L, -1)); - } - LuaDLL.lua_pop(L, 1); - return 0; - } - - [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))] - internal static int import(IntPtr l) - { - try - { - LuaDLL.luaL_checktype(l, 1, LuaTypes.LUA_TSTRING); - string str = LuaDLL.lua_tostring(l, 1); - - string[] ns = str.Split('.'); - - LuaDLL.lua_pushglobaltable(l); - - for (int n = 0; n < ns.Length; n++) - { - LuaDLL.lua_getfield(l, -1, ns[n]); - if (!LuaDLL.lua_istable(l, -1)) - { - return LuaObject.error(l, "expect {0} is type table", ns); - } - LuaDLL.lua_remove(l, -2); - } - - LuaDLL.lua_pushnil(l); - while (LuaDLL.lua_next(l, -2) != 0) - { - string key = LuaDLL.lua_tostring(l, -2); - LuaDLL.lua_getglobal(l, key); - if (!LuaDLL.lua_isnil(l, -1)) - { - LuaDLL.lua_pop(l, 1); - return LuaObject.error(l, "{0} had existed, import can't overload it.", key); - } - LuaDLL.lua_pop(l, 1); - LuaDLL.lua_setglobal(l, key); - } - - LuaDLL.lua_pop(l, 1); - - LuaObject.pushValue(l, true); - return 1; - } - catch (Exception e) - { - return LuaObject.error(l, e); - } - } - - [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))] - internal static int pcall(IntPtr L) - { - int status; - if (LuaDLL.lua_type(L, 1) != LuaTypes.LUA_TFUNCTION) - { - return LuaObject.error(L, "arg 1 expect function"); - } - LuaDLL.luaL_checktype(L, 1, LuaTypes.LUA_TFUNCTION); - status = LuaDLL.lua_pcall(L, LuaDLL.lua_gettop(L) - 1, LuaDLL.LUA_MULTRET, 0); - LuaDLL.lua_pushboolean(L, (status == 0)); - LuaDLL.lua_insert(L, 1); - return LuaDLL.lua_gettop(L); /* return status + all results */ - } - - internal static void pcall(IntPtr l, LuaCSFunction f) - { - int err = LuaObject.pushTry(l); - LuaDLL.lua_pushcfunction(l, f); - if (LuaDLL.lua_pcall(l, 0, 0, err) != 0) - { - LuaDLL.lua_pop(l, 1); - } - LuaDLL.lua_remove(l, err); - } - - [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))] - internal static int print(IntPtr L) - { - int n = LuaDLL.lua_gettop(L); - string s = ""; - - LuaDLL.lua_getglobal(L, "tostring"); - - for (int i = 1; i <= n; i++) - { - if (i > 1) - { - s += " "; - } - - LuaDLL.lua_pushvalue(L, -1); - LuaDLL.lua_pushvalue(L, i); - - LuaDLL.lua_call(L, 1, 1); - s += LuaDLL.lua_tostring(L, -1); - LuaDLL.lua_pop(L, 1); - } - LuaDLL.lua_settop(L, n); - Logger.Log(s); - if (logDelegate != null) - { - logDelegate(s); - } - return 0; - } - - [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))] - internal static int loadfile(IntPtr L) - { - loader(L); - - if (LuaDLL.lua_isnil(L, -1)) - { - string fileName = LuaDLL.lua_tostring(L, 1); - return LuaObject.error(L, "Can't find {0}", fileName); - } - return 2; - } - - [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))] - internal static int dofile(IntPtr L) - { - int n = LuaDLL.lua_gettop(L); - - loader(L); - if (!LuaDLL.lua_toboolean(L, -2)) - { - return 2; - } - else - { - if (LuaDLL.lua_isnil(L, -1)) - { - string fileName = LuaDLL.lua_tostring(L, 1); - return LuaObject.error(L, "Can't find {0}", fileName); - } - int k = LuaDLL.lua_gettop(L); - LuaDLL.lua_call(L, 0, LuaDLL.LUA_MULTRET); - k = LuaDLL.lua_gettop(L); - return k - n; - } - } - - [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))] - static public int panicCallback(IntPtr l) - { - string reason = string.Format("unprotected error in call to Lua API ({0})", LuaDLL.lua_tostring(l, -1)); - throw new Exception(reason); - } - - static public void pushcsfunction(IntPtr L, LuaCSFunction function) - { - LuaDLL.lua_getref(L, get(L).PCallCSFunctionRef); - LuaDLL.lua_pushcclosure(L, function, 0); - LuaDLL.lua_call(L, 1, 1); - } - - public object doString(string str) - { - byte[] bytes = Encoding.UTF8.GetBytes(str); - - object obj; - if (doBuffer(bytes, "temp buffer", out obj)) - return obj; - return null; ; - } - - public object doString(string str, string chunkname) - { - byte[] bytes = Encoding.UTF8.GetBytes(str); - - object obj; - if (doBuffer(bytes, chunkname, out obj)) - return obj; - return null; ; - } - - [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))] - internal static int loader(IntPtr L) - { - string fileName = LuaDLL.lua_tostring(L, 1); - byte[] bytes = loadFile(fileName); - if (bytes != null) - { - if (LuaDLL.luaL_loadbuffer(L, bytes, bytes.Length, "@" + fileName) == 0) - { - LuaObject.pushValue(L, true); - LuaDLL.lua_insert(L, -2); - return 2; - } - else - { - string errstr = LuaDLL.lua_tostring(L, -1); - return LuaObject.error(L, errstr); - } - } - LuaObject.pushValue(L, true); - LuaDLL.lua_pushnil(L); - return 2; - } - - public object doFile(string fn) - { - byte[] bytes = loadFile(fn); - if (bytes == null) - { - Logger.LogError(string.Format("Can't find {0}", fn)); - return null; - } - - object obj; - if (doBuffer(bytes, "@" + fn, out obj)) - return obj; - return null; - } - - /// - /// Ensure remove BOM from bytes - /// - /// - /// - public static byte[] CleanUTF8Bom(byte[] bytes) - { - if (bytes.Length > 3 && bytes[0] == 0xEF && bytes[1] == 0xBB && bytes[2] == 0xBF) - { - var oldBytes = bytes; - bytes = new byte[bytes.Length - 3]; - Array.Copy(oldBytes, 3, bytes, 0, bytes.Length); - } - return bytes; - } - - public bool doBuffer(byte[] bytes, string fn, out object ret) - { - // ensure no utf-8 bom, LuaJIT can read BOM, but Lua cannot! - bytes = CleanUTF8Bom(bytes); - ret = null; - int errfunc = LuaObject.pushTry(L); - if (LuaDLL.luaL_loadbuffer(L, bytes, bytes.Length, fn) == 0) - { - if (LuaDLL.lua_pcall(L, 0, LuaDLL.LUA_MULTRET, errfunc) != 0) - { - LuaDLL.lua_pop(L, 2); - return false; - } - LuaDLL.lua_remove(L, errfunc); // pop error function - ret = topObjects(errfunc - 1); - return true; - } - string err = LuaDLL.lua_tostring(L, -1); - LuaDLL.lua_pop(L, 2); - throw new Exception(err); - } - - internal static byte[] loadFile(string fn) - { - try - { - byte[] bytes; - if (loaderDelegate != null) - bytes = loaderDelegate(fn); - else - { -#if !SLUA_STANDALONE - fn = fn.Replace(".", "/"); - TextAsset asset = (TextAsset)Resources.Load(fn); - if (asset == null) - return null; - bytes = asset.bytes; -#else - bytes = File.ReadAllBytes(fn); -#endif - } - return bytes; - } - catch (Exception e) - { - throw new Exception(e.Message); - } - } - - - internal object getObject(string key) - { - LuaDLL.lua_pushglobaltable(L); - object o = getObject(key.Split(new char[] { '.' })); - LuaDLL.lua_pop(L, 1); - return o; - } - - internal void setObject(string key, object v) - { - LuaDLL.lua_pushglobaltable(L); - setObject(key.Split(new char[] { '.' }), v); - LuaDLL.lua_pop(L, 1); - } - - internal object getObject(string[] remainingPath) - { - object returnValue = null; - for (int i = 0; i < remainingPath.Length; i++) - { - LuaDLL.lua_pushstring(L, remainingPath[i]); - LuaDLL.lua_gettable(L, -2); - returnValue = this.getObject(L, -1); - LuaDLL.lua_remove(L, -2); - if (returnValue == null) break; - } - return returnValue; - } - - - internal object getObject(int reference, string field) - { - int oldTop = LuaDLL.lua_gettop(L); - LuaDLL.lua_getref(L, reference); - object returnValue = getObject(field.Split(new char[] { '.' })); - LuaDLL.lua_settop(L, oldTop); - return returnValue; - } - - internal object getObject(int reference, int index) - { - if (index >= 1) - { - int oldTop = LuaDLL.lua_gettop(L); - LuaDLL.lua_getref(L, reference); - LuaDLL.lua_rawgeti(L, -1, index); - object returnValue = getObject(L, -1); - LuaDLL.lua_settop(L, oldTop); - return returnValue; - } - throw new IndexOutOfRangeException(); - } - - internal object getObject(int reference, object field) - { - int oldTop = LuaDLL.lua_gettop(L); - LuaDLL.lua_getref(L, reference); - LuaObject.pushObject(L, field); - LuaDLL.lua_gettable(L, -2); - object returnValue = getObject(L, -1); - LuaDLL.lua_settop(L, oldTop); - return returnValue; - } - - internal void setObject(string[] remainingPath, object o) - { - int top = LuaDLL.lua_gettop(L); - for (int i = 0; i < remainingPath.Length - 1; i++) - { - LuaDLL.lua_pushstring(L, remainingPath[i]); - LuaDLL.lua_gettable(L, -2); - } - LuaDLL.lua_pushstring(L, remainingPath[remainingPath.Length - 1]); - LuaObject.pushVar(L, o); - LuaDLL.lua_settable(L, -3); - LuaDLL.lua_settop(L, top); - } - - - internal void setObject(int reference, string field, object o) - { - int oldTop = LuaDLL.lua_gettop(L); - LuaDLL.lua_getref(L, reference); - setObject(field.Split(new char[] { '.' }), o); - LuaDLL.lua_settop(L, oldTop); - } - - internal void setObject(int reference, int index, object o) - { - if (index >= 1) - { - int oldTop = LuaDLL.lua_gettop(L); - LuaDLL.lua_getref(L, reference); - LuaObject.pushVar(L, o); - LuaDLL.lua_rawseti(L, -2, index); - LuaDLL.lua_settop(L, oldTop); - return; - } - throw new IndexOutOfRangeException(); - } - - internal void setObject(int reference, object field, object o) - { - int oldTop = LuaDLL.lua_gettop(L); - LuaDLL.lua_getref(L, reference); - LuaObject.pushObject(L, field); - LuaObject.pushObject(L, o); - LuaDLL.lua_settable(L, -3); - LuaDLL.lua_settop(L, oldTop); - } - - internal object topObjects(int from) - { - int top = LuaDLL.lua_gettop(L); - int nArgs = top - from; - if (nArgs == 0) - return null; - else if (nArgs == 1) - { - object o = LuaObject.checkVar(L, top); - LuaDLL.lua_pop(L, 1); - return o; - } - else - { - object[] o = new object[nArgs]; - for (int n = 1; n <= nArgs; n++) - { - o[n - 1] = LuaObject.checkVar(L, from + n); - - } - LuaDLL.lua_settop(L, from); - return o; - } - } - - object getObject(IntPtr l, int p) - { - p = LuaDLL.lua_absindex(l, p); - return LuaObject.checkVar(l, p); - } - - public LuaFunction getFunction(string key) - { - return (LuaFunction)this[key]; - } - - public LuaTable getTable(string key) - { - return (LuaTable)this[key]; - } - - - public object this[string path] - { - get - { - return this.getObject(path); - } - set - { - this.setObject(path, value); - } - } - - public void gcRef(UnRefAction act, int r) - { - UnrefPair u = new UnrefPair(); - u.act = act; - u.r = r; - lock (refQueue) - { - refQueue.Enqueue(u); - } - } - - public void checkRef() - { - int cnt = 0; - // fix il2cpp lock issue on iOS - lock (refQueue) - { - cnt = refQueue.Count; - } - - var l = L; - for (int n = 0; n < cnt; n++) - { - UnrefPair u; - lock (refQueue) - { - u = refQueue.Dequeue(); - } - u.act(l, u.r); - } - } - } -} diff --git a/KSFramework/Assets/Plugins/Slua_Managed/LuaState.cs.meta b/KSFramework/Assets/Plugins/Slua_Managed/LuaState.cs.meta deleted file mode 100644 index 5cf41212..00000000 --- a/KSFramework/Assets/Plugins/Slua_Managed/LuaState.cs.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 62daeee0fd05f124fa9dd011d4c45985 -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: diff --git a/KSFramework/Assets/Plugins/Slua_Managed/LuaSvr.cs b/KSFramework/Assets/Plugins/Slua_Managed/LuaSvr.cs deleted file mode 100644 index 9e4c3467..00000000 --- a/KSFramework/Assets/Plugins/Slua_Managed/LuaSvr.cs +++ /dev/null @@ -1,291 +0,0 @@ -// The MIT License (MIT) - -// Copyright 2015 Siney/Pangweiwei siney@yeah.net -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -// uncomment this will use static binder(class BindCustom/BindUnity), -// init will not use reflection to speed up the speed -//#define USE_STATIC_BINDER - -namespace SLua -{ - using System; - using System.Threading; - using System.Collections; - using System.Collections.Generic; - using LuaInterface; - using System.Reflection; -#if !SLUA_STANDALONE - using UnityEngine; - using Debug = UnityEngine.Debug; -#endif - - public enum LuaSvrFlag { - LSF_BASIC = 0, - LSF_DEBUG = 1, - LSF_EXTLIB = 2, - LSF_3RDDLL = 4 - }; - - public class LuaSvr - { - public LuaState luaState; -#if !SLUA_STANDALONE - static LuaSvrGameObject lgo; -#endif - int errorReported = 0; - public bool inited = false; - - public LuaSvr() - { - LuaState luaState = new LuaState(); - this.luaState = luaState; - } - - private volatile int bindProgress = 0; - private void doBind(object state) - { - IntPtr L = (IntPtr)state; - - List> list = new List>(); - -#if !SLUA_STANDALONE -#if USE_STATIC_BINDER - Assembly[] ams = AppDomain.CurrentDomain.GetAssemblies(); - - bindProgress = 0; - - List bindlist = new List(); - for (int n = 0; n < ams.Length;n++ ) - { - Assembly a = ams[n]; - Type[] ts = null; - try - { - ts = a.GetExportedTypes(); - } - catch - { - continue; - } - for (int k = 0; k < ts.Length; k++) - { - Type t = ts[k]; - if (t.IsDefined(typeof(LuaBinderAttribute), false)) - { - bindlist.Add(t); - } - } - } - - bindProgress = 1; - - bindlist.Sort(new System.Comparison((Type a, Type b) => { - LuaBinderAttribute la = System.Attribute.GetCustomAttribute( a, typeof(LuaBinderAttribute) ) as LuaBinderAttribute; - LuaBinderAttribute lb = System.Attribute.GetCustomAttribute( b, typeof(LuaBinderAttribute) ) as LuaBinderAttribute; - - return la.order.CompareTo(lb.order); - })); - - for (int n = 0; n < bindlist.Count; n++) - { - Type t = bindlist[n]; - var sublist = (Action[])t.GetMethod("GetBindList").Invoke(null, null); - list.AddRange(sublist); - } -#else - var assemblyName = "Assembly-CSharp"; - Assembly assembly = Assembly.Load(assemblyName); - list.AddRange(getBindList(assembly,"SLua.BindUnity")); - list.AddRange(getBindList(assembly,"SLua.BindUnityUI")); - list.AddRange(getBindList(assembly,"SLua.BindDll")); - list.AddRange(getBindList(assembly,"SLua.BindCustom")); -#endif -#endif - - bindProgress = 2; - - int count = list.Count; - for (int n = 0; n < count; n++) - { - Action action = list[n]; - action(L); - bindProgress = (int)(((float)n / count) * 98.0) + 2; - } - - bindProgress = 100; - } - - Action[] getBindList(Assembly assembly,string ns) { - Type t=assembly.GetType(ns); - if(t!=null) - return (Action[]) t.GetMethod("GetBindList").Invoke(null, null); - return new Action[0]; - } - - - public IEnumerator waitForBind(Action tick, Action complete) - { - int lastProgress = 0; - do { - if (tick != null) - tick (bindProgress); - // too many yield return will increase binding time - // so check progress and skip odd progress - if (lastProgress != bindProgress && bindProgress % 2 == 0) - { - lastProgress = bindProgress; - yield return null; - } - } while (bindProgress != 100); - - if (tick != null) - tick (bindProgress); - - complete(); - } - - void doinit(IntPtr L,LuaSvrFlag flag) - { -#if !SLUA_STANDALONE - LuaTimer.reg(L); -#if UNITY_EDITOR - if (UnityEditor.EditorApplication.isPlaying) -#endif - LuaCoroutine.reg(L, lgo); -#endif - Helper.reg(L); - LuaValueType.reg(L); - - if((flag&LuaSvrFlag.LSF_EXTLIB)!=0) - LuaDLL.luaS_openextlibs(L); - if((flag&LuaSvrFlag.LSF_3RDDLL)!=0) - Lua3rdDLL.open(L); - -#if !SLUA_STANDALONE -#if UNITY_EDITOR - if (UnityEditor.EditorApplication.isPlaying) - { -#endif - lgo.state = luaState; - lgo.onUpdate = this.tick; - lgo.init(); -#if UNITY_EDITOR - } - -#endif -#endif - - inited = true; - } - - void checkTop(IntPtr L) - { - if (LuaDLL.lua_gettop(luaState.L) != errorReported) - { - Logger.LogError("Some function not remove temp value from lua stack. You should fix it."); - errorReported = LuaDLL.lua_gettop(luaState.L); - } - } - - public void init(Action tick,Action complete,LuaSvrFlag flag=LuaSvrFlag.LSF_BASIC) - { -#if !SLUA_STANDALONE - if (lgo == null -#if UNITY_EDITOR - && UnityEditor.EditorApplication.isPlaying -#endif - ) - { - GameObject go = new GameObject("LuaSvrProxy"); - lgo = go.AddComponent(); - GameObject.DontDestroyOnLoad(go); - - } -#endif - IntPtr L = luaState.L; - LuaObject.init(L); - -#if SLUA_STANDALONE - doBind(L); - doinit(L, flag); - complete(); - checkTop(L); -#else - - - // be caurefull here, doBind Run in another thread - // any code access unity interface will cause deadlock. - // if you want to debug bind code using unity interface, need call doBind directly, like: - // doBind(L); -#if UNITY_EDITOR - if (!UnityEditor.EditorApplication.isPlaying) - { - doBind(L); - doinit(L, flag); - complete(); - checkTop(L); - } - else - { -#endif - ThreadPool.QueueUserWorkItem(doBind, L); - lgo.StartCoroutine(waitForBind(tick, () => - { - doinit(L, flag); - complete(); - checkTop(L); - })); -#if UNITY_EDITOR - } -#endif -#endif - } - - public object start(string main) - { - if (main != null) - { - luaState.doFile(main); - LuaFunction func = (LuaFunction)luaState["main"]; - if(func!=null) - return func.call(); - } - return null; - } - -#if !SLUA_STANDALONE - void tick() - { - if (!inited) - return; - - if (LuaDLL.lua_gettop(luaState.L) != errorReported) - { - errorReported = LuaDLL.lua_gettop(luaState.L); - Logger.LogError(string.Format("Some function not remove temp value({0}) from lua stack. You should fix it.",LuaDLL.luaL_typename(luaState.L,errorReported))); - } - - luaState.checkRef(); - LuaTimer.tick(Time.deltaTime); - } -#endif - } -} diff --git a/KSFramework/Assets/Plugins/Slua_Managed/LuaSvr.cs.meta b/KSFramework/Assets/Plugins/Slua_Managed/LuaSvr.cs.meta deleted file mode 100644 index 6aa2347d..00000000 --- a/KSFramework/Assets/Plugins/Slua_Managed/LuaSvr.cs.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 5eb3a136ce8cd9242ba7b6ff1a170d24 -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: diff --git a/KSFramework/Assets/Plugins/Slua_Managed/LuaSvrGameObject.cs b/KSFramework/Assets/Plugins/Slua_Managed/LuaSvrGameObject.cs deleted file mode 100644 index 0d0c3a6a..00000000 --- a/KSFramework/Assets/Plugins/Slua_Managed/LuaSvrGameObject.cs +++ /dev/null @@ -1,65 +0,0 @@ -// The MIT License (MIT) - -// Copyright 2015 Siney/Pangweiwei siney@yeah.net -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -#if !SLUA_STANDALONE -namespace SLua -{ - using UnityEngine; - using System.Collections; - using SLua; - using System; - using System.Net; - using System.Net.Sockets; - using LuaInterface; - using System.IO; - - public class LuaSvrGameObject : MonoBehaviour - { - - public LuaState state; - public Action onUpdate; - - void OnDestroy() - { - if (state != null) - { - - // state is disposed by editorapplication if in the Editor - // state isn't disposed in App because that all resources will be disposed by app on process exit. - } - } - - public void init() { - - } - - - void Update() - { - if (onUpdate != null) onUpdate(); - - } - - - } -} -#endif \ No newline at end of file diff --git a/KSFramework/Assets/Plugins/Slua_Managed/LuaSvrGameObject.cs.meta b/KSFramework/Assets/Plugins/Slua_Managed/LuaSvrGameObject.cs.meta deleted file mode 100644 index 7c45a066..00000000 --- a/KSFramework/Assets/Plugins/Slua_Managed/LuaSvrGameObject.cs.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: bbeb72ba7c754064b8983a2ebc1dbeae -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 9999 - icon: {instanceID: 0} - userData: diff --git a/KSFramework/Assets/Plugins/Slua_Managed/LuaValueType.cs b/KSFramework/Assets/Plugins/Slua_Managed/LuaValueType.cs deleted file mode 100644 index 24d74d27..00000000 --- a/KSFramework/Assets/Plugins/Slua_Managed/LuaValueType.cs +++ /dev/null @@ -1,1091 +0,0 @@ -// The MIT License (MIT) - -// Copyright 2015 Siney/Pangweiwei siney@yeah.net -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -namespace SLua -{ - using System; - using LuaInterface; - class LuaValueType : LuaObject - { -#if !UNITY_IPHONE && !LUA_5_3 && !SLUA_STANDALONE - static string script = @" -if not UnityEngine or not UnityEngine.Vector2 then - print('No static code gen yet, ignore `LuaValueType:reg` !!! ') - return -end -local setmetatable=setmetatable -local getmetatable=getmetatable -local type=type -local clamp=clamp -local acos=math.acos -local sin=math.sin -local cos=math.cos -local sqrt=math.sqrt -local error=error -local min=math.min -local max=math.max -local abs=math.abs -local pow=math.pow -local Time=UnityEngine.Time - -local ToAngle=57.29578 -local ToRad=0.01745329 -local Epsilon=0.00001 -local Infinite=1/0 -local Sqrt2=0.7071067811865475244008443621048490 -local PI=3.14159265358979323846264338327950 - -local function clamp(v,min,max) - min = min or 0 - max = max or 1 - return v>max and max or (v='A' and k:sub(1,1)<='Z' then - cls[k]=v - end - end -end - -local Matrix3x3={} -local Vector3 - -do - - function Matrix3x3.SetAt(m,row,col,v) - m[row*3+col+1]=v - end - - function Matrix3x3.New() - local r={1,0,0,0,1,0,0,0,1} - setmetatable(r,Matrix3x3) - return r - end - - function Matrix3x3.__tostring(m) - return string.format('Matrix3x3(%f,%f,%f,%f,%f,%f,%f,%f,%f)' - ,m[1],m[2],m[3] - ,m[4],m[5],m[6] - ,m[7],m[8],m[9]) - end - - function Matrix3x3.SetAxisAngle(m,axis,rad) - -- This function contributed by Erich Boleyn (erich@uruk.org) */ - -- This function used from the Mesa OpenGL code (matrix.c) */ - local s, c - local vx, vy, vz, xx, yy, zz, xy, yz, zx, xs, ys, zs, one_c - - s = sin (rad) - c = cos (rad) - - vx = axis[1] - vy = axis[2] - vz = axis[3] - - xx = vx * vx - yy = vy * vy - zz = vz * vz - xy = vx * vy - yz = vy * vz - zx = vz * vx - xs = vx * s - ys = vy * s - zs = vz * s - one_c = 1.0 - c - local Set=Matrix3x3.SetAt - Set(m,0,0, (one_c * xx) + c ) - Set(m,1,0, (one_c * xy) - zs) - Set(m,2,0, (one_c * zx) + ys) - Set(m,0,1, (one_c * xy) + zs) - Set(m,1,1, (one_c * yy) + c ) - Set(m,2,1, (one_c * yz) - xs) - Set(m,0,2, (one_c * zx) - ys) - Set(m,1,2, (one_c * yz) + xs) - Set(m,2,2, (one_c * zz) + c ) - end - - function Matrix3x3.Mul(m,v) - local res=Vector3.New(0,0,0) - res[1] = m[1] * v[1] + m[4] * v[2] + m[7] * v[3] - res[2] = m[2] * v[1] + m[5] * v[2] + m[8] * v[3] - res[3] = m[3] * v[1] + m[6] * v[2] + m[9] * v[3] - return res - end - - function Matrix3x3:SetIdentity() - self[1],self[2],self[3]=1,0,0 - self[4],self[5],self[6]=0,1,0 - self[7],self[8],self[9]=0,0,1 - end - - function Matrix3x3:SetOrthoNormal( x,y,z ) - self[1],self[2],self[3]=x[1],y[1],z[1] - self[4],self[5],self[6]=x[2],y[2],z[2] - self[7],self[8],self[9]=x[3],y[3],z[3] - end -end - -do - local Raw=UnityEngine.Vector3 - Vector3={__typename='Vector3',__raw=Raw} - local T=Vector3 - local I={__typename='Vector3'} - _G['UnityEngine.Vector3.Instance']=I - UnityEngine.Vector3=Vector3 - local get={} - local set={} - - Vector3.__index = function(t,k) - local f=rawget(Vector3,k) - if f then return f end - local f=rawget(get,k) - if f then return f(t) end - error('Not found '..k) - end - - Vector3.__newindex = function(t,k,v) - local f=rawget(set,k) - if f then return f(t,v) end - error('Not found '..k) - end - - - Vector3.New=function (x,y,z) - local v={x or 0,y or 0,z or 0} - setmetatable(v,I) - return v - end - - Vector3.__call = function(t,x,y,z) - return Vector3.New(x,y,z) - end - - I.__index = function(t,k) - local f=rawget(I,k) - if f then return f end - local f=rawget(get,k) - if f then return f(t) end - error('Not found '..k) - end - - I.__newindex = function(t,k,v) - local f=rawget(set,k) - if f then return f(t,v) end - error('Not found '..k) - end - - I.__eq = function(a,b) - return abs(a[1]-b[1])Epsilon then - v[1],v[2],v[3]=v[1]/m,v[2]/m,v[3]/m - else - v:Set(0,0,0) - end - end - - function Vector3.Normalize(v) - local v=Vector3.Clone(v) - Vector3.Normalized(v) - return v - end - - function I:Normalize() - Vector3.Normalized(self) - end - - function Vector3.Magnitude(v) - local v= sqrt(v[1]^2+v[2]^2+v[3]^2) - return v - end - - function Vector3.SqrMagnitude(v) - local v= v[1]^2+v[2]^2+v[3]^2 - return v - end - - function Vector3.Dot(a,b) - local v= a[1]*b[1] + a[2]*b[2] + a[3]*b[3] - return v - end - - function Vector3.Cross(a,b) - return Vector3.New((a[2] * b[3]) - (a[3] * b[2]) - , (a[3] * b[1]) - (a[1] * b[3]) - , (a[1] * b[2]) - (a[2] * b[1])) - end - - function Vector3.OrthoNormalVector(n) - local res=Vector3.New(0,0,0) - if abs(n[3]) > Sqrt2 then - local a = n[2]^2 + n[3]^2 - local k = 1 / sqrt (a) - res[1],res[2],res[3] = 0,-n[3]*k,n[2]*k - else - local a = n[1]^2 + n[2]^2 - local k = 1 / sqrt (a) - res[1],res[2],res[3] = -n[2]*k,n[1]*k,0 - end - return res - end - - function Vector3.Slerp(a,b,t) - if t<=0 then return Vector3.Clone(a) end - if t>=1 then return Vector3.Clone(b) end - - local ma=Vector3.Magnitude(a) - local mb=Vector3.Magnitude(b) - if ma1-Epsilon then - return Vector3.Lerp(a,b,t) - elseif dot<-1+Epsilon then - local lerpedMagnitude = lerpf (ma, mb, t) - local na = I.__div(a,ma) - local axis = Vector3.OrthoNormalVector(na) - local m=Matrix3x3.New() - Matrix3x3.SetAxisAngle(m,axis,PI*t) - local slerped = Matrix3x3.Mul(m,na) - Vector3.Mul(slerped,lerpedMagnitude) - return slerped - else - local lerpedMagnitude = lerpf (ma, mb, t) - local axis = Vector3.Cross(a,b) - local na = a/ma - Vector3.Normalized(axis) - local angle=acos(dot)*t - local m=Matrix3x3.New() - Matrix3x3.SetAxisAngle(m,axis,angle) - local slerped = Matrix3x3.Mul(m,na) - Vector3.Mul(slerped,lerpedMagnitude) - return slerped - end - end - - function Vector3.Lerp(a,b,t) - return Vector3.New(a[1]+(b[1]-a[1])*t - ,a[2]+(b[2]-a[2])*t - ,a[3]+(b[3]-a[3])*t - ) - end - - function Vector3.Min(a,b) - return Vector3.New(min(a[1],b[1]) - ,min(a[2],b[2]) - ,min(a[3],b[3])) - end - - function Vector3.Max(a,b) - return Vector3.New(max(a[1],b[1]) - ,max(a[2],b[2]) - ,max(a[3],b[3])) - end - - function Vector3.MoveTowards(a,b,adv) - local v = I.__sub(b,a) - local m = Vector3.Magnitude(v) - if m>adv and m~=0 then - Vector3.Div(v,m) - Vector3.Mul(v,adv) - Vector3.Add(v,a) - return v - end - return Vector3.Clone(b) - end - - local function ClampedMove(a,b,mag) - local delta = b-a - if delta > 0 then - return a + min (delta, mag) - else - return a - min (-delta, mag) - end - end - - function Vector3.RotateTowards(a,b,angleMove,mag) - local ma = Vector3.Magnitude(a) - local mb = Vector3.Magnitude (b) - - if ma > Epsilon and mb > Epsilon then - local na = a / ma - local nb = b / mb - - local dot = Vector3.Dot(na, nb) - if dot > 1.0 - Epsilon then - return Vector3.MoveTowards (a, b, mag) - elseif dot < -1.0 + Epsilon then - local axis = Vector3.OrthoNormalVector(na) - local m=Matrix3x3.New() - Matrix3x3.SetAxisAngle(m, axis, angleMove) - local rotated = Matrix3x3.Mul(m,na) - Vector3.Mul(rotated,ClampedMove(ma, mb, mag)) - return rotated - else - local angle = acos(dot); - local axis = Vector3.Cross(na, nb) - Vector3.Normalized(axis) - local m=Matrix3x3.New() - Matrix3x3.SetAxisAngle(m,axis, min(angleMove, angle)) - local rotated = Matrix3x3.Mul(m,na) - Vector3.Mul(rotated,ClampedMove(ma, mb, mag)) - return rotated - end - else - return Vector3.MoveTowards (a,b,mag) - end - end - - function Vector3.Distance(a,b) - a=Vector3.Clone(a) - Vector3.Sub(a,b) - return Vector3.Magnitude(a) - end - - function Vector3.OrthoNormalize(u,v,w) - Vector3.Normalized(u) - - local dot0 = Vector3.Dot(u,v) - local tu=Vector3.Clone(u) - Vector3.Mul(tu,dot0) - Vector3.Sub(v,tu) - Vector3.Normalized(v) - - if w then - local dot1 = Vector3.Dot(v,w) - local dot0 = Vector3.Dot(u,w) - local tw=I.__mul(u,dot0) - local tv=I.__mul(v,dot1) - Vector3.Add(tv,tw) - Vector3.Sub(w,tv) - Vector3.Normalized(w) - end - end - - function Vector3.Scale(a,b) - return Vector3.New(a[1]*b[1],a[2]*b[2],a[3]*b[3]) - end - - function I:Scale( self,b ) - return Vector3.Scale(self,b) - end - - -- code copy from reflactor of UnityEgnine - function Vector3.SmoothDamp(current,target,currentVelocity,smoothTime,maxSpeed,deltaTime) - local deltaTime = deltaTime or Time.deltaTime - local maxSpeed = maxSpeed or Infinite - smoothTime = max(Epsilon,smoothTime) - local float num = 2 / smoothTime - local float num2 = num * deltaTime - local float num3 = 1 / (((1 + num2) + ((0.48 * num2) * num2)) + (((0.235 * num2) * num2) * num2)) - local vector = current - target; - local vector2 = target - local maxLength = maxSpeed * smoothTime - vector = Vector3.ClampMagnitude(vector, maxLength) - target = current - vector - local vector3 = currentVelocity + vector * deltaTime * num - local newv = currentVelocity - vector3 * num3 * num - local vector4 = target + (vector + vector3) * num3 - if Vector3.Dot(vector2 - current, vector4 - vector2) > 0 then - vector4 = vector2 - newv = (vector4 - vector2) / deltaTime - end - currentVelocity:Set(newv.x,newv.y,newv.z) - return vector4,currentVelocity - end - - -- code copy from reflactor of UnityEgnine - function Vector3.ClampMagnitude(vector,maxLength) - if Vector3.SqrMagnitude(vector) > (maxLength^2) then - return vector.normalized * maxLength - end - return Vector3.Clone(vector) - end - - function Vector3.Reflect(dir,nml) - local dot=Vector3.Dot(nml,dir)*-2 - local v=I.__mul(nml,dot) - Vector3.Add(v,dir) - return v - end - - -- code copy from reflactor of UnityEgnine - function Vector3.ProjectOnPlane(vector,planeNormal) - return vector - Vector3.Project(vector, planeNormal) - end - - -- code copy from reflactor of UnityEgnine - function Vector3.Project( vector,normal ) - local num = Vector3.Dot(normal, normal) - if num < Epsilon then - return Vector3.zero - end - return (normal * Vector3.Dot(vector, normal)) / num - end - - setmetatable(Vector3,Vector3) -end - -do - - - local Raw=UnityEngine.Color - local Color={__typename='Color',__raw=Raw} - _G['UnityEngine.Color.Instance']=Color - UnityEngine.Color=Color - local get={} - local set={} - - Color.__index = function(t,k) - local f=rawget(Color,k) - if f then return f end - local f=rawget(get,k) - if f then return f(t) end - error('Not found '..k) - end - - Color.__newindex = function(t,k,v) - local f=rawget(set,k) - if f then return f(t,v) end - error('Not found '..k) - end - - Color.__tostring = function(self) - return string.format('Color(%f,%f,%f,%f)',self[1],self[2],self[3],self[4]) - end - - - function Color.New(r,g,b,a) - a=a or 1 - local c={r or 0,g or 0,b or 0,a or 0} - setmetatable(c,Color) - return c - end - - function Color.__call(t,r,g,b,a) - return Color.New(r,g,b,a) - end - - function Color.__add(a,b) - return Color.New(a[1]+b[1],a[2]+b[2],a[3]+b[3],a[4]+b[4]) - end - - function Color.__sub(a,b) - return Color.New(a[1]-b[1],a[2]-b[2],a[3]-b[3],a[4]-b[4]) - end - - function Color.__mul( a,b ) - if type(a)=='number' then - return Color.New(a*b[1],a*b[2],a*b[3],a*b[4]) - elseif type(b)=='number' then - return Color.New(a[1]*b,a[2]*b,a[3]*b,a[4]*b) - else - return Color.New(a[1]*b[1],a[2]*b[2],a[3]*b[3],a[4]*b[4]) - end - end - - function Color.__div( a,b ) - return Color.New(a[1]/b,a[2]/b,a[3]/b,a[4]/b) - end - - function Color.__eq( a,b ) - return a[1]==b[1] and a[2]==b[2] and a[3]==b[3] and a[4]==b[4] - end - - local function ToLinear(value) - if value <= 0.04045 then - return value / 12.92 - elseif value < 1.0 then - return pow((value + 0.055)/1.055, 2.4) - else - return pow(value, 2.4) - end - end - - local function ToGamma(value) - if value <= 0.0 then - return 0.0 - elseif value <= 0.0031308 then - return 12.92 * value - elseif value <= 1.0 then - return 1.055 * pow(value, 0.41666) - 0.055 - else - return pow(value, 0.41666) - end - end - - function get.red() return Color.New(1,0,0,1) end - function get.green() return Color.New(0,1,0,1) end - function get.blue() return Color.New(0,0,1,1) end - function get.white() return Color.New(1,1,1,1) end - function get.black() return Color.New(0,0,0,1) end - function get.yellow() return Color.New(1, 0.9215686, 0.01568628, 1) end - function get.cyan() return Color.New(0,1,1,1) end - function get.magenta() return Color.New(1,0,1,1) end - function get.gray() return Color.New(0.5,0.5,0.5,1) end - function get.grey() return Color.New(0.5,0.5,0.5,1) end - function get.clear() return Color.New(0,0,0,0) end - function get:grayscale() return (0.299 * self[1]) + (0.587 * self[2]) + (0.114 * self[3]) end - function get:linear() - return Color.New(ToLinear(self[1]),ToLinear(self[2]),ToLinear(self[3]),self[4]) - end - function get:gamma() - return Color.New(ToGamma(self[1]),ToGamma(self[2]),ToGamma(self[3]),self[4]) - end - function get:r() return self[1] end - function get:g() return self[2] end - function get:b() return self[3] end - function get:a() return self[4] end - function set:r(v) self[1]=v end - function set:g(v) self[2]=v end - function set:b(v) self[3]=v end - function set:a(v) self[4]=v end - - function Color.Lerp( a,b,t ) - t=clamp(t) - return Color.New( lerpf(a[1],b[1],t),lerpf(a[2],b[2],t),lerpf(a[3],b[3],t),lerpf(a[4],b[4],t) ) - end - - - setmetatable(Color,Color) - -end - -do - local Raw=UnityEngine.Vector2 - local Vector2={__typename='Vector2',__raw=Raw} - _G['UnityEngine.Vector2.Instance']=Vector2 - UnityEngine.Vector2=Vector2 - local get={} - local set={} - - Vector2.__index = function(t,k) - local f=rawget(Vector2,k) - if f then return f end - local f=rawget(get,k) - if f then return f(t) end - error('Not found '..k) - end - - Vector2.__newindex = function(t,k,v) - local f=rawget(set,k) - if f then return f(t,v) end - error('Not found '..k) - end - - Vector2.__tostring = function(self) - return string.format('Vector2(%f,%f)',self[1],self[2]) - end - - function Vector2.New(x,y) - local v={x or 0,y or 0} - setmetatable(v,Vector2) - return v - end - - function Vector2.__call(t,x,y) - return Vector2.New(x,y) - end - - function Vector2.__add( a,b ) - return Vector2.New(a[1]+b[1],a[2]+b[2]) - end - - function Vector2.__sub( a,b ) - return Vector2.New(a[1]-b[1],a[2]-b[2]) - end - - function Vector2.__eq( a,b ) - return abs(a[1]-b[1])0.999999 - end - - - function Quaternion.New(x,y,z,w) - local q={x or 0,y or 0,z or 0,w or 0} - setmetatable(q,Quaternion) - return q - end - - function Quaternion.__call(t,x,y,z,w) - return Quaternion.New(x,y,z,w) - end - - function get.identity() return Quaternion.New(0,0,0,1) end - function get:x() return self[1] end - function get:y() return self[2] end - function get:z() return self[3] end - function get:w() return self[4] end - function set:x(v) self[1]=v end - function set:y(v) self[2]=v end - function set:z(v) self[3]=v end - function set:w(v) self[4]=v end - - function get:eulerAngles() return Inst.eulerAngles[1](self) end - function set:eulerAngles(v) Inst.eulerAngles[2](self,v) end - - function Quaternion:Set(x,y,z,w) - self[1],self[2],self[3],self[4]=x,y,z,w - end - - function Quaternion:Clone() - return Quaternion.New(self[1],self[2],self[3],self[4]) - end - - function Quaternion:ToAngleAxis() - local angle = acos(self[4])*2 - if abs(angle-0) - /// A cache list of MemberInfo, for reflection optimize - /// - static Dictionary>> cachedMemberInfos = new Dictionary>>(); - - class MethodWrapper - { - object self; - IList mis; - public MethodWrapper(object self, IList mi) - { - this.self = self; - this.mis = mi; - } - - bool matchType(IntPtr l, int p, LuaTypes lt, Type t) - { - if (t.IsPrimitive && t != typeof(bool)) - return lt == LuaTypes.LUA_TNUMBER; - - if (t == typeof(bool)) - return lt == LuaTypes.LUA_TBOOLEAN; - - if (t == typeof(string)) - return lt == LuaTypes.LUA_TSTRING; - - switch (lt) - { - case LuaTypes.LUA_TFUNCTION: - return t == typeof(LuaFunction) || t.BaseType == typeof(MulticastDelegate); - case LuaTypes.LUA_TTABLE: - return t == typeof(LuaTable) || LuaObject.luaTypeCheck(l, p, t.Name); - default: - return lt == LuaTypes.LUA_TUSERDATA || t == typeof(object); - } - } - - object checkVar(IntPtr l, int p, Type t) - { - string tn = t.Name; - - switch (tn) - { - case "String": - { - string str; - if (checkType(l, p, out str)) - return str; - } - break; - case "Decimal": - return (decimal)LuaDLL.lua_tonumber(l, p); - case "Int64": - return (long)LuaDLL.lua_tonumber(l, p); - case "UInt64": - return (ulong)LuaDLL.lua_tonumber(l, p); - case "Int32": - return (int)LuaDLL.lua_tointeger(l, p); - case "UInt32": - return (uint)LuaDLL.lua_tointeger(l, p); - case "Single": - return (float)LuaDLL.lua_tonumber(l, p); - case "Double": - return (double)LuaDLL.lua_tonumber(l, p); - case "Boolean": - return (bool)LuaDLL.lua_toboolean(l, p); - case "Byte": - return (byte)LuaDLL.lua_tointeger(l, p); - case "UInt16": - return (ushort)LuaDLL.lua_tointeger(l, p); - case "Int16": - return (short)LuaDLL.lua_tointeger(l, p); - default: - // Enum convert - if (t.IsEnum) - { - var num = LuaDLL.lua_tointeger(l, p); - return Enum.ToObject(t, num); - } - return LuaObject.checkVar(l, p); - } - return null; - } - - internal bool matchType(IntPtr l, int from, ParameterInfo[] pis, bool isstatic) - { - int top = LuaDLL.lua_gettop(l); - from = isstatic ? from : from + 1; - - if (top - from + 1 != pis.Length) - return false; - - for (int n = 0; n < pis.Length; n++) - { - int p = n + from; - LuaTypes t = LuaDLL.lua_type(l, p); - if (!matchType(l, p, t, pis[n].ParameterType)) - return false; - } - return true; - } - - public int invoke(IntPtr l) - { - for (int k = 0; k < mis.Count; k++) - { - MethodInfo m = (MethodInfo)mis[k]; - if (matchType(l, 2, m.GetParameters(), m.IsStatic)) - { - return forceInvoke(l, m); - } - } - // cannot find best match function, try call first one - return forceInvoke(l, mis[0] as MethodInfo); - //return error(l, "Can't find valid overload function {0} to invoke or parameter type mis-matched.", mis[0].Name); - } - - /// - /// invoke a C# method without match check - /// - /// - /// - /// - private int forceInvoke(IntPtr l, MethodInfo m) - { - object[] args; - checkArgs(l, 1, m, out args); - object ret = m.Invoke(m.IsStatic ? null : self, args); - pushValue(l, true); - if (ret != null) - { - pushVar(l, ret); - return 2; - } - return 1; - } - - public void checkArgs(IntPtr l, int from, MethodInfo m, out object[] args) - { - ParameterInfo[] ps = m.GetParameters(); - args = new object[ps.Length]; - int k = 0; - from = m.IsStatic ? from + 1 : from + 2; - - for (int n = from; n <= LuaDLL.lua_gettop(l); n++, k++) - { - if (k + 1 > ps.Length) - break; - args[k] = checkVar(l, n, ps[k].ParameterType); - } - } - } - - - [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))] - static public int luaIndex(IntPtr l) - { - try - { - ObjectCache oc = ObjectCache.get(l); - object self = oc.get(l, 1); - - LuaTypes t = LuaDLL.lua_type(l, 2); - switch (t) - { - case LuaTypes.LUA_TSTRING: - return indexString(l, self, LuaDLL.lua_tostring(l, 2)); - case LuaTypes.LUA_TNUMBER: - return indexInt(l, self, LuaDLL.lua_tointeger(l, 2)); - default: - return indexObject(l, self, checkObj(l, 2)); - } - } - catch (Exception e) - { - return error(l, e); - } - } - - static int indexObject(IntPtr l, object self, object key) - { - - if (self is IDictionary) - { - var dict = self as IDictionary; - - object v = dict[key]; - pushValue(l, true); - pushVar(l, v); - return 2; - } - return 0; - - } - - static Type getType(object o) - { - if (o is LuaClassObject) - return (o as LuaClassObject).GetClsType(); - return o.GetType(); - } - - static int indexString(IntPtr l, object self, string key) - { - Type t = getType(self); - - if (self is IDictionary) - { - if (t.IsGenericType && t.GetGenericArguments()[0] != typeof(string)) - { - goto IndexProperty; - } - object v = (self as IDictionary)[key]; - if (v != null) - { - pushValue(l, true); - pushVar(l, v); - return 2; - } - } - - IndexProperty: - - var mis = GetCacheMembers(t, key); - if (mis == null || mis.Count == 0) - { - return error(l, "Can't find " + key); - } - - pushValue(l, true); - MemberInfo mi = mis[0]; - switch (mi.MemberType) - { - case MemberTypes.Property: - PropertyInfo p = (PropertyInfo)mi; - MethodInfo get = p.GetGetMethod(true); - pushVar(l, get.Invoke(self, null)); - break; - case MemberTypes.Field: - FieldInfo f = (FieldInfo)mi; - pushVar(l, f.GetValue(self)); - break; - case MemberTypes.Method: - LuaCSFunction ff = new MethodWrapper(self, mis).invoke; - pushObject(l, ff); - break; - case MemberTypes.Event: - break; - default: - return 1; - } - - return 2; - - } - - /// - /// Collect Type Members, including base type - /// - /// - /// - /// - static void CollectTypeMembers(Type type, ref Dictionary> membersMap) - { - var mems = type.GetMembers(BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly); // GetMembers can get basetType's members, but GetMember cannot - for (var i = 0; i < mems.Length; i++) - { - var mem = mems[i]; - List members; - if (!membersMap.TryGetValue(mem.Name, out members)) - { - members = membersMap[mem.Name] = new List(); - } - members.Add(mem); - } - if (type.BaseType != null) - { - CollectTypeMembers(type.BaseType, ref membersMap); - } - - } - /// - /// Get Member from Type, use reflection, use cache Dictionary - /// - /// - /// - /// - static IList GetCacheMembers(Type type, string key) - { - Dictionary> cache; - if (!cachedMemberInfos.TryGetValue(type, out cache)) - { - cachedMemberInfos[type] = cache = new Dictionary>(); - // Get Member including all parent fields - CollectTypeMembers(type, ref cache); - } - return cache[key]; - } - - static int newindexString(IntPtr l, object self, string key) - { - if (self is IDictionary) - { - var dictType = getType(self); - var valueType = dictType.GetGenericArguments()[1]; - (self as IDictionary)[key] = checkVar(l, 3, valueType); - return ok(l); - } - - Type t = getType(self); - //MemberInfo[] mis = t.GetMember(key, BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); - //if (mis.Length == 0) - //{ - // return error(l, "Can't find " + key); - //} - - var mis = GetCacheMembers(t, key); - if (mis == null || mis.Count == 0) - { - return error(l, "Can't find " + key); - } - MemberInfo mi = mis[0]; - switch (mi.MemberType) - { - case MemberTypes.Property: - { - PropertyInfo p = (PropertyInfo)mi; - MethodInfo set = p.GetSetMethod(true); - var value = checkVar(l, 3, p.PropertyType); - set.Invoke(self, new object[] { value }); - break; - } - case MemberTypes.Field: - { - FieldInfo f = (FieldInfo)mi; - var value = checkVar(l, 3, f.FieldType); - f.SetValue(self, value); - break; - } - case MemberTypes.Method: - return error(l, "Method can't set"); - case MemberTypes.Event: - return error(l, "Event can't set"); - - } - return ok(l); - } - - - static int indexInt(IntPtr l, object self, int index) - { - Type type = getType(self); - if (self is IList) - { - pushValue(l, true); - pushVar(l, (self as IList)[index]); - return 2; - } - else if (self is IDictionary) - { - var dict = (IDictionary)self;// as IDictionary; - //support enumerate key - object dictKey = index; - if (type.IsGenericType) - { - Type keyType = type.GetGenericArguments()[0]; - - if (keyType.IsEnum) - { - pushValue(l, true); - pushVar(l, dict[Enum.Parse(keyType, dictKey.ToString())]); - return 2; - } - - dictKey = changeType(dictKey, keyType); // if key is not int but ushort/uint, IDictionary will cannot find the key and return null! - } - - pushValue(l, true); - pushVar(l, dict[dictKey]); - return 2; - } - return 0; - } - - static int newindexInt(IntPtr l, object self, int index) - { - Type type = getType(self); - if (self is IList) - { - if (type.IsGenericType) - { - Type t = type.GetGenericArguments()[0]; - (self as IList)[index] = changeType(checkVar(l, 3), t); - } - else - (self as IList)[index] = checkVar(l, 3); - } - else if (self is IDictionary) - { - Type keyType = type.GetGenericArguments()[0]; - object dictKey = index; - dictKey = changeType(dictKey, keyType); // if key is not int but ushort/uint, IDictionary will cannot find the key and return null! - - if (type.IsGenericType) - { - Type t = type.GetGenericArguments()[1]; - (self as IDictionary)[dictKey] = changeType(checkVar(l, 3), t); - } - else - (self as IDictionary)[dictKey] = checkVar(l, 3); - } - - pushValue(l, true); - return 1; - } - - static int newindexObject(IntPtr l, object self, object k, object v) - { - if (self is IDictionary) - { - var dict = self as IDictionary; - var dictType = getType(self); - var valueType = dictType.GetGenericArguments()[1]; - - var key = k; - var value = changeType(v, valueType); - dict[key] = value; - } - return ok(l); - } - - [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))] - static public int luaNewIndex(IntPtr l) - { - try - { - ObjectCache oc = ObjectCache.get(l); - object self = oc.get(l, 1); - - LuaTypes t = LuaDLL.lua_type(l, 2); - switch (t) - { - case LuaTypes.LUA_TSTRING: - return newindexString(l, self, LuaDLL.lua_tostring(l, 2)); - case LuaTypes.LUA_TNUMBER: - return newindexInt(l, self, LuaDLL.lua_tointeger(l, 2)); - default: - return newindexObject(l, self, checkVar(l, 2), checkVar(l, 3)); - } - } - catch (Exception e) - { - return error(l, e); - } - } - - [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))] - static public int methodWrapper(IntPtr l) - { - try - { - ObjectCache oc = ObjectCache.get(l); - LuaCSFunction func = (LuaCSFunction)oc.get(l, 1); - return func(l); - } - catch (Exception e) - { - return error(l, e); - } - } - - static new public void init(IntPtr l) - { - LuaDLL.lua_createtable(l, 0, 3); - pushValue(l, luaIndex); - LuaDLL.lua_setfield(l, -2, "__index"); - pushValue(l, luaNewIndex); - LuaDLL.lua_setfield(l, -2, "__newindex"); - LuaDLL.lua_pushcfunction(l, lua_gc); - LuaDLL.lua_setfield(l, -2, "__gc"); - LuaDLL.lua_setfield(l, LuaIndexes.LUA_REGISTRYINDEX, "LuaVarObject"); - - LuaDLL.lua_createtable(l, 0, 1); - pushValue(l, methodWrapper); - LuaDLL.lua_setfield(l, -2, "__call"); - LuaDLL.lua_setfield(l, LuaIndexes.LUA_REGISTRYINDEX, ObjectCache.getAQName(typeof(LuaCSFunction))); - } - } - - class LuaClassObject - { - Type cls; - - public LuaClassObject(Type t) - { - cls = t; - } - - public Type GetClsType() - { - return cls; - } - } -} diff --git a/KSFramework/Assets/Plugins/Slua_Managed/LuaVarObject.cs.meta b/KSFramework/Assets/Plugins/Slua_Managed/LuaVarObject.cs.meta deleted file mode 100644 index a4e6ea50..00000000 --- a/KSFramework/Assets/Plugins/Slua_Managed/LuaVarObject.cs.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 99134f2c79521c04e9ca31bc724dfe6a -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: diff --git a/KSFramework/Assets/Plugins/Slua_Managed/ObjectCache.cs b/KSFramework/Assets/Plugins/Slua_Managed/ObjectCache.cs deleted file mode 100644 index f7a09706..00000000 --- a/KSFramework/Assets/Plugins/Slua_Managed/ObjectCache.cs +++ /dev/null @@ -1,350 +0,0 @@ -// The MIT License (MIT) - -// Copyright 2015 Siney/Pangweiwei siney@yeah.net -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - - -using System.Runtime.CompilerServices; - -namespace SLua -{ - using System; - using System.Runtime.InteropServices; - using System.Collections.Generic; - using LuaInterface; - using System.Runtime.CompilerServices; - - public class ObjectCache - { - static Dictionary multiState = new Dictionary(); - - static IntPtr oldl = IntPtr.Zero; - static internal ObjectCache oldoc = null; - - public static ObjectCache get(IntPtr l) - { - if (oldl == l) - return oldoc; - ObjectCache oc; - if (multiState.TryGetValue(l, out oc)) - { - oldl = l; - oldoc = oc; - return oc; - } - - LuaDLL.lua_getglobal(l, "__main_state"); - if (LuaDLL.lua_isnil(l, -1)) - { - LuaDLL.lua_pop(l, 1); - return null; - } - - IntPtr nl = LuaDLL.lua_touserdata(l, -1); - LuaDLL.lua_pop(l, 1); - if (nl != l) - return get(nl); - return null; - } - - class ObjSlot - { - public int freeslot; - public object v; - public ObjSlot(int slot, object o) - { - freeslot = slot; - v = o; - } - } - -#if SPEED_FREELIST - class FreeList : List - { - public FreeList() - { - this.Add(new ObjSlot(0, null)); - } - - public int add(object o) - { - ObjSlot free = this[0]; - if (free.freeslot == 0) - { - Add(new ObjSlot(this.Count, o)); - return this.Count - 1; - } - else - { - int slot = free.freeslot; - free.freeslot = this[slot].freeslot; - this[slot].v = o; - this[slot].freeslot = slot; - return slot; - } - } - - public void del(int i) - { - ObjSlot free = this[0]; - this[i].freeslot = free.freeslot; - this[i].v = null; - free.freeslot = i; - } - - public bool get(int i, out object o) - { - if (i < 1 || i > this.Count) - { - throw new ArgumentOutOfRangeException(); - } - - ObjSlot slot = this[i]; - o = slot.v; - return o != null; - } - - public object get(int i) - { - object o; - if (get(i, out o)) - return o; - return null; - } - - public void set(int i, object o) - { - this[i].v = o; - } - } -#else - - class FreeList : Dictionary - { - private int id = 1; - public int add(object o) - { - Add(id, o); - return id++; - } - - public void del(int i) - { - this.Remove(i); - } - - public bool get(int i, out object o) - { - return TryGetValue(i, out o); - } - - public object get(int i) - { - object o; - if (TryGetValue(i, out o)) - return o; - return null; - } - - public void set(int i, object o) - { - this[i] = o; - } - } - -#endif - - FreeList cache = new FreeList(); - public class ObjEqualityComparer : IEqualityComparer - { - public new bool Equals(object x, object y) - { - - return ReferenceEquals(x, y); - } - - public int GetHashCode(object obj) - { - return RuntimeHelpers.GetHashCode(obj); - } - } - - Dictionary objMap = new Dictionary(new ObjEqualityComparer()); - int udCacheRef = 0; - - - public ObjectCache(IntPtr l) - { - LuaDLL.lua_newtable(l); - LuaDLL.lua_newtable(l); - LuaDLL.lua_pushstring(l, "v"); - LuaDLL.lua_setfield(l, -2, "__mode"); - LuaDLL.lua_setmetatable(l, -2); - udCacheRef = LuaDLL.luaL_ref(l, LuaIndexes.LUA_REGISTRYINDEX); - } - - - static public void clear() - { - - oldl = IntPtr.Zero; - oldoc = null; - - } - internal static void del(IntPtr l) - { - multiState.Remove(l); - } - - internal static void make(IntPtr l) - { - ObjectCache oc = new ObjectCache(l); - multiState[l] = oc; - oldl = l; - oldoc = oc; - } - - internal void gc(int index) - { - object o; - if (cache.get(index, out o)) - { - int oldindex; - if (isGcObject(o) && objMap.TryGetValue(o,out oldindex) && oldindex==index) - { - objMap.Remove(o); - } - cache.del(index); - } - } -#if !SLUA_STANDALONE - internal void gc(UnityEngine.Object o) - { - int index; - if(objMap.TryGetValue(o, out index)) - { - objMap.Remove(o); - cache.del(index); - } - } -#endif - - internal int add(object o) - { - int objIndex = cache.add(o); - if (isGcObject(o)) - { - objMap[o] = objIndex; - } - return objIndex; - } - - internal object get(IntPtr l, int p) - { - - int index = LuaDLL.luaS_rawnetobj(l, p); - object o; - if (index != -1 && cache.get(index, out o)) - { - return o; - } - return null; - - } - - internal void setBack(IntPtr l, int p, object o) - { - - int index = LuaDLL.luaS_rawnetobj(l, p); - if (index != -1) - { - cache.set(index, o); - } - - } - - internal void push(IntPtr l, object o) - { - push(l, o, true); - } - - internal void push(IntPtr l, Array o) - { - push(l, o, true, true); - } - - internal void push(IntPtr l, object o, bool checkReflect, bool isArray=false) - { - if (o == null) - { - LuaDLL.lua_pushnil(l); - return; - } - - int index = -1; - - bool gco = isGcObject(o); - bool found = gco && objMap.TryGetValue(o, out index); - if (found) - { - if (LuaDLL.luaS_getcacheud(l, index, udCacheRef) == 1) - return; - } - - index = add(o); -#if SLUA_CHECK_REFLECTION - int isReflect = LuaDLL.luaS_pushobject(l, index, isArray ? "LuaArray" : getAQName(o), gco, udCacheRef); - if (isReflect != 0 && checkReflect && !isArray) - { - Logger.LogWarning(string.Format("{0} not exported, using reflection instead", o.ToString())); - } -#else - LuaDLL.luaS_pushobject(l, index, isArray?"LuaArray":getAQName(o), gco, udCacheRef); -#endif - - } - - static Dictionary aqnameMap = new Dictionary(); - static string getAQName(object o) - { - Type t = o.GetType(); - return getAQName(t); - } - - internal static string getAQName(Type t) - { - string name; - if (aqnameMap.TryGetValue(t, out name)) - { - return name; - } - name = t.AssemblyQualifiedName; - aqnameMap[t] = name; - return name; - } - - - bool isGcObject(object obj) - { - return obj.GetType().IsValueType == false; - } - } -} - diff --git a/KSFramework/Assets/Plugins/Slua_Managed/ObjectCache.cs.meta b/KSFramework/Assets/Plugins/Slua_Managed/ObjectCache.cs.meta deleted file mode 100644 index f901a6d4..00000000 --- a/KSFramework/Assets/Plugins/Slua_Managed/ObjectCache.cs.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: db802782d21a2cb4f99e0b7785cd279c -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: diff --git a/KSFramework/Assets/Plugins/Slua_Managed/SLuaSetting.cs b/KSFramework/Assets/Plugins/Slua_Managed/SLuaSetting.cs deleted file mode 100644 index f5d269cd..00000000 --- a/KSFramework/Assets/Plugins/Slua_Managed/SLuaSetting.cs +++ /dev/null @@ -1,81 +0,0 @@ -// The MIT License (MIT) - -// Copyright 2015 Siney/Pangweiwei siney@yeah.net -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -using System.Collections; -#if UNITY_EDITOR -using UnityEditor; -#endif -#if !SLUA_STANDALONE -using UnityEngine; -#endif - -namespace SLua{ - public enum EOL{ - Native, - CRLF, - CR, - LF, - } - - public class SLuaSetting -#if !SLUA_STANDALONE - : ScriptableObject -#endif - { - - public EOL eol = EOL.Native; - public bool exportExtensionMethod = true; - public string UnityEngineGeneratePath = "Assets/Slua/LuaObject/"; - - public int debugPort=10240; - public string debugIP="0.0.0.0"; - - private static SLuaSetting _instance=null; - public static SLuaSetting Instance{ - get{ -#if !SLUA_STANDALONE - if(_instance == null){ - _instance = Resources.Load("setting"); - -#if UNITY_EDITOR - if(_instance == null){ - _instance = SLuaSetting.CreateInstance(); - AssetDatabase.CreateAsset(_instance,"Assets/Slua/Resources/setting.asset"); - } -#endif - - } -#endif - return _instance; - } - } - -#if UNITY_EDITOR && !SLUA_STANDALONE - [MenuItem("SLua/Setting")] - public static void Open(){ - Selection.activeObject = Instance; - } -#endif - - } - -} diff --git a/KSFramework/Assets/Plugins/Slua_Managed/SLuaSetting.cs.meta b/KSFramework/Assets/Plugins/Slua_Managed/SLuaSetting.cs.meta deleted file mode 100644 index 39cbed47..00000000 --- a/KSFramework/Assets/Plugins/Slua_Managed/SLuaSetting.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: aa35f0feac8a2f2459bb9b0f11233a7e -timeCreated: 1449026073 -licenseType: Free -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/KSFramework/Assets/Plugins/Slua_Managed/Timer.cs b/KSFramework/Assets/Plugins/Slua_Managed/Timer.cs deleted file mode 100644 index 6a0fa266..00000000 --- a/KSFramework/Assets/Plugins/Slua_Managed/Timer.cs +++ /dev/null @@ -1,358 +0,0 @@ -// The MIT License (MIT) - -// Copyright 2015 Siney/Pangweiwei siney@yeah.net -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -namespace SLua -{ - using LuaInterface; - using System; - using System.Collections.Generic; - - public class LuaTimer : LuaObject - { - class Timer - { - internal int sn; - internal int cycle; - internal int deadline; - internal Func handler; - internal bool delete; - internal LinkedList container; - } - class Wheel - { - internal static int dial_scale = 256; - internal int head; - internal LinkedList[] vecDial; - internal int dialSize; - internal int timeRange; - internal Wheel nextWheel; - internal Wheel(int dialSize) - { - this.dialSize = dialSize; - this.timeRange = dialSize * dial_scale; - this.head = 0; - this.vecDial = new LinkedList[dial_scale]; - for (int i = 0; i < dial_scale; ++i) - { - this.vecDial[i] = new LinkedList(); - } - } - internal LinkedList nextDial() - { - return vecDial[head++]; - } - internal void add(int delay, Timer tm) - { - var container = vecDial[(head + (delay - (dialSize - jiffies_msec)) / dialSize) % dial_scale]; - container.AddLast(tm); - tm.container = container; - } - } - static int nextSn = 0; - static int jiffies_msec = 20; - static float jiffies_sec = jiffies_msec * .001f; - static Wheel[] wheels; - static float pileSecs; - static float nowTime; - static Dictionary mapSnTimer; - static LinkedList executeTimers; - - static int intpow(int n, int m) - { - int ret = 1; - for (int i = 0; i < m; ++i) - ret *= n; - return ret; - } - - static void innerAdd(int deadline, Timer tm) - { - tm.deadline = deadline; - int delay = Math.Max(0, deadline - now()); - Wheel suitableWheel = wheels[wheels.Length - 1]; - for (int i = 0; i < wheels.Length; ++i) - { - var wheel = wheels[i]; - if (delay < wheel.timeRange) - { - suitableWheel = wheel; - break; - } - } - suitableWheel.add(delay, tm); - } - - static void innerDel(Timer tm) - { - innerDel(tm, true); - } - - static void innerDel(Timer tm,bool removeFromMap) - { - tm.delete = true; - if (tm.container != null) - { - tm.container.Remove(tm); - tm.container = null; - } - if (removeFromMap) mapSnTimer.Remove(tm.sn); - } - - static int now() - { - return (int)(nowTime * 1000); - } - - internal static void tick(float deltaTime) - { - nowTime += deltaTime; - pileSecs += deltaTime; - int cycle = 0; - while (pileSecs >= jiffies_sec) - { - pileSecs -= jiffies_sec; - cycle++; - } - for (int i = 0; i < cycle; ++i) - { - var timers = wheels[0].nextDial(); - LinkedListNode node = timers.First; - for (int j = 0; j < timers.Count; ++j) - { - var tm = node.Value; - executeTimers.AddLast(tm); - node = node.Next; - } - timers.Clear(); - - for (int j = 0; j < wheels.Length; ++j) - { - var wheel = wheels[j]; - if (wheel.head == Wheel.dial_scale) - { - wheel.head = 0; - if (wheel.nextWheel != null) - { - var tms = wheel.nextWheel.nextDial(); - LinkedListNode tmsNode = tms.First; - for (int k = 0; k < tms.Count; ++k) - { - var tm = tmsNode.Value; - if (tm.delete) - { - mapSnTimer.Remove(tm.sn); - } - else - { - innerAdd(tm.deadline, tm); - } - tmsNode = tmsNode.Next; - } - tms.Clear(); - } - } - else - { - break; - } - } - } - - while (executeTimers.Count > 0) - { - var tm = executeTimers.First.Value; - executeTimers.Remove(tm); - if (!tm.delete && tm.handler(tm.sn) && tm.cycle > 0) - { - innerAdd(now() + tm.cycle, tm); - } - else - { - mapSnTimer.Remove(tm.sn); - } - } - } - - static void init() - { - wheels = new Wheel[4]; - for (int i = 0; i < 4; ++i) - { - wheels[i] = new Wheel(jiffies_msec * intpow(Wheel.dial_scale, i)); - if (i > 0) - { - wheels[i - 1].nextWheel = wheels[i]; - } - } - mapSnTimer = new Dictionary(); - executeTimers = new LinkedList(); - } - - static int fetchSn() - { - return ++nextSn; - } - - internal static int add(int delay, Action handler) - { - return add(delay, 0, (int sn) => - { - handler(sn); - return false; - }); - } - - internal static int add(int delay, int cycle, Func handler) - { - Timer tm = new Timer(); - tm.sn = fetchSn(); - tm.cycle = cycle; - tm.handler = handler; - mapSnTimer[tm.sn] = tm; - innerAdd(now() + delay, tm); - return tm.sn; - } - - internal static void del(int sn) - { - Timer tm; - if (mapSnTimer.TryGetValue(sn, out tm)) - { - innerDel(tm); - } - } - - [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))] - public static int Delete(IntPtr l) - { - try{ - int id; - checkType(l, 1, out id); - del(id); - return ok(l); - }catch(Exception e) - { - return LuaObject.error(l, e); - } - } - - [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))] - public static int Add(IntPtr l) - { - try{ - int top = LuaDLL.lua_gettop(l); - if (top == 2) - { - int delay; - checkType(l, 1, out delay); - LuaDelegate ld; - checkType(l, 2, out ld); - Action ua; - if (ld.d != null) - ua = (Action)ld.d; - else - { - IntPtr ml = LuaState.get(l).L; - ua = (int id) => - { - int error = pushTry(ml); - pushValue(ml, id); - ld.pcall(1, error); - LuaDLL.lua_settop(ml, error - 1); - }; - } - ld.d = ua; - pushValue(l, true); - pushValue(l, add(delay, ua)); - return 2; - } - else if (top == 3) - { - int delay, cycle; - checkType(l, 1, out delay); - checkType(l, 2, out cycle); - LuaDelegate ld; - checkType(l, 3, out ld); - Func ua; - - if (ld.d != null) - ua = (Func)ld.d; - else - { - IntPtr ml = LuaState.get(l).L; - ua = (int id) => - { - int error = pushTry(ml); - pushValue(ml, id); - ld.pcall(1, error); - bool ret = LuaDLL.lua_toboolean(ml, -1); - LuaDLL.lua_settop(ml, error - 1); - return ret; - }; - } - ld.d = ua; - pushValue(l, true); - pushValue(l, add(delay, cycle, ua)); - return 2; - } - return LuaObject.error(l,"Argument error"); - }catch(Exception e) - { - return LuaObject.error(l, e); - } - } - - - [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))] - public static int DeleteAll(IntPtr l) - { - if (mapSnTimer == null) return 0; - try - { - foreach (var t in mapSnTimer) - { - innerDel(t.Value, false); - } - mapSnTimer.Clear(); - - pushValue(l, true); - return 1; - } - catch (Exception e) - { - return LuaObject.error(l, e); - } - } - - - static public void reg(IntPtr l) - { - init(); - getTypeTable(l, "LuaTimer"); - addMember(l, Add, false); - addMember(l, Delete, false); - addMember(l, DeleteAll, false); - createTypeMetatable(l, typeof(LuaTimer)); - } - } - -} diff --git a/KSFramework/Assets/Plugins/Slua_Managed/Timer.cs.meta b/KSFramework/Assets/Plugins/Slua_Managed/Timer.cs.meta deleted file mode 100644 index f194ae59..00000000 --- a/KSFramework/Assets/Plugins/Slua_Managed/Timer.cs.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: da187042c429ccc4ba59078d71f63ce2 -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: diff --git a/KSFramework/Assets/Plugins/Slua_Managed/WeakDictionary.cs b/KSFramework/Assets/Plugins/Slua_Managed/WeakDictionary.cs deleted file mode 100644 index e7745cef..00000000 --- a/KSFramework/Assets/Plugins/Slua_Managed/WeakDictionary.cs +++ /dev/null @@ -1,108 +0,0 @@ -// The MIT License (MIT) - -// Copyright 2015 Siney/Pangweiwei siney@yeah.net -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - - - -namespace SLua -{ - using System; - using System.Collections.Generic; - - public class WeakDictionary - { - Dictionary _dict = new Dictionary(); - - public V this[K key] - { - get - { - WeakReference w = _dict[key]; - if (w.IsAlive) - return (V)w.Target; - return default(V); - } - - set - { - Add(key, value); - } - } - - - ICollection Keys - { - get - { - return _dict.Keys; - } - } - ICollection Values - { - get - { - List l = new List(); - foreach (K key in _dict.Keys) - { - l.Add((V)_dict[key].Target); - } - return l; - } - } - - void Add(K key, V value) - { - if (_dict.ContainsKey(key)) - { - if (_dict[key].IsAlive) - throw new ArgumentException("key exists"); - - _dict[key].Target = value; - } - else - { - WeakReference w = new WeakReference(value); - _dict.Add(key, w); - } - } - - bool ContainsKey(K key) - { - return _dict.ContainsKey(key); - } - bool Remove(K key) - { - return _dict.Remove(key); - } - bool TryGetValue(K key, out V value) - { - WeakReference w; - if (_dict.TryGetValue(key, out w)) - { - value = (V)w.Target; - return true; - } - value = default(V); - return false; - - } - } -} \ No newline at end of file diff --git a/KSFramework/Assets/Plugins/Slua_Managed/WeakDictionary.cs.meta b/KSFramework/Assets/Plugins/Slua_Managed/WeakDictionary.cs.meta deleted file mode 100644 index 534d44dd..00000000 --- a/KSFramework/Assets/Plugins/Slua_Managed/WeakDictionary.cs.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: fe67559fdd76f4618a6a0fd2e68f6dd2 -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: diff --git a/KSFramework/Assets/Plugins/libs.meta b/KSFramework/Assets/Plugins/libs.meta index ec3140ec..d4e77ff4 100644 --- a/KSFramework/Assets/Plugins/libs.meta +++ b/KSFramework/Assets/Plugins/libs.meta @@ -1,8 +1,6 @@ fileFormatVersion: 2 -guid: 4f1f776064b909d428477b26ffdb839c +guid: d8770a5ff5441436a9c28efb893d8b66 folderAsset: yes -timeCreated: 1464666344 -licenseType: Pro DefaultImporter: userData: assetBundleName: diff --git a/KSFramework/Assets/Plugins/libs/armeabi-v7a.meta b/KSFramework/Assets/Plugins/libs/armeabi-v7a.meta new file mode 100644 index 00000000..c1664b5f --- /dev/null +++ b/KSFramework/Assets/Plugins/libs/armeabi-v7a.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 81912b35ad39b9f43b756f78801feda5 +folderAsset: yes +timeCreated: 1472434440 +licenseType: Pro +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/KSFramework/Assets/Plugins/libs/x86.meta b/KSFramework/Assets/Plugins/libs/x86.meta new file mode 100644 index 00000000..c45bb413 --- /dev/null +++ b/KSFramework/Assets/Plugins/libs/x86.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: e1a2e2f9e3356d540b234f35c8d73a0e +folderAsset: yes +timeCreated: 1472434440 +licenseType: Pro +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/KSFramework/Assets/Plugins/slua.bundle/slua.bundle.meta b/KSFramework/Assets/Plugins/slua.bundle/slua.bundle.meta new file mode 100644 index 00000000..24657ca1 --- /dev/null +++ b/KSFramework/Assets/Plugins/slua.bundle/slua.bundle.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 4071a75635bf248a086780cece51d460 +folderAsset: yes +timeCreated: 1472322821 +licenseType: Pro +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/KSFramework/Assets/Plugins/slua.bundle/slua.bundle/Contents.meta b/KSFramework/Assets/Plugins/slua.bundle/slua.bundle/Contents.meta new file mode 100644 index 00000000..42aac9bb --- /dev/null +++ b/KSFramework/Assets/Plugins/slua.bundle/slua.bundle/Contents.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 441dd43acdf5345a39b0119ba1b65b23 +folderAsset: yes +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/KSFramework/Assets/Plugins/slua.bundle/slua.bundle/Contents/Info.plist b/KSFramework/Assets/Plugins/slua.bundle/slua.bundle/Contents/Info.plist new file mode 100644 index 00000000..24652e53 --- /dev/null +++ b/KSFramework/Assets/Plugins/slua.bundle/slua.bundle/Contents/Info.plist @@ -0,0 +1,46 @@ + + + + + BuildMachineOSBuild + 15B42 + CFBundleDevelopmentRegion + en + CFBundleExecutable + slua + CFBundleIdentifier + com.sineysoft.slua + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + slua + CFBundlePackageType + BNDL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleSupportedPlatforms + + MacOSX + + CFBundleVersion + 1 + DTCompiler + com.apple.compilers.llvm.clang.1_0 + DTPlatformBuild + 7B1005 + DTPlatformVersion + GM + DTSDKBuild + 15A278 + DTSDKName + macosx10.11 + DTXcode + 0711 + DTXcodeBuild + 7B1005 + NSHumanReadableCopyright + Copyright © 2015年 Pang Weiwei. All rights reserved. + + diff --git a/KSFramework/Assets/Plugins/slua.bundle/slua.bundle/Contents/Info.plist.meta b/KSFramework/Assets/Plugins/slua.bundle/slua.bundle/Contents/Info.plist.meta new file mode 100644 index 00000000..5915f352 --- /dev/null +++ b/KSFramework/Assets/Plugins/slua.bundle/slua.bundle/Contents/Info.plist.meta @@ -0,0 +1,6 @@ +fileFormatVersion: 2 +guid: 34ab763b3ebcb4bfdb5085535ed744b2 +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/KSFramework/Assets/Plugins/slua.bundle/slua.bundle/Contents/MacOS.meta b/KSFramework/Assets/Plugins/slua.bundle/slua.bundle/Contents/MacOS.meta new file mode 100644 index 00000000..1703c653 --- /dev/null +++ b/KSFramework/Assets/Plugins/slua.bundle/slua.bundle/Contents/MacOS.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 42163d3bdca954d909ddc9b14adc6a0f +folderAsset: yes +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/KSFramework/Assets/Plugins/slua.bundle/slua.bundle/Contents/MacOS/slua b/KSFramework/Assets/Plugins/slua.bundle/slua.bundle/Contents/MacOS/slua new file mode 100644 index 00000000..9bcd3256 Binary files /dev/null and b/KSFramework/Assets/Plugins/slua.bundle/slua.bundle/Contents/MacOS/slua differ diff --git a/KSFramework/Assets/Plugins/slua.bundle/slua.bundle/Contents/MacOS/slua.meta b/KSFramework/Assets/Plugins/slua.bundle/slua.bundle/Contents/MacOS/slua.meta new file mode 100644 index 00000000..8278cd25 --- /dev/null +++ b/KSFramework/Assets/Plugins/slua.bundle/slua.bundle/Contents/MacOS/slua.meta @@ -0,0 +1,6 @@ +fileFormatVersion: 2 +guid: 1d7421e4b9bdb4ce3a663f94ee21acea +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/KSFramework/Assets/SLua/Editor/LuaCodeGen.cs b/KSFramework/Assets/SLua/Editor/LuaCodeGen.cs index 7a8dbb44..54565e7b 100644 --- a/KSFramework/Assets/SLua/Editor/LuaCodeGen.cs +++ b/KSFramework/Assets/SLua/Editor/LuaCodeGen.cs @@ -132,34 +132,34 @@ static public void Generate() CustomExport.OnGetUseList(out uselist); // Get use and nouse list from custom export. - object[] aCustomExport = new object[1]; - InvokeEditorMethod("OnGetUseList", ref aCustomExport); - if (null != aCustomExport[0]) - { - if (null != uselist) - { - uselist.AddRange((List)aCustomExport[0]); - } - else - { - uselist = (List)aCustomExport[0]; - } - } - - aCustomExport[0] = null; - InvokeEditorMethod("OnGetNoUseList", ref aCustomExport); - if (null != aCustomExport[0]) - { - if ((null != noUseList)) - { - noUseList.AddRange((List)aCustomExport[0]); - } - else - { - noUseList = (List)aCustomExport[0]; - } - } - + object[] aCustomExport = new object[1]; + InvokeEditorMethod("OnGetUseList", ref aCustomExport); + if (null != aCustomExport[0]) + { + if (null != uselist) + { + uselist.AddRange((List)aCustomExport[0]); + } + else + { + uselist = (List)aCustomExport[0]; + } + } + + aCustomExport[0] = null; + InvokeEditorMethod("OnGetNoUseList", ref aCustomExport); + if (null != aCustomExport[0]) + { + if ((null != noUseList)) + { + noUseList.AddRange((List)aCustomExport[0]); + } + else + { + noUseList = (List)aCustomExport[0]; + } + } + List exports = new List(); string path = GenPath + "Unity/"; foreach (Type t in types) @@ -210,34 +210,34 @@ static public void GenerateUI() CustomExport.OnGetUseList(out uselist); // Get use and nouse list from custom export. - object[] aCustomExport = new object[1]; - InvokeEditorMethod("OnGetUseList", ref aCustomExport); - if (null != aCustomExport[0]) - { - if (null != uselist) - { - uselist.AddRange((List)aCustomExport[0]); - } - else - { - uselist = (List)aCustomExport[0]; - } - } - - aCustomExport[0] = null; - InvokeEditorMethod("OnGetNoUseList", ref aCustomExport); - if (null != aCustomExport[0]) - { - if ((null != noUseList)) - { - noUseList.AddRange((List)aCustomExport[0]); - } - else - { - noUseList = (List)aCustomExport[0]; - } - } - + object[] aCustomExport = new object[1]; + InvokeEditorMethod("OnGetUseList", ref aCustomExport); + if (null != aCustomExport[0]) + { + if (null != uselist) + { + uselist.AddRange((List)aCustomExport[0]); + } + else + { + uselist = (List)aCustomExport[0]; + } + } + + aCustomExport[0] = null; + InvokeEditorMethod("OnGetNoUseList", ref aCustomExport); + if (null != aCustomExport[0]) + { + if ((null != noUseList)) + { + noUseList.AddRange((List)aCustomExport[0]); + } + else + { + noUseList = (List)aCustomExport[0]; + } + } + Assembly assembly = Assembly.Load("UnityEngine.UI"); Type[] types = assembly.GetExportedTypes(); @@ -297,12 +297,12 @@ static public void Custom() // Add custom namespaces. object[] aCustomExport = null; List aCustomNs = LuaCodeGen.InvokeEditorMethod("OnAddCustomNamespace", ref aCustomExport); - foreach (object cNsSet in aCustomNs) - { - foreach (string strNs in (HashSet)cNsSet) - { - namespaces.Add(strNs); - } + foreach (object cNsSet in aCustomNs) + { + foreach (string strNs in (HashSet)cNsSet) + { + namespaces.Add(strNs); + } } Assembly assembly; @@ -333,9 +333,9 @@ static public void Custom() } } - CustomExport.OnAddCustomClass(fun); - - //detect interface ICustomExportPost,and call OnAddCustomClass + CustomExport.OnAddCustomClass(fun); + + //detect interface ICustomExportPost,and call OnAddCustomClass aCustomExport = new object[] { fun }; InvokeEditorMethod("OnAddCustomClass", ref aCustomExport); @@ -346,23 +346,23 @@ static public void Custom() Debug.Log("Generate custom interface finished"); } - static public List InvokeEditorMethod(string methodName, ref object[] parameters) + static public List InvokeEditorMethod(string methodName, ref object[] parameters) { - List aReturn = new List(); + List aReturn = new List(); System.Reflection.Assembly editorAssembly = System.Reflection.Assembly.Load("Assembly-CSharp-Editor"); Type[] editorTypes = editorAssembly.GetExportedTypes(); foreach (Type t in editorTypes) { - if(typeof(T).IsAssignableFrom(t)) + if(typeof(T).IsAssignableFrom(t)) { - System.Reflection.MethodInfo method = t.GetMethod(methodName,System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public); - if (method != null) - { - object cRes = method.Invoke(null, parameters); - if (null != cRes) - { - aReturn.Add(cRes); - } + System.Reflection.MethodInfo method = t.GetMethod(methodName,System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public); + if (method != null) + { + object cRes = method.Invoke(null, parameters); + if (null != cRes) + { + aReturn.Add(cRes); + } } } } @@ -370,28 +370,28 @@ static public List InvokeEditorMethod(string methodName, ref object[] return aReturn; } - static public List GetEditorField(string strFieldName) - { - List aReturn = new List(); - System.Reflection.Assembly cEditorAssembly = System.Reflection.Assembly.Load("Assembly-CSharp-Editor"); - Type[] aEditorTypes = cEditorAssembly.GetExportedTypes(); - foreach (Type t in aEditorTypes) - { - if (typeof(T).IsAssignableFrom(t)) - { - FieldInfo cField = t.GetField(strFieldName, BindingFlags.Static | BindingFlags.Public); - if (null != cField) - { - object cValue = cField.GetValue(t); - if (null != cValue) - { - aReturn.Add(cValue); - } - } - } + static public List GetEditorField(string strFieldName) + { + List aReturn = new List(); + System.Reflection.Assembly cEditorAssembly = System.Reflection.Assembly.Load("Assembly-CSharp-Editor"); + Type[] aEditorTypes = cEditorAssembly.GetExportedTypes(); + foreach (Type t in aEditorTypes) + { + if (typeof(T).IsAssignableFrom(t)) + { + FieldInfo cField = t.GetField(strFieldName, BindingFlags.Static | BindingFlags.Public); + if (null != cField) + { + object cValue = cField.GetValue(t); + if (null != cValue) + { + aReturn.Add(cValue); + } + } + } } - return aReturn; + return aReturn; } [MenuItem("SLua/3rdDll/Make")] @@ -403,10 +403,10 @@ static public void Generate3rdDll() List cust = new List(); List assemblyList = new List(); - CustomExport.OnAddCustomAssembly(ref assemblyList); - - //detect interface ICustomExportPost,and call OnAddCustomAssembly - object[] aCustomExport = new object[] { assemblyList }; + CustomExport.OnAddCustomAssembly(ref assemblyList); + + //detect interface ICustomExportPost,and call OnAddCustomAssembly + object[] aCustomExport = new object[] { assemblyList }; InvokeEditorMethod("OnAddCustomAssembly", ref aCustomExport); foreach (string assemblyItem in assemblyList) @@ -549,20 +549,20 @@ class CodeGenerator CustomExport.OnGetAssemblyToGenerateExtensionMethod(out asems); // Get list from custom export. - object[] aCustomExport = new object[1]; - LuaCodeGen.InvokeEditorMethod("OnGetAssemblyToGenerateExtensionMethod", ref aCustomExport); - if (null != aCustomExport[0]) - { - if (null != asems) - { - asems.AddRange((List)aCustomExport[0]); - } - else - { - asems = (List)aCustomExport[0]; - } - } - + object[] aCustomExport = new object[1]; + LuaCodeGen.InvokeEditorMethod("OnGetAssemblyToGenerateExtensionMethod", ref aCustomExport); + if (null != aCustomExport[0]) + { + if (null != asems) + { + asems.AddRange((List)aCustomExport[0]); + } + else + { + asems = (List)aCustomExport[0]; + } + } + foreach (string assstr in asems) { Assembly assembly = Assembly.Load(assstr); @@ -1045,9 +1045,9 @@ void RegEnumFunction(Type t, StreamWriter file) Write(file, "static public void reg(IntPtr l) {"); Write(file, "getEnumTable(l,\"{0}\");", string.IsNullOrEmpty(givenNamespace) ? FullName(t) : givenNamespace); - foreach (object value in Enum.GetValues (t)) + foreach (string name in Enum.GetNames (t)) { - Write(file, "addMember(l,{0},\"{1}\");", Convert.ToInt32(value), value.ToString()); + Write(file, "addMember(l,{0},\"{1}\");", Convert.ToInt32(Enum.Parse(t, name)), name); } Write(file, "LuaDLL.lua_pop(l, 1);"); @@ -1608,12 +1608,12 @@ bool DontExport(MemberInfo mi) // Check in custom export function filter list. List aFuncFilterList = LuaCodeGen.GetEditorField("FunctionFilterList"); - foreach (object aFilterList in aFuncFilterList) - { - if (((List)aFilterList).Contains(methodString)) - { - return true; - } + foreach (object aFilterList in aFuncFilterList) + { + if (((List)aFilterList).Contains(methodString)) + { + return true; + } } return mi.IsDefined(typeof(DoNotToLuaAttribute), false); diff --git a/KSFramework/Assets/SLua/Editor/obj.meta b/KSFramework/Assets/SLua/Editor/obj.meta index 08154179..74c93d9f 100644 --- a/KSFramework/Assets/SLua/Editor/obj.meta +++ b/KSFramework/Assets/SLua/Editor/obj.meta @@ -3,3 +3,5 @@ guid: 02eedaf63ed771e458b7f38c6ac61f26 folderAsset: yes DefaultImporter: userData: + assetBundleName: + assetBundleVariant: diff --git a/KSFramework/Assets/SLua/Meta/Resources/lua3rdmeta.asset.meta b/KSFramework/Assets/SLua/Meta/Resources/lua3rdmeta.asset.meta index 17a6defe..d16f612e 100644 --- a/KSFramework/Assets/SLua/Meta/Resources/lua3rdmeta.asset.meta +++ b/KSFramework/Assets/SLua/Meta/Resources/lua3rdmeta.asset.meta @@ -1,4 +1,8 @@ fileFormatVersion: 2 guid: 6654e56324095d144b28a67f5c8eb8ed +timeCreated: 1472434494 +licenseType: Pro NativeFormatImporter: userData: + assetBundleName: + assetBundleVariant: diff --git a/KSFramework/Assets/SLua/Resources/setting.asset.meta b/KSFramework/Assets/SLua/Resources/setting.asset.meta index 5f08ac0b..fe7540f4 100644 --- a/KSFramework/Assets/SLua/Resources/setting.asset.meta +++ b/KSFramework/Assets/SLua/Resources/setting.asset.meta @@ -1,4 +1,8 @@ fileFormatVersion: 2 guid: b5c884e4d5dc9734f90542d2f8528552 +timeCreated: 1472434494 +licenseType: Pro NativeFormatImporter: userData: + assetBundleName: + assetBundleVariant: diff --git a/KSFramework/Product/Bundles/Android/Android b/KSFramework/Product/Bundles/Android/Android index 5a2d1e3c..5978536a 100644 Binary files a/KSFramework/Product/Bundles/Android/Android and b/KSFramework/Product/Bundles/Android/Android differ diff --git a/KSFramework/Product/Bundles/Android/Android.manifest b/KSFramework/Product/Bundles/Android/Android.manifest index e8c657b5..107f38c4 100644 --- a/KSFramework/Product/Bundles/Android/Android.manifest +++ b/KSFramework/Product/Bundles/Android/Android.manifest @@ -1,5 +1,5 @@ ManifestFileVersion: 0 -CRC: 2446659444 +CRC: 3753706042 AssetBundleManifest: AssetBundleInfos: Info_0: diff --git a/KSFramework/Product/Bundles/Android/ui/login.prefab.bytes b/KSFramework/Product/Bundles/Android/ui/login.prefab.bytes index 63a2aa45..7adbae09 100644 Binary files a/KSFramework/Product/Bundles/Android/ui/login.prefab.bytes and b/KSFramework/Product/Bundles/Android/ui/login.prefab.bytes differ diff --git a/KSFramework/Product/Bundles/Android/ui/login.prefab.bytes.manifest b/KSFramework/Product/Bundles/Android/ui/login.prefab.bytes.manifest index 2e012270..b7c97c61 100644 --- a/KSFramework/Product/Bundles/Android/ui/login.prefab.bytes.manifest +++ b/KSFramework/Product/Bundles/Android/ui/login.prefab.bytes.manifest @@ -1,12 +1,12 @@ ManifestFileVersion: 0 -CRC: 3536214961 +CRC: 3377764140 Hashes: AssetFileHash: serializedVersion: 2 - Hash: 430e48f1ae974b3eb059658f473e1ef1 + Hash: fcefb5441617093551ffb0e4bb74c3d9 TypeTreeHash: serializedVersion: 2 - Hash: 9f623385ecb8db163c769a9e9c4f5785 + Hash: e8f198d5b890ae6244c451d26ce1d3ba HashAppended: 0 ClassTypes: - Class: 1 @@ -18,7 +18,7 @@ ClassTypes: - Class: 48 Script: {instanceID: 0} - Class: 114 - Script: {fileID: 11500000, guid: 327bf15252499524ca2de7a67ab4f467, type: 3} + Script: {fileID: 11500000, guid: 0c01f3f0b88b4448ab1ccfa117a1d57e, type: 3} - Class: 114 Script: {fileID: 1392445389, guid: f5f67c52d1564df4a8936ccd202a3bd8, type: 3} - Class: 114 @@ -29,6 +29,8 @@ ClassTypes: Script: {fileID: -765806418, guid: f5f67c52d1564df4a8936ccd202a3bd8, type: 3} - Class: 114 Script: {fileID: 708705254, guid: f5f67c52d1564df4a8936ccd202a3bd8, type: 3} +- Class: 114 + Script: {fileID: 11500000, guid: 938311ed4b5a34590af2bad889d53090, type: 3} - Class: 115 Script: {instanceID: 0} - Class: 128 diff --git a/KSFramework/Product/Bundles/Windows/Windows b/KSFramework/Product/Bundles/Windows/Windows new file mode 100644 index 00000000..2c13289e Binary files /dev/null and b/KSFramework/Product/Bundles/Windows/Windows differ diff --git a/KSFramework/Product/Bundles/Windows/Windows.manifest b/KSFramework/Product/Bundles/Windows/Windows.manifest new file mode 100644 index 00000000..395b6455 --- /dev/null +++ b/KSFramework/Product/Bundles/Windows/Windows.manifest @@ -0,0 +1,7 @@ +ManifestFileVersion: 0 +CRC: 4080580983 +AssetBundleManifest: + AssetBundleInfos: + Info_0: + Name: ui/login.prefab.bytes + Dependencies: {} diff --git a/KSFramework/Product/Bundles/Windows/ui/login.prefab.bytes b/KSFramework/Product/Bundles/Windows/ui/login.prefab.bytes new file mode 100644 index 00000000..ffdb8d09 Binary files /dev/null and b/KSFramework/Product/Bundles/Windows/ui/login.prefab.bytes differ diff --git a/KSFramework/Product/Bundles/Windows/ui/login.prefab.bytes.manifest b/KSFramework/Product/Bundles/Windows/ui/login.prefab.bytes.manifest new file mode 100644 index 00000000..deadcb3c --- /dev/null +++ b/KSFramework/Product/Bundles/Windows/ui/login.prefab.bytes.manifest @@ -0,0 +1,48 @@ +ManifestFileVersion: 0 +CRC: 3463925110 +Hashes: + AssetFileHash: + serializedVersion: 2 + Hash: 373b99e9bc4e5dde370af57bcdbbb68d + TypeTreeHash: + serializedVersion: 2 + Hash: e8f198d5b890ae6244c451d26ce1d3ba +HashAppended: 0 +ClassTypes: +- Class: 1 + Script: {instanceID: 0} +- Class: 21 + Script: {instanceID: 0} +- Class: 28 + Script: {instanceID: 0} +- Class: 48 + Script: {instanceID: 0} +- Class: 114 + Script: {fileID: 11500000, guid: 0c01f3f0b88b4448ab1ccfa117a1d57e, type: 3} +- Class: 114 + Script: {fileID: 1392445389, guid: f5f67c52d1564df4a8936ccd202a3bd8, type: 3} +- Class: 114 + Script: {fileID: 1980459831, guid: f5f67c52d1564df4a8936ccd202a3bd8, type: 3} +- Class: 114 + Script: {fileID: 1301386320, guid: f5f67c52d1564df4a8936ccd202a3bd8, type: 3} +- Class: 114 + Script: {fileID: -765806418, guid: f5f67c52d1564df4a8936ccd202a3bd8, type: 3} +- Class: 114 + Script: {fileID: 708705254, guid: f5f67c52d1564df4a8936ccd202a3bd8, type: 3} +- Class: 114 + Script: {fileID: 11500000, guid: 938311ed4b5a34590af2bad889d53090, type: 3} +- Class: 115 + Script: {instanceID: 0} +- Class: 128 + Script: {instanceID: 0} +- Class: 213 + Script: {instanceID: 0} +- Class: 222 + Script: {instanceID: 0} +- Class: 223 + Script: {instanceID: 0} +- Class: 224 + Script: {instanceID: 0} +Assets: +- Assets/BundleResources/UI/Login.prefab +Dependencies: [] diff --git a/KSFramework/Product/Bundles/iOS/iOS b/KSFramework/Product/Bundles/iOS/iOS index 12f6ba6d..a789f668 100644 Binary files a/KSFramework/Product/Bundles/iOS/iOS and b/KSFramework/Product/Bundles/iOS/iOS differ diff --git a/KSFramework/Product/Bundles/iOS/iOS.manifest b/KSFramework/Product/Bundles/iOS/iOS.manifest index 75323b00..0f9bb94a 100644 --- a/KSFramework/Product/Bundles/iOS/iOS.manifest +++ b/KSFramework/Product/Bundles/iOS/iOS.manifest @@ -1,5 +1,5 @@ ManifestFileVersion: 0 -CRC: 3870322611 +CRC: 1093111308 AssetBundleManifest: AssetBundleInfos: Info_0: diff --git a/KSFramework/Product/Bundles/iOS/ui/login.prefab.bytes b/KSFramework/Product/Bundles/iOS/ui/login.prefab.bytes index 3c1f6721..4bdc83cf 100644 Binary files a/KSFramework/Product/Bundles/iOS/ui/login.prefab.bytes and b/KSFramework/Product/Bundles/iOS/ui/login.prefab.bytes differ diff --git a/KSFramework/Product/Bundles/iOS/ui/login.prefab.bytes.manifest b/KSFramework/Product/Bundles/iOS/ui/login.prefab.bytes.manifest index 1cf8f1dd..5f510c7e 100644 --- a/KSFramework/Product/Bundles/iOS/ui/login.prefab.bytes.manifest +++ b/KSFramework/Product/Bundles/iOS/ui/login.prefab.bytes.manifest @@ -1,12 +1,12 @@ ManifestFileVersion: 0 -CRC: 1202010467 +CRC: 1965533871 Hashes: AssetFileHash: serializedVersion: 2 - Hash: 55966069e75e2cd4780c9199b6197ad5 + Hash: 8055d4658fb71c44e98f5de70004f7c8 TypeTreeHash: serializedVersion: 2 - Hash: 9f623385ecb8db163c769a9e9c4f5785 + Hash: e8f198d5b890ae6244c451d26ce1d3ba HashAppended: 0 ClassTypes: - Class: 1 @@ -18,7 +18,7 @@ ClassTypes: - Class: 48 Script: {instanceID: 0} - Class: 114 - Script: {fileID: 11500000, guid: 327bf15252499524ca2de7a67ab4f467, type: 3} + Script: {fileID: 11500000, guid: 0c01f3f0b88b4448ab1ccfa117a1d57e, type: 3} - Class: 114 Script: {fileID: 1392445389, guid: f5f67c52d1564df4a8936ccd202a3bd8, type: 3} - Class: 114 @@ -29,6 +29,8 @@ ClassTypes: Script: {fileID: -765806418, guid: f5f67c52d1564df4a8936ccd202a3bd8, type: 3} - Class: 114 Script: {fileID: 708705254, guid: f5f67c52d1564df4a8936ccd202a3bd8, type: 3} +- Class: 114 + Script: {fileID: 11500000, guid: 938311ed4b5a34590af2bad889d53090, type: 3} - Class: 115 Script: {instanceID: 0} - Class: 128 diff --git a/KSFramework/Product/Lua/Init.lua b/KSFramework/Product/Lua/Init.lua index 04bc6689..ebbc7e9b 100644 --- a/KSFramework/Product/Lua/Init.lua +++ b/KSFramework/Product/Lua/Init.lua @@ -16,9 +16,7 @@ end -- simple new table to a object function new(table, ctorFunc) - if not table then - assert(table ~= nil) - end + assert(table ~= nil) table.__index = table diff --git a/KSFramework/Product/Lua/UI/UIBillboard.lua.demo b/KSFramework/Product/Lua/UI/Billboard/UIBillboard.lua.demo similarity index 95% rename from KSFramework/Product/Lua/UI/UIBillboard.lua.demo rename to KSFramework/Product/Lua/UI/Billboard/UIBillboard.lua.demo index c8e5f107..b0fc2e0f 100644 --- a/KSFramework/Product/Lua/UI/UIBillboard.lua.demo +++ b/KSFramework/Product/Lua/UI/Billboard/UIBillboard.lua.demo @@ -1,4 +1,4 @@ -local UIBase = import("KSFramework/UIBase") +local UIBase = import("UI/UIBase") --if not Cookie then -- Cookie = Slua.GetClass('KSFramework.Cookie') --end diff --git a/KSFramework/Product/Lua/UI/UILogin.lua b/KSFramework/Product/Lua/UI/Login/Login.lua similarity index 87% rename from KSFramework/Product/Lua/UI/UILogin.lua rename to KSFramework/Product/Lua/UI/Login/Login.lua index d5c253fc..38a3790a 100644 --- a/KSFramework/Product/Lua/UI/UILogin.lua +++ b/KSFramework/Product/Lua/UI/Login/Login.lua @@ -1,4 +1,4 @@ -local UIBase = import("KSFramework/UIBase") +local UIBase = import("UI/UIBase") if not Cookie then Cookie = Slua.GetClass('KSFramework.Cookie') @@ -28,12 +28,13 @@ function UILogin:OnInit(controller) Log.Info("================================ UILogin:OnInit ============================") - local text = self:GetUIText("Login") - text.text = I18N.Str("UILogin.LoginDescText") + --local text = self:GetUIText("Login") + --text.text = I18N.Str("UILogin.LoginDescText") + -- read LoginText from Outlet + self.LoginText.text = I18N.Str("UILogin.LoginDescText") - local btn = self:GetUIButton("Button") - local btnText = self:GetUIText('Button/Text') - btnText.text = I18N.Str('UILogin.LoginButtonText') + self.LoginButtonText.text = I18N.Str('UILogin.LoginButtonText') + local btn = self.LoginButton print(string.format("Controller type: %s, Button type full name: %s", type(self.Controller), btn:GetType().FullName)) diff --git a/KSFramework/Product/Lua/KSFramework/UIBase.lua b/KSFramework/Product/Lua/UI/UIBase.lua similarity index 100% rename from KSFramework/Product/Lua/KSFramework/UIBase.lua rename to KSFramework/Product/Lua/UI/UIBase.lua diff --git a/KSFramework/Product/SettingSource/I18N/en_US.xlsx b/KSFramework/Product/SettingSource/I18N/en_US.xls similarity index 99% rename from KSFramework/Product/SettingSource/I18N/en_US.xlsx rename to KSFramework/Product/SettingSource/I18N/en_US.xls index ab37d270..3a4bcb5a 100644 Binary files a/KSFramework/Product/SettingSource/I18N/en_US.xlsx and b/KSFramework/Product/SettingSource/I18N/en_US.xls differ diff --git a/KSFramework/Product/SettingSource/I18N/zh_CN.xlsx b/KSFramework/Product/SettingSource/I18N/zh_CN.xls similarity index 99% rename from KSFramework/Product/SettingSource/I18N/zh_CN.xlsx rename to KSFramework/Product/SettingSource/I18N/zh_CN.xls index adf01e64..664c7335 100644 Binary files a/KSFramework/Product/SettingSource/I18N/zh_CN.xlsx and b/KSFramework/Product/SettingSource/I18N/zh_CN.xls differ diff --git a/KSFramework/ProjectSettings/GraphicsSettings.asset b/KSFramework/ProjectSettings/GraphicsSettings.asset index 12771120..057c661a 100644 --- a/KSFramework/ProjectSettings/GraphicsSettings.asset +++ b/KSFramework/ProjectSettings/GraphicsSettings.asset @@ -39,20 +39,20 @@ GraphicsSettings: m_SpritesDefaultMaterial: {fileID: 10754, guid: 0000000000000000f000000000000000, type: 0} m_ShaderSettings_Tier1: - useCascadedShadowMaps: 0 - standardShaderQuality: 0 - useReflectionProbeBoxProjection: 0 - useReflectionProbeBlending: 0 + useCascadedShadowMaps: 1 + standardShaderQuality: 2 + useReflectionProbeBoxProjection: 1 + useReflectionProbeBlending: 1 m_ShaderSettings_Tier2: - useCascadedShadowMaps: 0 - standardShaderQuality: 1 - useReflectionProbeBoxProjection: 0 - useReflectionProbeBlending: 0 + useCascadedShadowMaps: 1 + standardShaderQuality: 2 + useReflectionProbeBoxProjection: 1 + useReflectionProbeBlending: 1 m_ShaderSettings_Tier3: - useCascadedShadowMaps: 0 - standardShaderQuality: 1 - useReflectionProbeBoxProjection: 0 - useReflectionProbeBlending: 0 + useCascadedShadowMaps: 1 + standardShaderQuality: 2 + useReflectionProbeBoxProjection: 1 + useReflectionProbeBlending: 1 m_BuildTargetShaderSettings: [] m_LightmapStripping: 0 m_FogStripping: 0 diff --git a/appveyor.yml b/appveyor.yml index d588aa0c..eeedd2a1 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,4 +1,4 @@ -version: 0.9.{build} +version: 0.11.{build} os: Windows Server 2012 R2 artifacts: - path: KSFramework-$(appveyor_build_version).zip diff --git a/slua b/slua index 28181187..4be05d74 160000 --- a/slua +++ b/slua @@ -1 +1 @@ -Subproject commit 28181187f13a5624f5d2c2a0e764688862dfd5ae +Subproject commit 4be05d744ca93ce4ca7d45d9502783a0a41dd2c4