author Myhailo Danylenko <isbear@ukrpost.net>
Fri, 27 Mar 2009 09:43:41 +0200
changeset 16 09b375e9ce32
parent 8 951f92c66821
child 17 ab4470465a0c
permissions -rw-r--r--
Switch to new module organization scheme

#include <lua.h>

#include "config.h"
#include "lm_types.h"
#include "lm_message_node.h"
#include "lm_message.h"
#include "lm_message_handler.h"
#include "lm_proxy.h"
#include "lm_ssl.h"
#include "lm_connection.h"

/// Some common principles:
/// Most methods can be used in two way:
/// * to get value they are invoked without their last argument. Returned value is either a value or pair of nil and error message.
/// * to set value they are invoked with last arg (value) specified. Returned value in most cases is an object, on which operation is performed (to allow chain-initialization).
/// Every object have pointer method to return pointer (lightuserdata) to underlying C loudmouth structure.
/// Every module have a bless method to convert given pointer (lightuserdata) to corresponding lua object.
/// Every unique C loudmouth object have only one corresponding lua object. Thus, result of "lm.message.bless ( message1:pointer () )" will be exactly message1 object (not its copy).
/// Where message handler object is expected, message handler function can be specified. However, you can unregister handler only if you have message handler object.

int luaopen_loudmouth (lua_State *L)
	lua_pushconststring (L, LLM_OBJREGISTRY); // 1 registry key
	lua_newtable (L);                    // 2 registry value (table)
	lua_createtable (L, 0, 1);           // 3 metatable
	lua_pushconststring (L, "__mode");        // 4 metatable key
	lua_pushconststring (L, "v");             // 5 metatable value
	lua_settable (L, -3);                // 3 metatable
	lua_setmetatable (L, -2);            // 2 registry value
	lua_rawset (L, LUA_REGISTRYINDEX);   // 0
	lua_createtable (L, 6, 0);

	lua_pushconststring (L, "message_node");
	luaopen_lm_message_node (L);
	lua_settable (L, -3);
	lua_pushconststring (L, "message");
	luaopen_lm_message (L);
	lua_settable (L, -3);
	lua_pushconststring (L, "message_handler");
	luaopen_lm_message_handler (L);
	lua_settable (L, -3);
	lua_pushconststring (L, "proxy");
	luaopen_lm_proxy (L);
	lua_settable (L, -3);
	lua_pushconststring (L, "ssl");
	luaopen_lm_ssl (L);
	lua_settable (L, -3);
	lua_pushconststring (L, "connection");
	luaopen_lm_connection (L);
	lua_settable (L, -3);

	return 1;