Beispiel #1
0
        internal int DoTraceback(LuaState state)
        {
            // if err is not a string, just pass it on (the stack is local to the function)
            // I spent a solid hour of debugging non stop only to fix the issue with this one line
            // (the issue was that nlua would throw exception objects and this thing would inappropriately
            // stringify them btw, if you're interested)
            if (!LuaLib.LuaIsString(state, -1))
            {
                return(LuaLib.LuaGetTop(state));
            }

            var error = LuaLib.LuaToString(state, -1);

            LuaLib.LuaPop(state, 1);

            LuaLib.LuaNewTable(state); // t

            LuaLib.LuaPushString(state, "__etgmod_error");
            LuaLib.LuaPushBoolean(state, true);
            LuaLib.LuaSetTable(state, -3);

            LuaLib.LuaPushString(state, "msg");          // k
            LuaLib.LuaPushString(state, error);          // v
            LuaLib.LuaSetTable(state, -3);               // t[k] = v

            LuaLib.LuaPushString(state, "traceback");    // k
            LuaLib.LuaLTraceback(state, state, null, 0); // v
            LuaLib.LuaSetTable(state, -3);               // t[k] = v

            return(1);                                   // t is left
        }