diff options
Diffstat (limited to 'Sluift/client.cpp')
-rw-r--r-- | Sluift/client.cpp | 36 |
1 files changed, 32 insertions, 4 deletions
diff --git a/Sluift/client.cpp b/Sluift/client.cpp index 9cb5090..cdbc591 100644 --- a/Sluift/client.cpp +++ b/Sluift/client.cpp @@ -42,4 +42,20 @@ 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; +} + SLUIFT_LUA_FUNCTION(Client, async_connect) { SluiftClient* client = getClient(L); @@ -55,4 +71,5 @@ SLUIFT_LUA_FUNCTION(Client, async_connect) { } } + client->setTraceEnabled(getGlobalDebug(L)); client->connect(host, port); return 0; @@ -60,4 +77,15 @@ SLUIFT_LUA_FUNCTION(Client, async_connect) { 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", + "" +) { + getClient(L)->setTraceEnabled(lua_toboolean(L, 1)); + return 0; +} + +SLUIFT_LUA_FUNCTION_WITH_HELP( Client, wait_connected, "Block until the client is connected.\n\nThis is useful after an `async_connect`.", @@ -65,5 +93,5 @@ SLUIFT_LUA_FUNCTION_WITH_HELP( "" ) { - getClient(L)->waitConnected(); + getClient(L)->waitConnected(getGlobalTimeout(L)); return 0; } @@ -275,5 +303,5 @@ static int sendQuery(lua_State* L, IQ::Type type) { } - int timeout = Sluift::globals.timeout; + int timeout = getGlobalTimeout(L); if (boost::optional<int> timeoutInt = Lua::getIntField(L, 2, "timeout")) { timeout = *timeoutInt; @@ -307,5 +335,5 @@ SLUIFT_LUA_FUNCTION(Client, query_pubsub) { } - int timeout = Sluift::globals.timeout; + int timeout = getGlobalTimeout(L); if (boost::optional<int> timeoutInt = Lua::getIntField(L, 2, "timeout")) { timeout = *timeoutInt; @@ -521,5 +549,5 @@ SLUIFT_LUA_FUNCTION(Client, get_next_event) { SluiftClient* client = getClient(L); - int timeout = Sluift::globals.timeout; + int timeout = getGlobalTimeout(L); boost::optional<SluiftClient::Event::Type> type; int condition = 0; |