public void CallFunc(string field, int nResult, params object[] Args) { IntPtr L = _Interpreter.L; L.GetRef(_Reference); L.GetField(-1, field); L.Replace(-2); if (LuaDLL.lua_type(L, -1) == LuaTypes.LUA_TFUNCTION) { var b = LuaDLL.lua_gettop(L); LuaDLL.lua_pushstdcallcfunction(L, _Interpreter.tracebackFunction); LuaDLL.lua_insert(L, b); int nArg = 0; if (Args != null) { nArg = Args.Length; for (int i = 0; i < Args.Length; ++i) { L.PushAnyObject(Args[i]); } } if (L.PCall(nArg, nResult, b) == LuaThreadStatus.LUA_OK) { L.Remove(b); } else { ULUA.ThrowExceptionFromError(L, b - 1); } } }
public static int loader(IntPtr L) { // Get script to load string fileName = string.Empty; fileName = LuaDLL.lua_tostring(L, 1); //fileName = fileName.Replace('.', '/'); //fileName += ".lua"; string lowerName = fileName.ToLower(); if (lowerName.EndsWith(".lua")) { int index = fileName.LastIndexOf('.'); fileName = fileName.Substring(0, index); } fileName = fileName.Replace('.', '/') + ".lua"; /* * // Load with Unity3D resources * byte[] text = Load(fileName); * * if( text == null ) * { * return 0; * } * LuaDLL.luaL_loadbuffer(L, text, text.Length, fileName); */ //LuaScriptMgr mgr = LuaScriptMgr.GetMgrFromLuaState(L); //if (mgr == null) return 0; LuaDLL.lua_pushstdcallcfunction(L, traceback); int oldTop = LuaDLL.lua_gettop(L); byte[] text = LuaStatic.Load(fileName); if (text == null) { if (!fileName.Contains("mobdebug")) { Debugger.LogError("Loader lua file failed: {0}", fileName); } LuaDLL.lua_pop(L, 1); return(0); } if (LuaDLL.luaL_loadbuffer(L, text, text.Length, fileName) != 0) { ULUA.ThrowExceptionFromError(L, oldTop); LuaDLL.lua_pop(L, 1); } return(1); }