Пример #1
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);
     }
 }
Пример #2
0
        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();
        }