void LuaState::Init( bool initStandardLibrary ) { // Register some basic functions with Lua. if (initStandardLibrary) { // A "bug" in Lua 5.01 causes stack entries to be left behind. LuaAutoBlock autoBlock(this); luaopen_base(m_state); luaopen_table( m_state ); luaopen_io(m_state); luaopen_string(m_state); luaopen_wstring(m_state); luaopen_math(m_state); luaopen_debug(m_state); #ifndef _WIN32_WCE luaopen_loadlib(m_state); #endif _WIN32_WCE ScriptFunctionsRegister( this ); GetGlobals().Register("LuaDumpGlobals", LS_LuaDumpGlobals); GetGlobals().Register("LuaDumpObject", LS_LuaDumpObject); GetGlobals().Register("LuaDumpFile", LS_LuaDumpFile); } GetGlobals().Register("LOG", LS_LOG); GetGlobals().Register("_ALERT", LS_LOG); lua_atpanic( m_state, FatalError ); }
static int pmain (lua_State *L) { lua_pushcfunction(L, luaopen_base); lua_pushstring(L, ""); lua_call(L, 1, 0); lua_pushcfunction(L, luaopen_package); lua_pushstring(L, LUA_LOADLIBNAME); lua_call(L, 1, 0); lua_pushcfunction(L, luaopen_table); lua_pushstring(L, LUA_TABLIBNAME); lua_call(L, 1, 0); lua_pushcfunction(L, luaopen_io); lua_pushstring(L, LUA_IOLIBNAME); lua_call(L, 1, 0); lua_pushcfunction(L, luaopen_os); lua_pushstring(L, LUA_OSLIBNAME); lua_call(L, 1, 0); lua_pushcfunction(L, luaopen_string); lua_pushstring(L, LUA_STRLIBNAME); lua_call(L, 1, 0); lua_pushcfunction(L, luaopen_math); lua_pushstring(L, LUA_MATHLIBNAME); lua_call(L, 1, 0); lua_pushcfunction(L, luaopen_debug); lua_pushstring(L, LUA_DBLIBNAME); lua_call(L, 1, 0); lua_pushcfunction(L, luaopen_wstring); lua_pushstring(L, LUA_WSTRLIBNAME); lua_call(L, 1, 0); #if 0 luaopen_wstring(L); lua_settop(L, 0); lua_pushvalue(L, LUA_GLOBALSINDEX); lua_replace(L, LUA_ENVIRONINDEX); /* restore environment */ #endif return 0; }
static int pmain (lua_State *L) { const luaL_reg *lib = lualibs; for (; lib->func; lib++) { lua_pushcfunction(L, lib->func); lua_pushstring(L, lib->name); lua_call(L, 1, 0); } #if 0 luaopen_wstring(L); lua_settop(L, 0); lua_pushvalue(L, LUA_GLOBALSINDEX); lua_replace(L, LUA_ENVIRONINDEX); /* restore environment */ #endif return 0; }