Empty to field
* Message with empty to field can be created
* Fixed checklm* functions for complex types
* Formatting fixes
--- a/lm.lua Sun Mar 08 00:48:19 2009 +0200
+++ b/lm.lua Sat Mar 14 02:41:26 2009 +0200
@@ -210,8 +210,8 @@
if type ( a ) ~= "table" then
error "table expected as argument"
end
- if not a.mtype or not a.to then
- error "you must specify message type and destination"
+ if not a.mtype then
+ error "you must specify message type"
end
local mtype, subtype = a.mtype:match ( "(.-)%-(.+)" )
local m
--- a/lm_connection.c Sun Mar 08 00:48:19 2009 +0200
+++ b/lm_connection.c Sat Mar 14 02:41:26 2009 +0200
@@ -527,29 +527,29 @@
static const luaL_Reg reg_f_lm_connection[] = {
{ "new", new_lm_connection },
{ "bless", bless_lua_lm_connection },
- { NULL, NULL },
+ { NULL, NULL },
};
static const luaL_Reg reg_m_lm_connection[] = {
- { "open", open_lm_connection },
- { "close", close_lm_connection },
- { "authenticate", authenticate_lm_connection },
- { "port", port_lm_connection },
- { "server", server_lm_connection },
- { "jid", jid_lm_connection },
- { "keep_alive_rate", keep_alive_rate_lm_connection },
- { "state", status_lm_connection },
- { "proxy", proxy_lm_connection },
- { "ssl", ssl_lm_connection },
- { "send", send_lm_connection },
- { "handler", handler_lm_connection },
- { "ondisconnect", ondisconnect_lm_connection },
- { "open_wait", open_wait_lm_connection },
- { "authenticate_wait", authenticate_wait_lm_connection },
- { "send_wait", send_wait_lm_connection },
- { "pointer", pointer_lm_connection },
- { "__gc", gc_lm_connection },
- { NULL, NULL },
+ { "open", open_lm_connection },
+ { "close", close_lm_connection },
+ { "authenticate", authenticate_lm_connection },
+ { "port", port_lm_connection },
+ { "server", server_lm_connection },
+ { "jid", jid_lm_connection },
+ { "keep_alive_rate", keep_alive_rate_lm_connection },
+ { "state", status_lm_connection },
+ { "proxy", proxy_lm_connection },
+ { "ssl", ssl_lm_connection },
+ { "send", send_lm_connection },
+ { "handler", handler_lm_connection },
+ { "ondisconnect", ondisconnect_lm_connection },
+ { "open_wait", open_wait_lm_connection },
+ { "authenticate_wait", authenticate_wait_lm_connection },
+ { "send_wait", send_wait_lm_connection },
+ { "pointer", pointer_lm_connection },
+ { "__gc", gc_lm_connection },
+ { NULL, NULL },
};
int luaopen_lm_connection (lua_State *L)
--- a/lm_message.c Sun Mar 08 00:48:19 2009 +0200
+++ b/lm_message.c Sat Mar 14 02:41:26 2009 +0200
@@ -69,13 +69,17 @@
/// lm.message.new
/// Creates new message object.
+/// Note: you can specify nil as to argument to send message to server.
/// A: string (to), message type, message sub type (optional)
/// R: lm message object
static int new_lm_message (lua_State *L)
{
- const char *to = luaL_checkstring (L, 1);
+ const char *to = NULL;
int type = luaL_checkenum (L, 2, type_lm_message);
LmMessage *message;
+
+ if (lua_type (L, 1) != LUA_TNIL)
+ to = luaL_checkstring (L, 1);
if (lua_gettop (L) > 2)
message = lm_message_new_with_sub_type (to, type,
luaL_checkenum (L, 3, sub_type_lm_message));
@@ -142,12 +146,12 @@
static const luaL_Reg reg_f_lm_message[] = {
{ "new", new_lm_message },
{ "bless", bless_lua_lm_message },
- { NULL, NULL },
+ { NULL, NULL },
};
static const luaL_Reg reg_m_lm_message[] = {
- { "node", node_lm_message },
- { "type", kind_lm_message },
+ { "node", node_lm_message },
+ { "type", kind_lm_message },
// These methods are common for message and message node
{ "next", next_lm_node },
{ "prev", prev_lm_node },
@@ -161,9 +165,9 @@
{ "xml", xml_lm_node },
{ "path", path_lm_node },
// End common methods
- { "pointer", pointer_lm_message },
- { "__gc", gc_lm_message },
- { NULL, NULL },
+ { "pointer", pointer_lm_message },
+ { "__gc", gc_lm_message },
+ { NULL, NULL },
};
int luaopen_lm_message (lua_State *L)
--- a/lm_message_handler.c Sun Mar 08 00:48:19 2009 +0200
+++ b/lm_message_handler.c Sat Mar 14 02:41:26 2009 +0200
@@ -113,7 +113,7 @@
static const luaL_Reg reg_f_lm_handler[] = {
{ "new", new_lm_handler },
{ "bless", bless_lua_lm_handler },
- { NULL, NULL },
+ { NULL, NULL },
};
static const luaL_Reg reg_m_lm_handler[] = {
@@ -121,7 +121,7 @@
{ "valid", valid_lm_handler },
{ "pointer", pointer_lm_handler },
{ "__gc", gc_lm_handler },
- { NULL, NULL },
+ { NULL, NULL },
};
int luaopen_lm_message_handler (lua_State *L)
--- a/lm_message_node.c Sun Mar 08 00:48:19 2009 +0200
+++ b/lm_message_node.c Sat Mar 14 02:41:26 2009 +0200
@@ -232,7 +232,7 @@
static const luaL_Reg reg_f_lm_node[] = {
{ "bless", bless_lua_lm_node },
- { NULL, NULL },
+ { NULL, NULL },
};
static const luaL_Reg reg_m_lm_node[] = {
@@ -250,7 +250,7 @@
{ "path", path_lm_node },
{ "pointer", pointer_lm_node },
{ "__gc", gc_lm_node },
- { NULL, NULL },
+ { NULL, NULL },
};
int luaopen_lm_message_node (lua_State *L)
--- a/lm_proxy.c Sun Mar 08 00:48:19 2009 +0200
+++ b/lm_proxy.c Sat Mar 14 02:41:26 2009 +0200
@@ -148,7 +148,7 @@
static const luaL_Reg reg_f_lm_proxy[] = {
{ "new", new_lm_proxy },
{ "bless", bless_lua_lm_proxy },
- { NULL, NULL },
+ { NULL, NULL },
};
static const luaL_Reg reg_m_lm_proxy[] = {
@@ -159,7 +159,7 @@
{ "password", password_lm_proxy },
{ "pointer", pointer_lm_proxy },
{ "__gc", gc_lm_proxy },
- { NULL, NULL },
+ { NULL, NULL },
};
int luaopen_lm_proxy (lua_State *L)
--- a/lm_ssl.c Sun Mar 08 00:48:19 2009 +0200
+++ b/lm_ssl.c Sat Mar 14 02:41:26 2009 +0200
@@ -173,14 +173,14 @@
{ "new", new_lm_ssl },
{ "bless", bless_lua_lm_ssl },
{ "supported", supported_lm_ssl },
- { NULL, NULL },
+ { NULL, NULL },
};
const static luaL_Reg reg_m_lm_ssl[] = {
{ "fingerprint", fingerprint_lm_ssl },
{ "pointer", pointer_lm_ssl },
{ "__gc", gc_lm_ssl },
- { NULL, NULL },
+ { NULL, NULL },
};
int luaopen_lm_ssl (lua_State *L)
--- a/lm_types.c Sun Mar 08 00:48:19 2009 +0200
+++ b/lm_types.c Sat Mar 14 02:41:26 2009 +0200
@@ -14,15 +14,15 @@
luaL_free (cb->L, cb);
}
-#define LLM_CHECK(WHAT, TYPE) \
+#define LLM_CHECK(WHAT, LWHAT, TYPE) \
llm_##WHAT##_t *luaL_checklm_##WHAT (lua_State *L, int index) \
{ \
- llm_##WHAT##_t *object = luaL_checkudata (L, index, "loudmouth." #WHAT); \
+ llm_##WHAT##_t *object = luaL_checkudata (L, index, "loudmouth." #LWHAT); \
luaL_argcheck (L, object != NULL, index, "loudmouth " #WHAT " expected"); \
return object; \
}
-#define LLM_BLESS(WHAT, LWHAT, TYPE) \
+#define LLM_BLESS(WHAT, LWHAT, TYPE) \
llm_##WHAT##_t *bless_lm_##WHAT (lua_State *L, TYPE *WHAT) \
{ \
llm_##WHAT##_t *object; /* top of stack */ \
@@ -33,26 +33,26 @@
if (!lua_isnil (L, -1)) { /* 2 object */ \
lua_remove (L, -2); /* 1 object */ \
object = lua_touserdata (L, -1); \
- D ("Existing " #LWHAT " object %X requested", (int) object); \
+ D ("Existing " #LWHAT " object %X requested", (int) object); \
return object; \
} \
/* 2 nil */ \
lua_remove (L, -1); /* 1 registry table */ \
object = lua_newuserdata (L, sizeof (llm_##WHAT##_t)); /* 2 userdata */ \
- luaL_getmetatable (L, "loudmouth." #LWHAT); /* 3 metatable */ \
+ luaL_getmetatable (L, "loudmouth." #LWHAT); /* 3 metatable */ \
lua_setmetatable (L, -2); /* 2 object */ \
lua_pushlightuserdata (L, WHAT); /* 3 light userdata */ \
lua_pushvalue (L, -2); /* 4 object */ \
lua_rawset (L, -4); /* 2 object */ \
lua_remove (L, -2); /* 1 object */ \
object->WHAT = WHAT; \
- lm_##LWHAT##_ref (WHAT); \
- D ("New " #LWHAT " object %X blessed", (int) object); \
+ lm_##LWHAT##_ref (WHAT); \
+ D ("New " #LWHAT " object %X blessed", (int) object); \
return object; \
}
#define LLM_DEFINE(WHAT, LWHAT, TYPE) \
-LLM_CHECK (WHAT, TYPE) \
+LLM_CHECK (WHAT, LWHAT, TYPE) \
LLM_BLESS (WHAT, LWHAT, TYPE)
LLM_DEFINE (connection, connection, LmConnection)