Allow main.connection() to fail
authorMyhailo Danylenko <isbear@ukrpost.net>
Wed, 31 Mar 2010 00:28:04 +0300
changeset 98 59aeae623ac6
parent 97 b00f9ce82016
child 99 ed4676536ed9
Allow main.connection() to fail
main.c
--- a/main.c	Wed Mar 31 00:12:21 2010 +0300
+++ b/main.c	Wed Mar 31 00:28:04 2010 +0300
@@ -382,10 +382,13 @@
 /// main.connection
 /// Returns lightuserdata of mcabber's loudmouth connection.
 /// This can be very useful with lua-loudmouth, and not much otherwise.
-/// R: lightuserdata
+/// R: lightuserdata or nil
 static int lua_main_connection (lua_State *L)
 {
-	lua_pushlightuserdata (L, lconnection);
+	if (xmpp_is_online ())
+		lua_pushlightuserdata (L, lconnection);
+	else
+		lua_pushnil (L);
 	return 1;
 }
 #endif