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-- |
0 | 1 |
|
2 |
#include <lua.h> |
|
3 |
||
16
09b375e9ce32
Switch to new module organization scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
8
diff
changeset
|
4 |
#include "config.h" |
0 | 5 |
#include "lm_types.h" |
6 |
#include "lm_message_node.h" |
|
7 |
#include "lm_message.h" |
|
8 |
#include "lm_message_handler.h" |
|
9 |
#include "lm_proxy.h" |
|
10 |
#include "lm_ssl.h" |
|
11 |
#include "lm_connection.h" |
|
12 |
||
8 | 13 |
/// Some common principles: |
14 |
/// Most methods can be used in two way: |
|
15 |
/// * to get value they are invoked without their last argument. Returned value is either a value or pair of nil and error message. |
|
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). |
|
17 |
/// Every object have pointer method to return pointer (lightuserdata) to underlying C loudmouth structure. |
|
18 |
/// Every module have a bless method to convert given pointer (lightuserdata) to corresponding lua object. |
|
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). |
|
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. |
|
21 |
||
0 | 22 |
int luaopen_loudmouth (lua_State *L) |
23 |
{ |
|
16
09b375e9ce32
Switch to new module organization scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
8
diff
changeset
|
24 |
lua_pushconststring (L, LLM_OBJREGISTRY); // 1 registry key |
0 | 25 |
lua_newtable (L); // 2 registry value (table) |
26 |
lua_createtable (L, 0, 1); // 3 metatable |
|
16
09b375e9ce32
Switch to new module organization scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
8
diff
changeset
|
27 |
lua_pushconststring (L, "__mode"); // 4 metatable key |
09b375e9ce32
Switch to new module organization scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
8
diff
changeset
|
28 |
lua_pushconststring (L, "v"); // 5 metatable value |
0 | 29 |
lua_settable (L, -3); // 3 metatable |
30 |
lua_setmetatable (L, -2); // 2 registry value |
|
31 |
lua_rawset (L, LUA_REGISTRYINDEX); // 0 |
|
32 |
||
33 |
lua_createtable (L, 6, 0); |
|
34 |
||
16
09b375e9ce32
Switch to new module organization scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
8
diff
changeset
|
35 |
lua_pushconststring (L, "message_node"); |
0 | 36 |
luaopen_lm_message_node (L); |
16
09b375e9ce32
Switch to new module organization scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
8
diff
changeset
|
37 |
lua_settable (L, -3); |
09b375e9ce32
Switch to new module organization scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
8
diff
changeset
|
38 |
lua_pushconststring (L, "message"); |
0 | 39 |
luaopen_lm_message (L); |
16
09b375e9ce32
Switch to new module organization scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
8
diff
changeset
|
40 |
lua_settable (L, -3); |
09b375e9ce32
Switch to new module organization scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
8
diff
changeset
|
41 |
lua_pushconststring (L, "message_handler"); |
0 | 42 |
luaopen_lm_message_handler (L); |
16
09b375e9ce32
Switch to new module organization scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
8
diff
changeset
|
43 |
lua_settable (L, -3); |
09b375e9ce32
Switch to new module organization scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
8
diff
changeset
|
44 |
lua_pushconststring (L, "proxy"); |
0 | 45 |
luaopen_lm_proxy (L); |
16
09b375e9ce32
Switch to new module organization scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
8
diff
changeset
|
46 |
lua_settable (L, -3); |
09b375e9ce32
Switch to new module organization scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
8
diff
changeset
|
47 |
lua_pushconststring (L, "ssl"); |
0 | 48 |
luaopen_lm_ssl (L); |
16
09b375e9ce32
Switch to new module organization scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
8
diff
changeset
|
49 |
lua_settable (L, -3); |
09b375e9ce32
Switch to new module organization scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
8
diff
changeset
|
50 |
lua_pushconststring (L, "connection"); |
0 | 51 |
luaopen_lm_connection (L); |
16
09b375e9ce32
Switch to new module organization scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
8
diff
changeset
|
52 |
lua_settable (L, -3); |
0 | 53 |
|
54 |
return 1; |
|
55 |
} |
|
56 |