From 81eb47815ef615585443de296ca2a3f23da09df1 Mon Sep 17 00:00:00 2001 From: Leonardo Laguna Ruiz Date: Sun, 12 Apr 2020 12:44:04 +0300 Subject: [PATCH] Improves the LuaJIT performance by using luaL_openlibs to initialize the VM --- src/LuaJITEngine.cpp | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/LuaJITEngine.cpp b/src/LuaJITEngine.cpp index ee39157..5e87383 100644 --- a/src/LuaJITEngine.cpp +++ b/src/LuaJITEngine.cpp @@ -28,17 +28,16 @@ struct LuaJITEngine : ScriptEngine { return -1; } - // Import a subset of the standard library - luaopen_base(L); - luaopen_string(L); - luaopen_table(L); - luaopen_math(L); - luaopen_bit(L); - // Loads the JIT package otherwise it will be off - luaopen_jit(L); - // Disables access to the JIT package - lua_pushnil(L); - lua_setglobal(L,"jit"); + // Import the common Lua libraries + luaL_openlibs(L); + // Unloads the unsafe libraries + lua_pushinteger(L, 0); + lua_setglobal(L, "os"); + lua_pushinteger(L, 0); + lua_setglobal(L, "io"); + // Unloads 'require' so 'io' and 'os' cannot be reloaded + lua_pushinteger(L, 0); + lua_setglobal(L, "require"); // Set user pointer lua_pushlightuserdata(L, this);