diff options
Diffstat (limited to 'Sluift/sluift.cpp')
-rw-r--r-- | Sluift/sluift.cpp | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/Sluift/sluift.cpp b/Sluift/sluift.cpp index 95e7101..e6b2bb6 100644 --- a/Sluift/sluift.cpp +++ b/Sluift/sluift.cpp @@ -41,5 +41,5 @@ namespace Swift { } -extern "C" const char boot_lua[]; +extern "C" const char core_lua[]; /******************************************************************************* @@ -264,5 +264,5 @@ SLUIFT_LUA_FUNCTION(IDN, stringprep) { ******************************************************************************/ -static const luaL_reg sluift_functions[] = { {NULL, NULL} }; +static const luaL_Reg sluift_functions[] = { {NULL, NULL} }; SLUIFT_API int luaopen_sluift(lua_State* L) { @@ -271,12 +271,12 @@ SLUIFT_API int luaopen_sluift(lua_State* L) { Sluift::globals.timeout = -1; - luaL_register(L, "sluift", sluift_functions); + luaL_register(L, lua_tostring(L, 1), sluift_functions); - // Load bootstrap code - if (luaL_loadbuffer(L, boot_lua, strlen(boot_lua), "boot.lua") != 0) { + // Load core lib code + if (luaL_loadbuffer(L, core_lua, strlen(core_lua), "core.lua") != 0) { lua_error(L); } lua_call(L, 0, 1); - Sluift::globals.bootIndex = luaL_ref(L, LUA_REGISTRYINDEX); + Sluift::globals.coreLibIndex = luaL_ref(L, LUA_REGISTRYINDEX); // Register functions @@ -290,12 +290,11 @@ SLUIFT_API int luaopen_sluift(lua_State* L) { // Register convenience functions - lua_rawgeti(L, LUA_REGISTRYINDEX, Sluift::globals.bootIndex); - lua_getfield(L, -1, "tprint"); - lua_setfield(L, -3, "tprint"); - lua_pop(L, 1); - - lua_rawgeti(L, LUA_REGISTRYINDEX, Sluift::globals.bootIndex); - lua_getfield(L, -1, "disco"); - lua_setfield(L, -3, "disco"); + lua_rawgeti(L, LUA_REGISTRYINDEX, Sluift::globals.coreLibIndex); + std::vector<std::string> coreLibExports = boost::assign::list_of + ("tprint")("disco"); + foreach (const std::string& coreLibExport, coreLibExports) { + lua_getfield(L, -1, coreLibExport.c_str()); + lua_setfield(L, -3, coreLibExport.c_str()); + } lua_pop(L, 1); @@ -313,5 +312,5 @@ SLUIFT_API int luaopen_sluift(lua_State* L) { Lua::FunctionRegistry::getInstance().registerTypeMetaTable(L, table); luaL_getmetatable(L, Lua::FunctionRegistry::getMetaTableNameForType(table).c_str()); - lua_rawgeti(L, LUA_REGISTRYINDEX, Sluift::globals.bootIndex); + lua_rawgeti(L, LUA_REGISTRYINDEX, Sluift::globals.coreLibIndex); lua_getfield(L, -1, table.c_str()); if (!lua_isnil(L, -1)) { |