Skip to content

Commit

Permalink
更新tolua#到1.0.7.380版
Browse files Browse the repository at this point in the history
  • Loading branch information
jarjin2000 committed Nov 5, 2017
1 parent 441aaae commit fa4c848
Show file tree
Hide file tree
Showing 12 changed files with 80 additions and 41 deletions.
3 changes: 3 additions & 0 deletions Assets/LuaFramework/Lua/Main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ end
function OnLevelWasLoaded(level)
collectgarbage("collect")
Time.timeSinceLevelLoad = 0
end

function OnApplicationQuit()
end
2 changes: 1 addition & 1 deletion Assets/LuaFramework/ToLua/Core/LuaDLL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public string short_src

public class LuaDLL
{
public static string version = "1.0.7.364";
public static string version = "1.0.7.377";
public static int LUA_MULTRET = -1;
public static string[] LuaTypeName = { "none", "nil", "boolean", "lightuserdata", "number", "string", "table", "function", "userdata", "thread" };

Expand Down
3 changes: 2 additions & 1 deletion Assets/LuaFramework/ToLua/Core/LuaFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ public R1 Invoke<R1>()
}

//慎用, 有gc alloc
[System.Obsolete("LuaFunction.LazyCall() is obsolete.Use LuaFunction.Invoke()")]
public object[] LazyCall(params object[] args)
{
BeginPCall();
Expand All @@ -375,7 +376,7 @@ public object[] LazyCall(params object[] args)
EndPCall();
throw new LuaException("stack overflow");
}

PushArgs(args);
PCall();
object[] objs = luaState.CheckObjects(oldTop);
Expand Down
78 changes: 56 additions & 22 deletions Assets/LuaFramework/ToLua/Core/LuaState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ public T DoString<T>(string chunk, string chunkName = "LuaState.cs")
return LuaLoadBuffer<T>(buffer, chunkName);
}

public void DoFile(string fileName)
byte[] LoadFileBuffer(string fileName)
{
#if UNITY_EDITOR
if (!beStart)
Expand All @@ -596,36 +596,30 @@ public void DoFile(string fileName)
throw new LuaException(error);
}

return buffer;
}

string LuaChunkName(string name)
{
if (LuaConst.openLuaDebugger)
{
fileName = LuaFileUtils.Instance.FindFile(fileName);
name = LuaFileUtils.Instance.FindFile(name);
}

return "@" + name;
}

public void DoFile(string fileName)
{
byte[] buffer = LoadFileBuffer(fileName);
fileName = LuaChunkName(fileName);
LuaLoadBuffer(buffer, fileName);
}

public T DoFile<T>(string fileName)
{
#if UNITY_EDITOR
if (!beStart)
{
throw new LuaException("you must call Start() first to initialize LuaState");
}
#endif
byte[] buffer = LuaFileUtils.Instance.ReadFile(fileName);

if (buffer == null)
{
string error = string.Format("cannot open {0}: No such file or directory", fileName);
error += LuaFileUtils.Instance.FindFileError(fileName);
throw new LuaException(error);
}

if (LuaConst.openLuaDebugger)
{
fileName = LuaFileUtils.Instance.FindFile(fileName);
}

byte[] buffer = LoadFileBuffer(fileName);
fileName = LuaChunkName(fileName);
return LuaLoadBuffer<T>(buffer, fileName);
}

Expand Down Expand Up @@ -1807,6 +1801,46 @@ public void RefreshDelegateMap()
}
}

public void NewTable(string fullPath)
{
string[] path = fullPath.Split(new char[] { '.' });
int oldTop = LuaDLL.lua_gettop(L);

if (path.Length == 1)
{
LuaDLL.lua_newtable(L);
LuaDLL.lua_setglobal(L, fullPath);
}
else
{
LuaDLL.lua_getglobal(L, path[0]);

for (int i = 1; i < path.Length - 1; i++)
{
LuaDLL.lua_pushstring(L, path[i]);
LuaDLL.lua_gettable(L, -2);
}

LuaDLL.lua_pushstring(L, path[path.Length - 1]);
LuaDLL.lua_newtable(L);
LuaDLL.lua_settable(L, -3);
}

LuaDLL.lua_settop(L, oldTop);
}


public LuaTable NewTable(int narr = 0, int nrec = 0)
{
int oldTop = LuaDLL.lua_gettop(L);

LuaDLL.lua_createtable(L, 0, 0);
LuaTable table = ToLua.ToLuaTable(L, oldTop + 1);

LuaDLL.lua_settop(L, oldTop);
return table;
}

//慎用
public void ReLoad(string moduleFileName)
{
Expand Down
2 changes: 1 addition & 1 deletion Assets/LuaFramework/ToLua/Core/LuaStatePtr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ public int LuaTypeError(int stackPos, string tname, string t2 = null)
return LuaDLL.luaL_typerror(L, stackPos, tname, t2);
}

public bool LuaDoString(string chunk, string chunkName = "LuaStatePtr.cs")
public bool LuaDoString(string chunk, string chunkName = "@LuaStatePtr.cs")
{
byte[] buffer = Encoding.UTF8.GetBytes(chunk);
int status = LuaDLL.luaL_loadbuffer(L, buffer, buffer.Length, chunkName);
Expand Down
11 changes: 6 additions & 5 deletions Assets/LuaFramework/ToLua/Core/ToLua.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static class ToLua

#if UNITY_EDITOR
static int _instanceID = -1;
static int _line = 200;
static int _line = 201;
private static object consoleWindow;
private static object logListView;
private static FieldInfo logListViewCurrentRow;
Expand Down Expand Up @@ -155,14 +155,15 @@ static int Print(IntPtr L)
int line = LuaDLL.tolua_where(L, 1);
string filename = LuaDLL.lua_tostring(L, -1);
LuaDLL.lua_settop(L, n);
int offset = filename[0] == '@' ? 1 : 0;

if (!filename.Contains("."))
{
sb.Append('[').Append(filename).Append(".lua:").Append(line).Append("]:");
sb.Append('[').Append(filename, offset, filename.Length - offset).Append(".lua:").Append(line).Append("]:");
}
else
{
sb.Append('[').Append(filename).Append(':').Append(line).Append("]:");
sb.Append('[').Append(filename, offset, filename.Length - offset).Append(':').Append(line).Append("]:");
}
#endif

Expand Down Expand Up @@ -226,9 +227,9 @@ static int Loader(IntPtr L)
if (LuaConst.openLuaDebugger)
{
fileName = LuaFileUtils.Instance.FindFile(fileName);
}
}

if (LuaDLL.luaL_loadbuffer(L, buffer, buffer.Length, fileName) != 0)
if (LuaDLL.luaL_loadbuffer(L, buffer, buffer.Length, "@"+ fileName) != 0)
{
string err = LuaDLL.lua_tostring(L, -1);
throw new LuaException(err, LuaException.GetLastError());
Expand Down
1 change: 1 addition & 0 deletions Assets/LuaFramework/ToLua/Editor/ToLuaExport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1444,6 +1444,7 @@ static void GenFunction(_MethodBase m)
if (!haveParams)
{
int count = paramInfos.Length + offset;
if (m.Name == "op_UnaryNegation") count = 2;
sb.AppendFormat("\t\t\tToLua.CheckArgsCount(L, {0});\r\n", count);
}
else
Expand Down
6 changes: 2 additions & 4 deletions Assets/LuaFramework/ToLua/Lua/event.lua
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,8 @@ _event.__call = function(self, ...)
self.current = i
local flag, msg = f(...)

if not flag then
if self.keepSafe then
_list:remove(i)
end
if not flag then
_list:remove(i)
self.lock = false
error(msg)
end
Expand Down
7 changes: 4 additions & 3 deletions Assets/LuaFramework/ToLua/Misc/LuaClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public void OpenZbsDebugger(string ip = "localhost")
luaState.AddSearchPath(LuaConst.zbsDir);
}

luaState.LuaDoString(string.Format("DebugServerIp = '{0}'", ip));
luaState.LuaDoString(string.Format("DebugServerIp = '{0}'", ip), "@LuaClient.cs");
}

[MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
Expand Down Expand Up @@ -216,8 +216,9 @@ public virtual void Destroy()
if (luaState != null)
{
#if UNITY_5_4_OR_NEWER
SceneManager.sceneLoaded -= OnSceneLoaded;
SceneManager.sceneLoaded -= OnSceneLoaded;
#endif
luaState.Call("OnApplicationQuit", false);
LuaState state = luaState;
luaState = null;

Expand All @@ -233,7 +234,7 @@ public virtual void Destroy()
loop = null;
}

state.Dispose();
state.Dispose();
Instance = null;
}
}
Expand Down
2 changes: 1 addition & 1 deletion Assets/LuaFramework/ToLua/Misc/LuaCoroutine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public static void Register(LuaState state, MonoBehaviour behaviour)
state.RegFunction("StopCoroutine", StopCoroutine);
state.EndModule();

state.LuaDoString(strCo, "LuaCoroutine.cs");
state.LuaDoString(strCo, "@LuaCoroutine.cs");
mb = behaviour;
}

Expand Down
3 changes: 0 additions & 3 deletions Assets/LuaFramework/ToLua/Source/Generate/DelegateFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ public static void Init()
public static void Register()
{
dict.Clear();



}

public static Delegate CreateDelegate(Type t, LuaFunction func = null)
Expand Down
3 changes: 3 additions & 0 deletions ReadMe.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ XlsxToLua: https://github.com/zhangqi-ulua/XlsxToLua
UnityHello: https://github.com/woshihuo12/UnityHello
Excel配置:https://github.com/sy-yanghuan/proton

//-------------2017-11-05-------------
(1)更新tolua#到1.0.7.380版

//-------------2017-09-20-------------
(1)LuaManager初始化加入委托初始化

Expand Down

0 comments on commit fa4c848

Please sign in to comment.