diff options
| author | Remko Tronçon <git@el-tramo.be> | 2014-03-08 08:27:28 (GMT) |
|---|---|---|
| committer | Swift Review <review@swift.im> | 2014-03-20 18:35:05 (GMT) |
| commit | a51044193098128f615287308240edd0611a2e4b (patch) | |
| tree | 6c05d97d57259071b21b389573cbedcc92fcb260 | |
| parent | 2bb017cbe8825d9e4b319ab747e23afe73d106bd (diff) | |
| download | swift-contrib-a51044193098128f615287308240edd0611a2e4b.zip swift-contrib-a51044193098128f615287308240edd0611a2e4b.tar.bz2 | |
Sluift: Initialize client tracing at creation time
This avoids all calls to set_trace_enabled prior to connect()
being ignored.
Change-Id: Ib4f2bc9815aae2bd456f2ececcb2a37ac460eebc
| -rw-r--r-- | Sluift/client.cpp | 9 | ||||
| -rw-r--r-- | Sluift/sluift.cpp | 10 |
2 files changed, 10 insertions, 9 deletions
diff --git a/Sluift/client.cpp b/Sluift/client.cpp index e2ba480..63e3bf1 100644 --- a/Sluift/client.cpp +++ b/Sluift/client.cpp @@ -43,26 +43,18 @@ static inline SluiftClient* getClient(lua_State* L) { static inline int getGlobalTimeout(lua_State* L) { lua_rawgeti(L, LUA_REGISTRYINDEX, Sluift::globals.moduleLibIndex); lua_getfield(L, -1, "timeout"); int result = boost::numeric_cast<int>(lua_tointeger(L, -1)); lua_pop(L, 2); 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); for (size_t i = 0; i < payloads.size(); ++i) { Sluift::globals.elementConvertor.convertToLua(L, payloads[i]); lua_rawseti(L, -2, boost::numeric_cast<int>(i+1)); } Lua::registerGetByTypeIndex(L, -1); lua_setfield(L, -2, "payloads"); @@ -104,19 +96,18 @@ SLUIFT_LUA_FUNCTION(Client, async_connect) { int port = client->getOptions().manualPort; if (lua_istable(L, 2)) { if (boost::optional<std::string> hostString = Lua::getStringField(L, 2, "host")) { host = *hostString; } if (boost::optional<int> portInt = Lua::getIntField(L, 2, "port")) { port = *portInt; } } - client->setTraceEnabled(getGlobalDebug(L)); client->connect(host, port); return 0; } SLUIFT_LUA_FUNCTION_WITH_HELP( Client, set_trace_enabled, "Enable/disable tracing of the data sent/received.\n\n.", "self\n" "enable a boolean specifying whether to enable/disable tracing", diff --git a/Sluift/sluift.cpp b/Sluift/sluift.cpp index 858e634..3908631 100644 --- a/Sluift/sluift.cpp +++ b/Sluift/sluift.cpp @@ -42,18 +42,27 @@ using namespace Swift; namespace Swift { namespace Sluift { SluiftGlobals globals; } } 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 ******************************************************************************/ SLUIFT_LUA_FUNCTION_WITH_HELP( Sluift, new_client, "Creates a new client.\n\nReturns a @{Client} object.\n", @@ -68,18 +77,19 @@ SLUIFT_LUA_FUNCTION_WITH_HELP( SluiftClient** client = reinterpret_cast<SluiftClient**>(lua_newuserdata(L, sizeof(SluiftClient*))); lua_rawgeti(L, LUA_REGISTRYINDEX, Sluift::globals.coreLibIndex); lua_getfield(L, -1, "Client"); lua_setmetatable(L, -3); lua_pop(L, 1); *client = new SluiftClient(jid, password, &Sluift::globals.networkFactories, &Sluift::globals.eventLoop); + (*client)->setTraceEnabled(getGlobalDebug(L)); return 1; } SLUIFT_LUA_FUNCTION_WITH_HELP( Sluift, sha1, "Compute the SHA-1 hash of given data", "data the data to hash", "" ) { |
Swift