예제 #1
0
 protected void RegisterLogFunction()
 {
     BBLua.lua_pushstring(this.ls.L, "LuaDebugger");
     BBLua.lua_newtable(this.ls.L);
     BBLua.lua_pushstring(this.ls.L, "Log");
     BBLua.lua_pushcclosure(this.ls.L, Marshal.GetFunctionPointerForDelegate(this.logCallback), 0);
     BBLua.lua_rawset(this.ls.L, -3);
     BBLua.lua_rawset(this.ls.L, (int)LuaPseudoIndices.GLOBALSINDEX);
 }
예제 #2
0
        static LuaResult FakePcall(UIntPtr L, int nargs, int nresults, int errfunc)
        {
            if (!GlobalState.CatchErrors)
            {
                return(BBLua.lua_pcall(L, nargs, nresults, errfunc));
            }

            BBLua.lua_pushcclosure(L, ErrorHook.errorHandlerPtr, 0);
            BBLua.lua_insert(L, -nargs - 2);

            LuaResult res;

            if (nresults >= 0)
            {
                res = BBLua.lua_pcall(L, nargs, nresults, -nargs - 2);
            }
            else  //LUA_MULTRET
            {
                int stackBefore = BBLua.lua_gettop(L);
                res = BBLua.lua_pcall(L, nargs, nresults, -nargs - 2);
                int stackNow = BBLua.lua_gettop(L);

                if (res == LuaResult.OK)
                {
                    nresults = stackNow - stackBefore + nargs + 1;
                }
                else
                {
                    nresults = 0;
                }
            }

            if (res != LuaResult.OK)
            {
                BBLua.lua_settop(L, -2);           //remove errormsg

                for (int i = 0; i < nresults; i++) //push dummy returns, hopefully settlers accepts this
                {
                    BBLua.lua_pushnil(L);
                }
            }
            BBLua.lua_remove(L, -nresults - 1); //remove error handler

            return(LuaResult.OK);
        }