public static string StackTrace()
        {
            if (luaInterface == null || luaInterface->state == IntPtr.Zero)
            {
                return("Lua is null");
            }
            if (luaInterface->destroyed)
            {
                return("Lua is destroyed");
            }
            var      sb    = new StringBuilder();
            LuaDebug info  = new LuaDebug();
            int      level = 0;

            while (LuaBindings.lua_getstack(State, level, ref info) != 0)
            {
                LuaBindings.lua_getinfo(State, "nSl", ref info);
                var short_src = Marshal.PtrToStringAnsi(new IntPtr(info.short_src));
                var line      = string.Format("  [{0}] {1}:{2} -- {3} [{4}]",
                                              level, short_src, info.currentline,
                                              (info.name != null ? info.name : "<unknown>"),
                                              info.what);
                sb.AppendLine(line);
                level++;
            }
            return(sb.ToString());
        }
        static void LoadBank(LuaState L)
        {
            int nargs = LuaBindings.lua_gettop(L);
            var path  = LuaBindings.luaL_tolstring(L, 1, IntPtr.Zero);
            var value = LuaBindings.lua_toboolean(L, 2) != 0;

            ExtenderAudioManager.LoadBank(path, value);
        }
Example #3
0
 public void OpenLibraries(LuaState state)
 {
     LuaBindings.luaL_requiref(state, "package", luaopen_package, 1);
     LuaBindingMacros.lua_pop(state, 1);
     LuaBindings.luaL_requiref(state, "io", luaopen_io, 1);
     LuaBindingMacros.lua_pop(state, 1);
     LuaBindings.luaL_requiref(state, "os", luaopen_os, 1);
     LuaBindingMacros.lua_pop(state, 1);
 }
Example #4
0
 private unsafe void CloseLua(LuaInterface *luaInterface)
 {
     Console.WriteLine($"Closing lua.");
     if (luaInterface->destroyed == false)
     {
         LuaBindings.lua_close(luaInterface->state);
         luaInterface->state     = IntPtr.Zero;
         luaInterface->destroyed = true;
         luaInterface->msghander = 0;
     }
 }
        public void TestLog(LuaState L)
        {
            int nargs = LuaBindings.lua_gettop(L);

            for (int i = 1; i <= nargs; ++i)
            {
                var text = LuaBindings.luaL_tolstring(L, i, IntPtr.Zero);
                Console.Write(text);
            }
            Console.WriteLine();
        }
Example #6
0
 public static void OpenLibraries(LuaState state)
 {
     if (state == IntPtr.Zero)
     {
         throw new Exception("Lua state is null");
     }
     LuaBindings.luaL_requiref(state, "package", luaopen_package, 1);
     LuaBindingMacros.lua_pop(state, 1);
     LuaBindings.luaL_requiref(state, "io", luaopen_io, 1);
     LuaBindingMacros.lua_pop(state, 1);
     LuaBindings.luaL_requiref(state, "os", luaopen_os, 1);
     LuaBindingMacros.lua_pop(state, 1);
 }
 public void Update()
 {
     if (DebugEnabled)
     {
         var top = LuaBindings.lua_gettop(State);
         LuaBindings.lua_getglobal(State, "OnExtenderDebugUpdate");
         if (LuaBindingMacros.lua_isfunction(State, -1))
         {
             var result = LuaBindings.lua_pcallk(State, 0, 0, 0, 0, IntPtr.Zero);
         }
         else
         {
             LuaBindings.lua_settop(State, top);
         }
     }
 }
Example #8
0
 private unsafe void OpenLua(LuaInterface *luaInterface, IntPtr l_msghandler, IntPtr l_panic, bool *enableMessageHook)
 {
     Console.WriteLine($"Opening lua. Message hooks enabled={*enableMessageHook}");
     luaInterface->state     = CustomLuaRuntimeManager.luaL_newstate();
     luaInterface->destroyed = false;
     if (!*enableMessageHook)
     {
         LuaBindings.luaL_openlibs(luaInterface->state);
     }
     else
     {
         LuaBindings.lua_pushcclosure(luaInterface->state, l_msghandler, 0);
         var top = LuaBindings.lua_gettop(luaInterface->state);
         luaInterface->msghander = top;
         LuaBindings.lua_atpanic(luaInterface->state, l_panic);
         LuaBindings.luaL_openlibs(luaInterface->state);
         LuaBindings.luaopen_debug(luaInterface->state);
     }
 }
        public void Init()
        {
            Console.WriteLine("Registered TestLog function");
            lua.RegisterFunction <LuaFunc>("TestLog", TestLog);
            Console.WriteLine("Registered TesValue global");
            lua.SetGlobal("TestValue", (double)5);
            if (!CustomLuaRuntime)
            {
#pragma warning disable CS0162 // Unreachable code detected
                LuaHelper.OpenLibraries(State);
#pragma warning restore CS0162 // Unreachable code detected
            }
            else
            {
                customRuntime.OpenLibraries(State);
                //Restore debug.sethook function, engine stubs it at runtime.
                var top = LuaBindings.lua_gettop(State);
                LuaBindings.lua_getglobal(State, "debug");
                LuaBindings.lua_pushcclosure(State, customRuntime.db_sethook, 0);
                LuaBindings.lua_setfield(State, -2, "sethook");
                LuaBindings.lua_settop(State, top);
            }
            if (DebugEnabled)
            {
                Console.WriteLine("Loading debug scripts");
                var luadir = Path.Combine(Util.ExtenderDirectory, "lua_modules");
                lua.Eval(string.Format(@"package.path = package.path .. "";{0}""",
                                       $@"{Util.ExtenderDirectory}\?.lua".Replace(@"\", @"\\")));
                lua.Eval(string.Format(@"package.path = package.path .. "";{0}""",
                                       $@"{luadir}\share\lua\5.2\?.lua".Replace(@"\", @"\\")));
                lua.Eval(string.Format(@"package.cpath = package.cpath .. "";{0}""",
                                       $@"{luadir}\lib\lua\5.2\?.dll".Replace(@"\", @"\\")));
                if (File.Exists($"{Util.ExtenderDirectory}/InitDebugging.lua"))
                {
                    lua.LoadFile($"{Util.ExtenderDirectory}/InitDebugging.lua");
                }
            }

            RegisterLoadBanks();
        }