Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/pangweiwei/slua
Browse files Browse the repository at this point in the history
  • Loading branch information
pangweiwei committed Jan 14, 2018
2 parents 8e5814e + 0f935b0 commit 3f1a7d7
Show file tree
Hide file tree
Showing 20 changed files with 141 additions and 185 deletions.
68 changes: 3 additions & 65 deletions Assets/Plugins/Slua_Managed/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,68 +37,6 @@ public enum Level
Error
}
public static Action<Level, string> 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<UnityEngine.Object>(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)
{
Expand All @@ -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)
{
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions Assets/Plugins/Slua_Managed/LuaDLL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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)]
Expand Down
35 changes: 18 additions & 17 deletions Assets/Plugins/Slua_Managed/LuaState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,6 @@ public void openExtLib()

public void bindUnity()
{

if (!openedSluaLib)
openSluaLib();

Expand All @@ -593,6 +592,9 @@ public void bindUnity()

public IEnumerator bindUnity(Action<int> _tick, Action complete)
{
if (!openedSluaLib)
openSluaLib();

yield return LuaSvr.doBind(L, _tick, complete);
LuaValueType.reg(L);
}
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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)
{
Expand Down
Binary file modified Assets/Plugins/x64/slua.dll
Binary file not shown.
Binary file modified Assets/Plugins/x86/slua.dll
Binary file not shown.
66 changes: 66 additions & 0 deletions Assets/Slua/Editor/LoggerHelper.cs
Original file line number Diff line number Diff line change
@@ -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|/)(?<File>\w+):(?<Line>\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);
}
}
}
12 changes: 12 additions & 0 deletions Assets/Slua/Editor/LoggerHelper.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Assets/Slua/Editor/LuaCodeGen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
22 changes: 22 additions & 0 deletions Assets/Slua/Editor/ModuleSelector.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion build/make_ios.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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/

Expand Down
85 changes: 0 additions & 85 deletions build/make_win.bat

This file was deleted.

2 changes: 1 addition & 1 deletion build/make_win_x64.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 3f1a7d7

Please sign in to comment.