Ejemplo n.º 1
0
        public static IntPtr CheckUData(this LuaState state, int ud, string name)
        {
            IntPtr p = state.ToUserData(ud);

            if (p == IntPtr.Zero)
            {
                return(IntPtr.Zero);
            }
            if (!state.GetMetaTable(ud))
            {
                return(IntPtr.Zero);
            }

            state.GetField(LuaRegistry.Index, name);

            bool isEqual = state.RawEqual(-1, -2);

            state.Pop(2);

            if (isEqual)
            {
                return(p);
            }

            return(IntPtr.Zero);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// <para>Return a debug.traceback() call result (a multi-line string, containing a full stack trace, including C calls.</para>
        /// <para>Note: it won't return anything unless the interpreter is in the middle of execution - that is, it only makes sense to call it from a method called from Lua, or during a coroutine yield.</para>
        /// </summary>
        public string GetDebugTraceback()
        {
            int oldTop = luaState.GetTop();

            luaState.GetGlobal("debug");        // stack: debug
            luaState.GetField(-1, "traceback"); // stack: debug,traceback
            luaState.Remove(-2);                // stack: traceback
            luaState.PCall(0, -1, 0);
            return(translator.PopValues(luaState, oldTop)[0] as string);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Push a debug.traceback reference onto the stack, for a pcall function to use as error handler. (Remember to increment any top-of-stack markers!)
        /// </summary>
        private static int PushDebugTraceback(LuaState luaState, int argCount)
        {
            luaState.GetGlobal("debug");
            luaState.GetField(-1, "traceback");
            luaState.Remove(-2);
            int errindex = -argCount - 2;

            luaState.Insert(errindex);
            return(errindex);
        }