summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2014-01-18 09:27:41 (GMT)
committerRemko Tronçon <git@el-tramo.be>2014-01-18 10:44:42 (GMT)
commitd869b157f0d3eee5d4964878b3990df98a07e020 (patch)
tree4c01b3cef0a1653b8aebd80ac71ca7ede7076fff /Sluift/sluift.cpp
parent85c46a0fcce3495fe94397d53791628a8ccc74c4 (diff)
downloadswift-d869b157f0d3eee5d4964878b3990df98a07e020.zip
swift-d869b157f0d3eee5d4964878b3990df98a07e020.tar.bz2
Sluift: Refactor global debug & timeout options.
Use regular table values on the sluift table. Enable enabling tracing on a client after the fact. Change-Id: Iaa2bea61bdadf0b8dec4951654c402b7133c1151
Diffstat (limited to 'Sluift/sluift.cpp')
-rw-r--r--Sluift/sluift.cpp57
1 files changed, 9 insertions, 48 deletions
diff --git a/Sluift/sluift.cpp b/Sluift/sluift.cpp
index 39b92fc..08ffd92 100644
--- a/Sluift/sluift.cpp
+++ b/Sluift/sluift.cpp
@@ -70,7 +70,7 @@ SLUIFT_LUA_FUNCTION_WITH_HELP(
lua_setmetatable(L, -3);
lua_pop(L, 1);
- *client = new SluiftClient(jid, password, &Sluift::globals.networkFactories, &Sluift::globals.eventLoop, &Sluift::globals);
+ *client = new SluiftClient(jid, password, &Sluift::globals.networkFactories, &Sluift::globals.eventLoop);
return 1;
}
@@ -115,41 +115,6 @@ SLUIFT_LUA_FUNCTION_WITH_HELP(
return 1;
}
-static int sluift_index(lua_State* L) {
- try {
- std::string key(Lua::checkString(L, 2));
- if (key == "debug") {
- lua_pushboolean(L, Sluift::globals.debug);
- return 1;
- }
- else if (key == "timeout") {
- lua_pushnumber(L, Sluift::globals.timeout);
- return 1;
- }
- return 0;
- }
- catch (const std::exception& e) {
- return luaL_error(L, e.what());
- }
-}
-
-
-static int sluift_newindex(lua_State* L) {
- try {
- std::string key(Lua::checkString(L, 2));
- if (key == "debug") {
- Sluift::globals.debug = lua_toboolean(L, 3);
- }
- else if (key == "timeout") {
- Sluift::globals.timeout = Lua::checkIntNumber(L, 3);
- }
- return 0;
- }
- catch (const std::exception& e) {
- return luaL_error(L, e.what());
- }
-}
-
SLUIFT_LUA_FUNCTION_WITH_HELP(
Sluift, from_xml,
"Convert a raw XML string into a structured representation.",
@@ -314,11 +279,15 @@ SLUIFT_LUA_FUNCTION(IDN, stringprep) {
static const luaL_Reg sluift_functions[] = { {NULL, NULL} };
SLUIFT_API int luaopen_sluift(lua_State* L) {
- // Initialize globals
- Sluift::globals.debug = false;
- Sluift::globals.timeout = -1;
-
+ // Initialize & store the module table
luaL_register(L, lua_tostring(L, 1), sluift_functions);
+ lua_pushinteger(L, -1);
+ lua_setfield(L, -2, "timeout");
+ lua_pushboolean(L, 0);
+ lua_setfield(L, -2, "debug");
+
+ lua_pushvalue(L, -1);
+ Sluift::globals.moduleLibIndex = luaL_ref(L, LUA_REGISTRYINDEX);
// Load core lib code
if (luaL_loadbuffer(L, core_lua, core_lua_size, "core.lua") != 0) {
@@ -346,14 +315,6 @@ SLUIFT_API int luaopen_sluift(lua_State* L) {
}
lua_pop(L, 1);
- // Set read only
- lua_createtable(L, 0, 0);
- lua_pushcclosure(L, sluift_index, 0);
- lua_setfield(L, -2, "__index");
- lua_pushcclosure(L, sluift_newindex, 0);
- lua_setfield(L, -2, "__newindex");
- lua_setmetatable(L, -2);
-
// Load client metatable
lua_rawgeti(L, LUA_REGISTRYINDEX, Sluift::globals.coreLibIndex);
std::vector<std::string> tables = boost::assign::list_of("Client");