/// <summary> /// expects function on top /// runs function on top of stack, pushes return values, shows traceback in case of errors /// </summary> public static void TraceCallPushReturn(IntPtr L, IResultCount resultCount, params LuaValue[] arguments) { LuaFunction.Check(L, -1); Array.ForEach(arguments, a => a.Push(L)); var constantResults = resultCount as ConstantResults; int results = constantResults != null ? constantResults.Count : Lua.LUA_MULTRET; var baseIndex = Lua.lua_gettop(L) - arguments.Length; // function index new LuaFunction(Traceback).Push(L); // push traceback function Lua.lua_insert(L, baseIndex); // put it under chunk and args var status = Lua.lua_pcall(L, arguments.Length, results, baseIndex); Lua.lua_remove(L, baseIndex); // remove traceback function if (status != 0) { Lua.lua_gc(L, Lua.LUA_GCCOLLECT, 0); // force a complete garbage collection in case of errors CheckError(L, status); } }
/// <summary> /// /// runs a lua chunk loaded from a string, pushes returned values on stack, shows traceback in case of errors /// </summary> public static void DoStringPushReturn(IntPtr L, string s, IResultCount resultCount, params LuaValue[] arguments) { CheckError(L, Lua.luaL_loadstring(L, s)); TraceCallPushReturn(L, resultCount, arguments); }