summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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
@@ -18,18 +18,45 @@
#include <Swiften/Base/Path.h>
#include <Swiftob/Commands.h>
#include <Swiften/Base/BoostFilesystemVersion.h>
#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;
timerFactory_ = timerFactory;
mucs_ = mucs;
commands_->onReset.connect(boost::bind(&LuaCommands::registerCommands, this));
registerCommands();
}
@@ -399,20 +426,20 @@ void LuaCommands::messageOntoStack(Swift::Message::ref message, lua_State* L) {
lua_setfield(L, -2, "frombare");
lua_pushstring(L, message->getTo().toString().c_str());
lua_setfield(L, -2, "to");
lua_pushstring(L, message->getBody().c_str());
lua_setfield(L, -2, "body");
}
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
std::string filename = filePath.filename();
#else
std::string filename = filePath.filename().string();
#endif
filename += ".storage";
boost::filesystem::path storagePath(boost::filesystem::path(path_) / stringToPath(filename));
diff --git a/Swiftob/SConscript b/Swiftob/SConscript
index a830b84..b78ade9 100644
--- a/Swiftob/SConscript
+++ b/Swiftob/SConscript
@@ -7,19 +7,18 @@ if env["SCONS_STAGE"] == "build" and not GetOption("help") and not env.get("HAVE
elif env["SCONS_STAGE"] == "build":
myenv = env.Clone()
# Too many compile warnings here at the moment
myenv.Replace(CXXFLAGS = [flag for flag in env["CXXFLAGS"] if flag != "-Weverything"])
myenv.UseFlags(myenv.get("LUA_FLAGS", {}))
myenv.UseFlags(myenv["SWIFTEN_FLAGS"])
myenv.UseFlags(myenv["SWIFTEN_DEP_FLAGS"])
sources = [
- "linit.c",
"Swiftob.cpp",
"Users.cpp",
"Commands.cpp",
"MUCs.cpp",
"Storage.cpp",
"LuaCommands.cpp",
"main.cpp"
]
swiftob = myenv.Program("swiftob", sources)
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"