diff --git a/Assets/Plugins/Slua_Managed/Logger.cs b/Assets/Plugins/Slua_Managed/Logger.cs index 11ba6c8e..b5eccf18 100644 --- a/Assets/Plugins/Slua_Managed/Logger.cs +++ b/Assets/Plugins/Slua_Managed/Logger.cs @@ -37,68 +37,6 @@ public enum Level Error } public static Action LogAction; -#if !SLUA_STANDALONE - private static UnityEngine.Object FindScriptByMsg(string msg) - { -#if UNITY_EDITOR - string[] lines = msg.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None); - for (int i = 2; i < lines.Length; i++) - { - int idx = lines[i].IndexOf(":"); - if (idx < 0) continue; - string filename = lines[i].Substring(0, idx); - idx = filename.LastIndexOf("/"); - if (idx >= 0) filename = filename.Substring(idx + 1); - filename = filename.Trim(); - string[] guids = UnityEditor.AssetDatabase.FindAssets(filename); - filename = filename + ".txt"; - for (int j = 0; j < guids.Length; j++) - { - string path = UnityEditor.AssetDatabase.GUIDToAssetPath(guids[j]); - if (System.IO.Path.GetFileName(path).Equals(filename)) - { -#if UNITY_5 - return UnityEditor.AssetDatabase.LoadAssetAtPath(path); -#else - return UnityEditor.AssetDatabase.LoadAssetAtPath(path,typeof(UnityEngine.Object)); -#endif - } - } - } -#endif - return null; - } -#endif - - #if !SLUA_STANDALONE - static void Traceback(string msg, bool hasStacktrace = false) - { - #if UNITY_5 - var Type = UnityEngine.Application.GetStackTraceLogType (UnityEngine.LogType.Log); - UnityEngine.Application.SetStackTraceLogType (UnityEngine.LogType.Log, UnityEngine.StackTraceLogType.None); - UnityEngine.Debug.Log (msg, hasStacktrace ? FindScriptByMsg (msg) : null); - UnityEngine.Application.SetStackTraceLogType (UnityEngine.LogType.Log, Type); - #else - UnityEngine.Debug.Log(msg); - #endif - } - - static void TracebackErr(string msg, bool hasStacktrace = false) - { -#if UNITY_5 - var Type = UnityEngine.Application.GetStackTraceLogType (UnityEngine.LogType.Error); - UnityEngine.Application.SetStackTraceLogType (UnityEngine.LogType.Error, UnityEngine.StackTraceLogType.None); - UnityEngine.Debug.LogError (msg, hasStacktrace ? FindScriptByMsg (msg) : null); - UnityEngine.Application.SetStackTraceLogType (UnityEngine.LogType.Error, Type); -#else - UnityEngine.Debug.LogError(msg); - #endif - } - - - #endif - - public static void Log(string msg, bool hasStacktrace = false) { @@ -109,10 +47,10 @@ public static void Log(string msg, bool hasStacktrace = false) } #if !SLUA_STANDALONE - Traceback(msg,hasStacktrace); + UnityEngine.Debug.Log(msg); #else Console.WriteLine(msg); -#endif +#endif } public static void LogError(string msg, bool hasStacktrace = false) { @@ -123,7 +61,7 @@ public static void LogError(string msg, bool hasStacktrace = false) } #if !SLUA_STANDALONE - TracebackErr(msg,hasStacktrace); + UnityEngine.Debug.LogError(msg); #else Console.WriteLine(msg); #endif diff --git a/Assets/Plugins/Slua_Managed/LuaDLL.cs b/Assets/Plugins/Slua_Managed/LuaDLL.cs index 7e846cb6..f4a7d4ed 100644 --- a/Assets/Plugins/Slua_Managed/LuaDLL.cs +++ b/Assets/Plugins/Slua_Managed/LuaDLL.cs @@ -258,8 +258,8 @@ public static int lua_rawlen(IntPtr luaState, int stackPos) [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); +// [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) { @@ -268,7 +268,7 @@ public static int lua_call(IntPtr luaState, int nArgs, int nResults) public static int lua_pcall(IntPtr luaState, int nArgs, int nResults, int errfunc) { - return luaS_pcall(luaState, nArgs, nResults, errfunc); + return lua_pcallk(luaState, nArgs, nResults, errfunc, 0, IntPtr.Zero); } [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] diff --git a/Assets/Plugins/Slua_Managed/LuaState.cs b/Assets/Plugins/Slua_Managed/LuaState.cs index 48badcef..dd4743cd 100644 --- a/Assets/Plugins/Slua_Managed/LuaState.cs +++ b/Assets/Plugins/Slua_Managed/LuaState.cs @@ -583,7 +583,6 @@ public void openExtLib() public void bindUnity() { - if (!openedSluaLib) openSluaLib(); @@ -593,6 +592,9 @@ public void bindUnity() public IEnumerator bindUnity(Action _tick, Action complete) { + if (!openedSluaLib) + openSluaLib(); + yield return LuaSvr.doBind(L, _tick, complete); LuaValueType.reg(L); } @@ -764,8 +766,8 @@ static int init(IntPtr L) LuaDLL.lua_pushcfunction(L, warn); LuaDLL.lua_setglobal(L, "warn"); - LuaDLL.lua_pushcfunction(L, pcall); - LuaDLL.lua_setglobal(L, "pcall"); +// LuaDLL.lua_pushcfunction(L, pcall); +// LuaDLL.lua_setglobal(L, "pcall"); pushcsfunction(L, import); LuaDLL.lua_setglobal(L, "import"); @@ -987,20 +989,19 @@ internal static int import(IntPtr l) } } - [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 */ - } +// [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"); +// } +// 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) { diff --git a/Assets/Plugins/x64/slua.dll b/Assets/Plugins/x64/slua.dll index 2112d86a..300100b0 100644 Binary files a/Assets/Plugins/x64/slua.dll and b/Assets/Plugins/x64/slua.dll differ diff --git a/Assets/Plugins/x86/slua.dll b/Assets/Plugins/x86/slua.dll index b9899742..9a120f10 100644 Binary files a/Assets/Plugins/x86/slua.dll and b/Assets/Plugins/x86/slua.dll differ diff --git a/Assets/Slua/Editor/LoggerHelper.cs b/Assets/Slua/Editor/LoggerHelper.cs new file mode 100644 index 00000000..bf503414 --- /dev/null +++ b/Assets/Slua/Editor/LoggerHelper.cs @@ -0,0 +1,66 @@ +using System; +using System.Reflection; +using System.Text.RegularExpressions; +using UnityEditor; + +namespace SLua +{ + public static class LoggerHelper + { + static Regex rgx = new Regex(@"(\s|/)(?\w+):(?\d+):", RegexOptions.IgnoreCase); + static char[] LineEndings = new char[2] { '\n', '\r' }; + + [UnityEditor.Callbacks.OnOpenAsset(0)] + static bool OnOpenAsset(int instanceID, int line) + { + var instance = EditorUtility.InstanceIDToObject(instanceID) as MonoScript; + if (instance == null || instance.GetClass() != typeof(SLua.Logger)) + return false; + + var stacktrace = GetStackTrace(); + if (string.IsNullOrEmpty(stacktrace)) + return false; + + string[] lines = stacktrace.Split(LineEndings, StringSplitOptions.RemoveEmptyEntries); + for (int i = 3; i < lines.Length; i++) + { + var match = rgx.Match(lines[i]); + if (!match.Success) + continue; + var filename = match.Groups["File"].Value; + int linenumber = 0; + int.TryParse(match.Groups["Line"].Value, out linenumber); + + string[] guids = AssetDatabase.FindAssets(filename); + filename = filename + ".txt"; + for (int j = 0; j < guids.Length; j++) + { + string path = AssetDatabase.GUIDToAssetPath(guids[j]); + if (System.IO.Path.GetFileName(path).Equals(filename)) + { + UnityEditorInternal.InternalEditorUtility.OpenFileAtLineExternal(path, linenumber); + return true; + } + } + } + return false; + } + + static Type ConsoleWindowType = typeof(EditorWindow).Assembly.GetType("UnityEditor.ConsoleWindow"); + static Type ListViewStateType = typeof(EditorWindow).Assembly.GetType("UnityEditor.ListViewState"); + static FieldInfo ConsoleWindowField = ConsoleWindowType.GetField("ms_ConsoleWindow", BindingFlags.Static | BindingFlags.NonPublic); + static FieldInfo ListViewField = ConsoleWindowType.GetField("m_ListView", BindingFlags.Instance | BindingFlags.NonPublic); + static FieldInfo RowField = ListViewStateType.GetField("row", BindingFlags.Instance | BindingFlags.Public); + static FieldInfo ActiveTextField = ConsoleWindowType.GetField("m_ActiveText", BindingFlags.Instance | BindingFlags.NonPublic); + static string GetStackTrace() + { + var instance = ConsoleWindowField.GetValue(null); + if (instance == null) + return null; + + var listView = ListViewField.GetValue(instance); + int row = (int)RowField.GetValue(listView); + return (string)ActiveTextField.GetValue(instance); + } + } +} \ No newline at end of file diff --git a/Assets/Slua/Editor/LoggerHelper.cs.meta b/Assets/Slua/Editor/LoggerHelper.cs.meta new file mode 100644 index 00000000..fbaf8f56 --- /dev/null +++ b/Assets/Slua/Editor/LoggerHelper.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 53d88b07eb4ca4f4da74c0642fdbaeef +timeCreated: 1513933133 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Slua/Editor/LuaCodeGen.cs b/Assets/Slua/Editor/LuaCodeGen.cs index b94464d5..49737960 100644 --- a/Assets/Slua/Editor/LuaCodeGen.cs +++ b/Assets/Slua/Editor/LuaCodeGen.cs @@ -115,6 +115,8 @@ static void Update() public static string[] unityModule = new string[] { "UnityEngine","UnityEngine.CoreModule","UnityEngine.UIModule","UnityEngine.TextRenderingModule","UnityEngine.TextRenderingModule", "UnityEngine.UnityWebRequestWWWModule","UnityEngine.Physics2DModule","UnityEngine.AnimationModule","UnityEngine.TextRenderingModule","UnityEngine.IMGUIModule","UnityEngine.UnityWebRequestModule", "UnityEngine.PhysicsModule", "UnityEngine.UI" }; +#else + public static string[] unityModule = null; #endif [MenuItem("SLua/All/Make")] diff --git a/Assets/Slua/Editor/ModuleSelector.cs b/Assets/Slua/Editor/ModuleSelector.cs index 2b133075..b3f5b256 100644 --- a/Assets/Slua/Editor/ModuleSelector.cs +++ b/Assets/Slua/Editor/ModuleSelector.cs @@ -1,3 +1,25 @@ +// The MIT License (MIT) + +// Copyright 2015 Siney/Pangweiwei siney@yeah.net / jiangzhhhh jiangzhhhh@gmail.com +// +// 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 UnityEngine; using UnityEditor; using System; diff --git a/build/make_ios.sh b/build/make_ios.sh index 0dcb3e82..eec0fb32 100755 --- a/build/make_ios.sh +++ b/build/make_ios.sh @@ -42,7 +42,7 @@ make HOST_CC="gcc -std=c99" CROSS="$ISDKP" TARGET_FLAGS="$ISDKF" TARGET=arm64 TA # add simulator support ISDK=$IXCODE/Platforms/iPhoneSimulator.platform/Developer ISDKVER=iPhoneSimulator.sdk -set development target to 8.0 +# set development target to 9.0 DEVTAR=9.0 ISDKP=/usr/bin/ diff --git a/build/make_win.bat b/build/make_win.bat deleted file mode 100644 index 6830c490..00000000 --- a/build/make_win.bat +++ /dev/null @@ -1,85 +0,0 @@ -@echo off - -:: lua paths define -set LUAJIT_PATH=luajit-2.1.0-beta3 -set STANDARD_LUA_PATH=lua-5.1.5 - -:: deciding whether to use luajit or not -:: set USE_STANDARD_LUA=%1% -set USE_LUA_PATH=%LUAJIT_PATH% -:: if "%USE_STANDARD_LUA%"=="YES" (set USE_LUA_PATH=%STANDARD_LUA_PATH%) - -:: get visual studio tools path -:check2015 -if exist "%VS130COMNTOOLS%" ( - set VS_TOOL_VER=vs130 - set VCVARS="%VS130COMNTOOLS%..\..\VC\bin\" - goto build -) -:check2013 -if exist "%VS120COMNTOOLS%" ( - set VS_TOOL_VER=vs120 - set VCVARS="%VS120COMNTOOLS%..\..\VC\bin\" - goto build -) -:check2012 -if exist "%VS110COMNTOOLS%" ( - set VS_TOOL_VER=vs110 - set VCVARS="%VS110COMNTOOLS%..\..\VC\bin\" - goto build -) -:check2010 -if exist "%VS100COMNTOOLS%" ( - set VS_TOOL_VER=vs100 - set VCVARS="%VS100COMNTOOLS%..\..\VC\bin\" - goto build -) -:check2008 -if exist "%VS90COMNTOOLS%" ( - set VS_TOOL_VER=vs90 - set VCVARS="%VS90COMNTOOLS%..\..\VC\bin\" - goto build -) -else ( - goto missing -) - -:build -set ENV32="%VCVARS%vcvars32.bat" -set ENV64="%VCVARS%amd64\vcvars64.bat" - -copy /Y slua.c "%USE_LUA_PATH%\src\" -copy /Y luasocket-mini\*.* "%USE_LUA_PATH%\src\" - -call "%ENV32%" -echo Swtich to x86 build env(%VS_TOOL_VER%) -cd %USE_LUA_PATH%\src -call msvcbuild.bat -copy /Y lua51.dll ..\..\..\Assets\Plugins\x86\slua.dll -copy /Y lua51.dll ..\..\..\jit\win\x86\lua51.dll -copy /Y luajit.exe ..\..\..\jit\win\x86\luajit.exe -cd ..\.. - -call "%ENV64%" -echo Swtich to x64 build env(%VS_TOOL_VER%) -cd %USE_LUA_PATH%\src -call msvcbuild.bat -copy /Y lua51.dll ..\..\..\Assets\Plugins\x64\slua.dll -copy /Y lua51.dll ..\..\..\jit\win\x64\lua51.dll -copy /Y luajit.exe ..\..\..\jit\win\x64\luajit.exe -cd ..\.. - -call "%ENV64%" -echo Swtich to x64 build env(%VS_TOOL_VER%) -cd %USE_LUA_PATH%\src -call msvcbuild.bat gc64 -copy /Y lua51.dll ..\..\..\jit\win\gc64\lua51.dll -copy /Y luajit.exe ..\..\..\jit\win\gc64\luajit.exe -cd ..\.. - -goto :eof - -:missing -echo Can't find Visual Studio, compilation fails! - -goto :eof diff --git a/build/make_win_x64.bat b/build/make_win_x64.bat index e6c9d140..3443ef80 100644 --- a/build/make_win_x64.bat +++ b/build/make_win_x64.bat @@ -54,7 +54,7 @@ copy /Y luasocket-mini\*.* "%USE_LUA_PATH%\src\" call "%ENV64%" echo Swtich to x64 build env(%VS_TOOL_VER%) cd %USE_LUA_PATH%\src -call msvcbuild.bat +call msvcbuild.bat gc64 copy /Y lua51.dll ..\..\..\Assets\Plugins\x64\slua.dll copy /Y lua51.dll ..\..\..\jit\win\x64\lua51.dll copy /Y luajit.exe ..\..\..\jit\win\x64\luajit.exe diff --git a/build/slua.c b/build/slua.c index 20c86b1e..0f091c96 100644 --- a/build/slua.c +++ b/build/slua.c @@ -157,19 +157,19 @@ LUA_API const char* luaS_tolstring32(lua_State *L, int index, int* len) { return ret; } -#if LUA_VERSION_NUM>=503 -static int k(lua_State *L, int status, lua_KContext ctx) { - return status; -} - -LUA_API int luaS_yield(lua_State *L, int nrets) { - return k(L, lua_yieldk(L, nrets, 0, k), 0); -} - -LUA_API int luaS_pcall(lua_State *L, int nargs, int nresults, int err) { - return k(L, lua_pcallk(L, nargs, nresults, err, 0, k), 0); -} -#endif +// #if LUA_VERSION_NUM>=503 +// static int k(lua_State *L, int status, lua_KContext ctx) { +// return status; +// } + +// LUA_API int luaS_yield(lua_State *L, int nrets) { +// return k(L, lua_yieldk(L, nrets, 0, k), 0); +// } + +// LUA_API int luaS_pcall(lua_State *L, int nargs, int nresults, int err) { +// return k(L, lua_pcallk(L, nargs, nresults, err, 0, k), 0); +// } +// #endif diff --git a/jit/win/gc64/lua51.dll b/jit/win/gc64/lua51.dll index a4d944cc..b2863584 100644 Binary files a/jit/win/gc64/lua51.dll and b/jit/win/gc64/lua51.dll differ diff --git a/jit/win/gc64/luajit.exe b/jit/win/gc64/luajit.exe index 649e6a4f..92ae0f19 100644 Binary files a/jit/win/gc64/luajit.exe and b/jit/win/gc64/luajit.exe differ diff --git a/jit/win/x64/lua51.dll b/jit/win/x64/lua51.dll index 2112d86a..300100b0 100644 Binary files a/jit/win/x64/lua51.dll and b/jit/win/x64/lua51.dll differ diff --git a/jit/win/x64/luajit.exe b/jit/win/x64/luajit.exe index 2efc8210..80aa5b67 100644 Binary files a/jit/win/x64/luajit.exe and b/jit/win/x64/luajit.exe differ diff --git a/jit/win/x86/lua51.dll b/jit/win/x86/lua51.dll index b9899742..9a120f10 100644 Binary files a/jit/win/x86/lua51.dll and b/jit/win/x86/lua51.dll differ diff --git a/jit/win/x86/luajit.exe b/jit/win/x86/luajit.exe index c0575e47..f20d6729 100644 Binary files a/jit/win/x86/luajit.exe and b/jit/win/x86/luajit.exe differ diff --git a/tools/premake5_mac b/tools/premake5_mac old mode 100755 new mode 100644