lm.c
author Myhailo Danylenko <isbear@ukrpost.net>
Mon, 27 Apr 2009 13:15:23 +0300
changeset 19 d775d7289fe4
parent 17 ab4470465a0c
child 23 13f03e604c8a
permissions -rw-r--r--
Use lua_pushliteral and lua_setfield
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
     1
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
     2
#include <lua.h>
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
     3
16
09b375e9ce32 Switch to new module organization scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
     4
#include "config.h"
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
     5
#include "lm_types.h"
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
     6
#include "lm_message_node.h"
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
     7
#include "lm_message.h"
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
     8
#include "lm_message_handler.h"
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
     9
#include "lm_proxy.h"
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    10
#include "lm_ssl.h"
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    11
#include "lm_connection.h"
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    12
8
951f92c66821 Path method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 7
diff changeset
    13
/// Some common principles:
951f92c66821 Path method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 7
diff changeset
    14
/// Most methods can be used in two way:
951f92c66821 Path method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 7
diff changeset
    15
/// * to get value they are invoked without their last argument. Returned value is either a value or pair of nil and error message.
951f92c66821 Path method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 7
diff changeset
    16
/// * 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).
951f92c66821 Path method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 7
diff changeset
    17
/// Every object have pointer method to return pointer (lightuserdata) to underlying C loudmouth structure.
951f92c66821 Path method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 7
diff changeset
    18
/// Every module have a bless method to convert given pointer (lightuserdata) to corresponding lua object.
951f92c66821 Path method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 7
diff changeset
    19
/// 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).
951f92c66821 Path method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 7
diff changeset
    20
/// Where message handler object is expected, message handler function can be specified. However, you can unregister handler only if you have message handler object.
951f92c66821 Path method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 7
diff changeset
    21
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    22
int luaopen_loudmouth (lua_State *L)
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    23
{
17
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
    24
	lua_pushliteral (L, LLM_OBJREGISTRY); // 1 registry key
19
d775d7289fe4 Use lua_pushliteral and lua_setfield
Myhailo Danylenko <isbear@ukrpost.net>
parents: 17
diff changeset
    25
	lua_newtable (L);                     // 2 registry value (table)
d775d7289fe4 Use lua_pushliteral and lua_setfield
Myhailo Danylenko <isbear@ukrpost.net>
parents: 17
diff changeset
    26
	lua_createtable (L, 0, 1);            // 3 metatable
d775d7289fe4 Use lua_pushliteral and lua_setfield
Myhailo Danylenko <isbear@ukrpost.net>
parents: 17
diff changeset
    27
	lua_pushliteral (L, "v");             // 4 metatable value
d775d7289fe4 Use lua_pushliteral and lua_setfield
Myhailo Danylenko <isbear@ukrpost.net>
parents: 17
diff changeset
    28
	lua_setfield (L, -2, "__mode");       // 3 metatable
d775d7289fe4 Use lua_pushliteral and lua_setfield
Myhailo Danylenko <isbear@ukrpost.net>
parents: 17
diff changeset
    29
	lua_setmetatable (L, -2);             // 2 registry value
d775d7289fe4 Use lua_pushliteral and lua_setfield
Myhailo Danylenko <isbear@ukrpost.net>
parents: 17
diff changeset
    30
	lua_rawset (L, LUA_REGISTRYINDEX);    // 0
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    31
	
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    32
	lua_createtable (L, 6, 0);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    33
	luaopen_lm_message_node (L);
19
d775d7289fe4 Use lua_pushliteral and lua_setfield
Myhailo Danylenko <isbear@ukrpost.net>
parents: 17
diff changeset
    34
	lua_setfield (L, -2, "message_node");
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    35
	luaopen_lm_message (L);
19
d775d7289fe4 Use lua_pushliteral and lua_setfield
Myhailo Danylenko <isbear@ukrpost.net>
parents: 17
diff changeset
    36
	lua_setfield (L, -2, "message");
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    37
	luaopen_lm_message_handler (L);
19
d775d7289fe4 Use lua_pushliteral and lua_setfield
Myhailo Danylenko <isbear@ukrpost.net>
parents: 17
diff changeset
    38
	lua_setfield (L, -2, "message_handler");
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    39
	luaopen_lm_proxy (L);
19
d775d7289fe4 Use lua_pushliteral and lua_setfield
Myhailo Danylenko <isbear@ukrpost.net>
parents: 17
diff changeset
    40
	lua_setfield (L, -2, "proxy");
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    41
	luaopen_lm_ssl (L);
19
d775d7289fe4 Use lua_pushliteral and lua_setfield
Myhailo Danylenko <isbear@ukrpost.net>
parents: 17
diff changeset
    42
	lua_setfield (L, -2, "ssl");
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    43
	luaopen_lm_connection (L);
19
d775d7289fe4 Use lua_pushliteral and lua_setfield
Myhailo Danylenko <isbear@ukrpost.net>
parents: 17
diff changeset
    44
	lua_setfield (L, -2, "connection");
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    45
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    46
	return 1;
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    47
}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    48