@@ -427,43 +427,27 @@ void LuaMan::Clear()
427
427
428
428
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
429
429
430
- int LuaMan::Create ()
431
- {
432
- // Create the master state
433
- m_pMasterState = lua_open ();
430
+ int LuaMan::Create () {
431
+ m_pMasterState = luaL_newstate ();
434
432
// Attach the master state to LuaBind
435
- open (m_pMasterState);
436
- // Open the lua libs for the master state
437
- // luaL_openlibs(m_pMasterState);
438
-
439
- // Load only libraries we need
440
- lua_pushcfunction (m_pMasterState, luaopen_base);
441
- lua_pushliteral (m_pMasterState, LUA_COLIBNAME);
442
- lua_call (m_pMasterState, 1 , 0 );
443
-
444
- lua_pushcfunction (m_pMasterState, luaopen_table);
445
- lua_pushliteral (m_pMasterState, LUA_TABLIBNAME);
446
- lua_call (m_pMasterState, 1 , 0 );
447
-
448
- lua_pushcfunction (m_pMasterState, luaopen_string);
449
- lua_pushliteral (m_pMasterState, LUA_STRLIBNAME);
450
- lua_call (m_pMasterState, 1 , 0 );
451
-
452
- lua_pushcfunction (m_pMasterState, luaopen_math);
453
- lua_pushliteral (m_pMasterState, LUA_MATHLIBNAME);
454
- lua_call (m_pMasterState, 1 , 0 );
455
-
456
- lua_pushcfunction (m_pMasterState, luaopen_debug);
457
- lua_pushliteral (m_pMasterState, LUA_DBLIBNAME);
458
- lua_call (m_pMasterState, 1 , 0 );
459
-
460
- lua_pushcfunction (m_pMasterState, luaopen_package);
461
- lua_pushliteral (m_pMasterState, LUA_LOADLIBNAME);
462
- lua_call (m_pMasterState, 1 , 0 );
463
-
464
- lua_pushcfunction (m_pMasterState, luaopen_jit);
465
- lua_pushliteral (m_pMasterState, LUA_LOADLIBNAME);
466
- lua_call (m_pMasterState, 1 , 0 );
433
+ luabind::open (m_pMasterState);
434
+
435
+ const luaL_Reg libsToLoad[] = {
436
+ { LUA_COLIBNAME, luaopen_base },
437
+ { LUA_LOADLIBNAME, luaopen_package },
438
+ { LUA_TABLIBNAME, luaopen_table },
439
+ { LUA_STRLIBNAME, luaopen_string },
440
+ { LUA_MATHLIBNAME, luaopen_math },
441
+ { LUA_DBLIBNAME, luaopen_debug },
442
+ { LUA_JITLIBNAME, luaopen_jit },
443
+ { NULL , NULL } // End of array
444
+ };
445
+
446
+ for (const luaL_Reg *lib = libsToLoad; lib->func ; lib++) {
447
+ lua_pushcfunction (m_pMasterState, lib->func );
448
+ lua_pushstring (m_pMasterState, lib->name );
449
+ lua_call (m_pMasterState, 1 , 0 );
450
+ }
467
451
468
452
// LuaJIT should start automatically after we load the library but we're making sure it did anyway.
469
453
if (!luaJIT_setmode (m_pMasterState, 0 , LUAJIT_MODE_ENGINE | LUAJIT_MODE_ON)) { RTEAbort (" Failed to initialize LuaJIT!" ); }
0 commit comments