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-- |
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 |
{ |
|
17 | 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 | 31 |
|
32 |
lua_createtable (L, 6, 0); |
|
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 | 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 | 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 | 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 | 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 | 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 | 45 |
|
46 |
return 1; |
|
47 |
} |
|
48 |