author Myhailo Danylenko <isbear@ukrpost.net>
Wed, 16 Mar 2016 01:53:56 +0200
changeset 66 a40beb82130c
parent 43 bb5aaea5dd21
permissions -rw-r--r--
node: Use new loudmouth feature - public attribute list (v0.9.7)

/* Copyright 2009 Myhailo Danylenko

This file is part of lua-lm.

lua-lm is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>. */

#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_pushliteral (L, LLM_OBJREGISTRY); // 1 registry key
	lua_newtable (L);                     // 2 registry value (table)
	lua_createtable (L, 0, 1);            // 3 metatable
	lua_pushliteral (L, "v");             // 4 metatable value
	lua_setfield (L, -2, "__mode");       // 3 metatable
	lua_setmetatable (L, -2);             // 2 registry value
	lua_rawset (L, LUA_REGISTRYINDEX);    // 0
	lua_createtable (L, 6, 0);
	luaopen_lm_message_node (L);
	lua_setfield (L, -2, "message_node");
	luaopen_lm_message (L);
	lua_setfield (L, -2, "message");
	luaopen_lm_message_handler (L);
	lua_setfield (L, -2, "message_handler");
	luaopen_lm_proxy (L);
	lua_setfield (L, -2, "proxy");
	luaopen_lm_ssl (L);
	lua_setfield (L, -2, "ssl");
	luaopen_lm_connection (L);
	lua_setfield (L, -2, "connection");

	return 1;