lm.c
author Myhailo Danylenko <isbear@ukrpost.net>
Tue, 19 May 2009 02:12:02 +0300
changeset 23 13f03e604c8a
parent 19 d775d7289fe4
child 43 bb5aaea5dd21
permissions -rw-r--r--
License notes
23
13f03e604c8a License notes
Myhailo Danylenko <isbear@ukrpost.net>
parents: 19
diff changeset
     1
13f03e604c8a License notes
Myhailo Danylenko <isbear@ukrpost.net>
parents: 19
diff changeset
     2
/* Copyright 2009 Myhailo Danylenko
13f03e604c8a License notes
Myhailo Danylenko <isbear@ukrpost.net>
parents: 19
diff changeset
     3
13f03e604c8a License notes
Myhailo Danylenko <isbear@ukrpost.net>
parents: 19
diff changeset
     4
This file is part of lua-lm.
13f03e604c8a License notes
Myhailo Danylenko <isbear@ukrpost.net>
parents: 19
diff changeset
     5
13f03e604c8a License notes
Myhailo Danylenko <isbear@ukrpost.net>
parents: 19
diff changeset
     6
lua-lm is free software: you can redistribute it and/or modify
13f03e604c8a License notes
Myhailo Danylenko <isbear@ukrpost.net>
parents: 19
diff changeset
     7
it under the terms of the GNU General Public License as published by
13f03e604c8a License notes
Myhailo Danylenko <isbear@ukrpost.net>
parents: 19
diff changeset
     8
the Free Software Foundation, either version 2 of the License, or
13f03e604c8a License notes
Myhailo Danylenko <isbear@ukrpost.net>
parents: 19
diff changeset
     9
(at your option) any later version.
13f03e604c8a License notes
Myhailo Danylenko <isbear@ukrpost.net>
parents: 19
diff changeset
    10
13f03e604c8a License notes
Myhailo Danylenko <isbear@ukrpost.net>
parents: 19
diff changeset
    11
This program is distributed in the hope that it will be useful,
13f03e604c8a License notes
Myhailo Danylenko <isbear@ukrpost.net>
parents: 19
diff changeset
    12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13f03e604c8a License notes
Myhailo Danylenko <isbear@ukrpost.net>
parents: 19
diff changeset
    13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13f03e604c8a License notes
Myhailo Danylenko <isbear@ukrpost.net>
parents: 19
diff changeset
    14
GNU General Public License for more details.
13f03e604c8a License notes
Myhailo Danylenko <isbear@ukrpost.net>
parents: 19
diff changeset
    15
13f03e604c8a License notes
Myhailo Danylenko <isbear@ukrpost.net>
parents: 19
diff changeset
    16
You should have received a copy of the GNU General Public License
13f03e604c8a License notes
Myhailo Danylenko <isbear@ukrpost.net>
parents: 19
diff changeset
    17
along with this program.  If not, see <http://www.gnu.org/licenses/>. */
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    18
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    19
#include <lua.h>
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    20
16
09b375e9ce32 Switch to new module organization scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
    21
#include "config.h"
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    22
#include "lm_types.h"
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    23
#include "lm_message_node.h"
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    24
#include "lm_message.h"
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    25
#include "lm_message_handler.h"
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    26
#include "lm_proxy.h"
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    27
#include "lm_ssl.h"
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    28
#include "lm_connection.h"
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    29
8
951f92c66821 Path method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 7
diff changeset
    30
/// Some common principles:
951f92c66821 Path method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 7
diff changeset
    31
/// Most methods can be used in two way:
951f92c66821 Path method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 7
diff changeset
    32
/// * 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
    33
/// * 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
    34
/// 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
    35
/// 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
    36
/// 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
    37
/// 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
    38
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    39
int luaopen_loudmouth (lua_State *L)
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    40
{
17
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
    41
	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
    42
	lua_newtable (L);                     // 2 registry value (table)
d775d7289fe4 Use lua_pushliteral and lua_setfield
Myhailo Danylenko <isbear@ukrpost.net>
parents: 17
diff changeset
    43
	lua_createtable (L, 0, 1);            // 3 metatable
d775d7289fe4 Use lua_pushliteral and lua_setfield
Myhailo Danylenko <isbear@ukrpost.net>
parents: 17
diff changeset
    44
	lua_pushliteral (L, "v");             // 4 metatable value
d775d7289fe4 Use lua_pushliteral and lua_setfield
Myhailo Danylenko <isbear@ukrpost.net>
parents: 17
diff changeset
    45
	lua_setfield (L, -2, "__mode");       // 3 metatable
d775d7289fe4 Use lua_pushliteral and lua_setfield
Myhailo Danylenko <isbear@ukrpost.net>
parents: 17
diff changeset
    46
	lua_setmetatable (L, -2);             // 2 registry value
d775d7289fe4 Use lua_pushliteral and lua_setfield
Myhailo Danylenko <isbear@ukrpost.net>
parents: 17
diff changeset
    47
	lua_rawset (L, LUA_REGISTRYINDEX);    // 0
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    48
	
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    49
	lua_createtable (L, 6, 0);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    50
	luaopen_lm_message_node (L);
19
d775d7289fe4 Use lua_pushliteral and lua_setfield
Myhailo Danylenko <isbear@ukrpost.net>
parents: 17
diff changeset
    51
	lua_setfield (L, -2, "message_node");
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    52
	luaopen_lm_message (L);
19
d775d7289fe4 Use lua_pushliteral and lua_setfield
Myhailo Danylenko <isbear@ukrpost.net>
parents: 17
diff changeset
    53
	lua_setfield (L, -2, "message");
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    54
	luaopen_lm_message_handler (L);
19
d775d7289fe4 Use lua_pushliteral and lua_setfield
Myhailo Danylenko <isbear@ukrpost.net>
parents: 17
diff changeset
    55
	lua_setfield (L, -2, "message_handler");
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    56
	luaopen_lm_proxy (L);
19
d775d7289fe4 Use lua_pushliteral and lua_setfield
Myhailo Danylenko <isbear@ukrpost.net>
parents: 17
diff changeset
    57
	lua_setfield (L, -2, "proxy");
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    58
	luaopen_lm_ssl (L);
19
d775d7289fe4 Use lua_pushliteral and lua_setfield
Myhailo Danylenko <isbear@ukrpost.net>
parents: 17
diff changeset
    59
	lua_setfield (L, -2, "ssl");
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    60
	luaopen_lm_connection (L);
19
d775d7289fe4 Use lua_pushliteral and lua_setfield
Myhailo Danylenko <isbear@ukrpost.net>
parents: 17
diff changeset
    61
	lua_setfield (L, -2, "connection");
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    62
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    63
	return 1;
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    64
}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    65