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); }
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(); }
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); } } }
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(); }