From a51044193098128f615287308240edd0611a2e4b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Remko=20Tron=C3=A7on?= <git@el-tramo.be>
Date: Sat, 8 Mar 2014 09:27:28 +0100
Subject: Sluift: Initialize client tracing at creation time
This avoids all calls to set_trace_enabled prior to connect()
being ignored.
Change-Id: Ib4f2bc9815aae2bd456f2ececcb2a37ac460eebc
diff --git a/Sluift/client.cpp b/Sluift/client.cpp
index e2ba480..63e3bf1 100644
--- a/Sluift/client.cpp
+++ b/Sluift/client.cpp
@@ -49,14 +49,6 @@ static inline int getGlobalTimeout(lua_State* L) {
return result;
}
-static inline bool getGlobalDebug(lua_State* L) {
- lua_rawgeti(L, LUA_REGISTRYINDEX, Sluift::globals.moduleLibIndex);
- lua_getfield(L, -1, "debug");
- int result = lua_toboolean(L, -1);
- lua_pop(L, 2);
- return result;
-}
-
static void addPayloadsToTable(lua_State* L, const std::vector<boost::shared_ptr<Payload> >& payloads) {
if (!payloads.empty()) {
lua_createtable(L, boost::numeric_cast<int>(payloads.size()), 0);
@@ -110,7 +102,6 @@ SLUIFT_LUA_FUNCTION(Client, async_connect) {
port = *portInt;
}
}
- client->setTraceEnabled(getGlobalDebug(L));
client->connect(host, port);
return 0;
}
diff --git a/Sluift/sluift.cpp b/Sluift/sluift.cpp
index 858e634..3908631 100644
--- a/Sluift/sluift.cpp
+++ b/Sluift/sluift.cpp
@@ -48,6 +48,15 @@ namespace Swift {
extern "C" const char core_lua[];
extern "C" size_t core_lua_size;
+static inline bool getGlobalDebug(lua_State* L) {
+ lua_rawgeti(L, LUA_REGISTRYINDEX, Sluift::globals.moduleLibIndex);
+ lua_getfield(L, -1, "debug");
+ int result = lua_toboolean(L, -1);
+ lua_pop(L, 2);
+ return result;
+}
+
+
/*******************************************************************************
* Module functions
******************************************************************************/
@@ -74,6 +83,7 @@ SLUIFT_LUA_FUNCTION_WITH_HELP(
lua_pop(L, 1);
*client = new SluiftClient(jid, password, &Sluift::globals.networkFactories, &Sluift::globals.eventLoop);
+ (*client)->setTraceEnabled(getGlobalDebug(L));
return 1;
}
--
cgit v0.10.2-6-g49f6