예제 #1
0
        public static LuaFunctionInfo ReadFunctionInfo(LuaState ls, int level)
        {
            IntPtr memBlock = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(LuaDebugRecord)));

            if (BBLua.lua_getstack(ls.L, level, memBlock) == 0)
            {
                return(null);
            }
            BBLua.lua_getinfo(ls.L, "nSlu", memBlock);
            LuaDebugRecord ldr = (LuaDebugRecord)Marshal.PtrToStructure(memBlock, typeof(LuaDebugRecord));

            LuaFunctionInfo lfi = new LuaFunctionInfo(memBlock, ls, ldr.nups);

            if (ldr.source.Length > 1 && ldr.source[0] != '=')
            {
                lfi.Source = ldr.source;
                lfi.Line   = ldr.currentline;
            }
            else
            {
                lfi.Source = "unavailable";
                lfi.Line   = 0;
            }

            if (ldr.what == "C")
            {
                lfi.FunctionName = "Game Engine (direct call)";
            }
            else if (ldr.what == "main")
            {
                lfi.FunctionName = "Game Engine (code outside function)";
            }
            else if (ldr.name != "" && ldr.namewhat != "")
            {
                lfi.FunctionName = ldr.namewhat + " " + ldr.name + "()";
            }
            else if (ldr.what == "Lua" || ldr.what == "tail")
            {
                lfi.FunctionName = "Lua Code";
            }


            if (ls.LoadedFiles.ContainsKey(lfi.Source))
            {
                lfi.CanFakeEnvironment = true;
            }

            return(lfi);
        }
예제 #2
0
        protected string GetTosFunctionInfo()
        {
            IntPtr memBlock = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(LuaDebugRecord)));

            BBLua.lua_getinfo(this.L, ">nSf", memBlock); //fill structure and pop func back onto stack after removing it
            LuaDebugRecord ldr = (LuaDebugRecord)Marshal.PtrToStructure(memBlock, typeof(LuaDebugRecord));

            Marshal.FreeHGlobal(memBlock);

            string source;

            if (ldr.what == "C")
            {
                source = "Game Engine at 0x" + BBLua.lua_tocfunction(this.L, -1).ToInt32().ToString("X");
            }
            else
            {
                source = '\b' + ldr.source + ':' + ldr.linedefined + '\b';//" (line " + ldr.linedefined + ")";
            }
            return("<Function, defined in " + source + ">");
        }