summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2014-03-14 11:44:55 (GMT)
committerSwift Review <review@swift.im>2014-03-21 10:42:23 (GMT)
commitd0d9254dcac947f92525d66078c64bee18814144 (patch)
tree811cfecdeddb6e33f08561b8a7d235483c123ad7
parentdfe21a4a486e234441ccbe49fbf1445c227647ff (diff)
downloadswift-d0d9254dcac947f92525d66078c64bee18814144.zip
swift-d0d9254dcac947f92525d66078c64bee18814144.tar.bz2
Swiftob: Fix compilation against Lua 5.2
Change-Id: I0cbee4085d87cf39b55d6d429e3e45389469885f
-rw-r--r--Swiftob/LuaCommands.cpp31
-rw-r--r--Swiftob/SConscript1
-rw-r--r--Swiftob/linit.c1
3 files changed, 29 insertions, 4 deletions
diff --git a/Swiftob/LuaCommands.cpp b/Swiftob/LuaCommands.cpp
index c2478cd..0358f98 100644
--- a/Swiftob/LuaCommands.cpp
+++ b/Swiftob/LuaCommands.cpp
@@ -24,6 +24,33 @@
#define LUA_COMMANDS "__Lua_Commands"
#define STORAGE "__Storage"
+static const luaL_Reg defaultLibraries[] = {
+ {"", luaopen_base},
+ {LUA_LOADLIBNAME, luaopen_package},
+ {LUA_TABLIBNAME, luaopen_table},
+ {LUA_IOLIBNAME, luaopen_io},
+ {LUA_OSLIBNAME, luaopen_os},
+ {LUA_STRLIBNAME, luaopen_string},
+ {LUA_MATHLIBNAME, luaopen_math},
+ {LUA_DBLIBNAME, luaopen_debug},
+ {NULL, NULL}
+};
+
+static void initialize(lua_State* L) {
+ lua_gc(L, LUA_GCSTOP, 0);
+ for (const luaL_Reg* lib = defaultLibraries; lib->func; lib++) {
+#if LUA_VERSION_NUM >= 502
+ luaL_requiref(L, lib->name, lib->func, 1);
+ lua_pop(L, 1);
+#else
+ lua_pushcfunction(L, lib->func);
+ lua_pushstring(L, lib->name);
+ lua_call(L, 1, 0);
+#endif
+ }
+ lua_gc(L, LUA_GCRESTART, 0);
+}
+
LuaCommands::LuaCommands(Commands* commands, const std::string& path, Client* client, TimerFactory* timerFactory, MUCs* mucs) : path_(path), scriptsPath_(boost::filesystem::path(path_) / "scripts") {
commands_ = commands;
client_ = client;
@@ -405,8 +432,8 @@ void LuaCommands::messageOntoStack(Swift::Message::ref message, lua_State* L) {
void LuaCommands::loadScript(boost::filesystem::path filePath) {
std::cout << "Trying to load file from " << filePath << std::endl;
- lua_State* lua = lua_open();
- luaL_openlibs(lua);
+ lua_State* lua = luaL_newstate();
+ initialize(lua);
lua_pushlightuserdata(lua, this);
lua_setfield(lua, LUA_REGISTRYINDEX, LUA_COMMANDS);
#if BOOST_FILESYSTEM_VERSION == 2 // TODO: Delete this when boost 1.44 becomes a minimum requirement, and we no longer need v2
diff --git a/Swiftob/SConscript b/Swiftob/SConscript
index a830b84..b78ade9 100644
--- a/Swiftob/SConscript
+++ b/Swiftob/SConscript
@@ -13,7 +13,6 @@ elif env["SCONS_STAGE"] == "build":
myenv.UseFlags(myenv["SWIFTEN_FLAGS"])
myenv.UseFlags(myenv["SWIFTEN_DEP_FLAGS"])
sources = [
- "linit.c",
"Swiftob.cpp",
"Users.cpp",
"Commands.cpp",
diff --git a/Swiftob/linit.c b/Swiftob/linit.c
deleted file mode 100644
index 13c5b09..0000000
--- a/Swiftob/linit.c
+++ /dev/null
@@ -1 +0,0 @@
-#include "../3rdParty/Lua/src/linit.c"