lm_message.c
author Myhailo Danylenko <isbear@ukrpost.net>
Wed, 16 Mar 2016 01:53:56 +0200
changeset 66 a40beb82130c
parent 54 6bef2082e5f9
permissions -rw-r--r--
node: Use new loudmouth feature - public attribute list (v0.9.7)
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
#include <lauxlib.h>
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    21
#include <loudmouth/loudmouth.h>
17
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
    22
#include <string.h>
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    23
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
    24
#include "config.h"
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    25
#include "util.h"
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    26
#include "lm_types.h"
7
5db1448eb857 Message have node methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
    27
#include "lm_message_node.h"
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    28
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    29
/// lm.message
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    30
/// Module, representing individual message.
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    31
/// Message have a type and optionally a sub type.
8
951f92c66821 Path method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 7
diff changeset
    32
/// Message have a set common methods with message node,
39
c5a487f2fd7f Add message/message_node children iterator method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 38
diff changeset
    33
/// these are name, next, prev, parent, value, child, children,
8
951f92c66821 Path method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 7
diff changeset
    34
/// find_child, attribute, raw, xml and path. They just save
951f92c66821 Path method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 7
diff changeset
    35
/// you typing :node() each time and save memory for
951f92c66821 Path method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 7
diff changeset
    36
/// one node object.
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    37
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    38
/// message type
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    39
/// Message type (root tag type).
4
5770be2d5f3f Documentation updates
Myhailo Danylenko <isbear@ukrpost.net>
parents: 0
diff changeset
    40
/// G:
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
    41
const string2enum_t type_lm_message[] = {
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    42
	{ "message",         LM_MESSAGE_TYPE_MESSAGE         },
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    43
	{ "presence",        LM_MESSAGE_TYPE_PRESENCE        },
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    44
	{ "iq",              LM_MESSAGE_TYPE_IQ              },
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    45
	{ "stream",          LM_MESSAGE_TYPE_STREAM          },
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    46
	{ "stream error",    LM_MESSAGE_TYPE_STREAM_ERROR    },
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    47
	{ "stream features", LM_MESSAGE_TYPE_STREAM_FEATURES },
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    48
	{ "auth",            LM_MESSAGE_TYPE_AUTH            },
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    49
	{ "challenge",       LM_MESSAGE_TYPE_CHALLENGE       },
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    50
	{ "response",        LM_MESSAGE_TYPE_RESPONSE        },
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    51
	{ "success",         LM_MESSAGE_TYPE_SUCCESS         },
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    52
	{ "failure",         LM_MESSAGE_TYPE_FAILURE         },
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    53
	{ "proceed",         LM_MESSAGE_TYPE_PROCEED         },
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    54
	{ "starttls",        LM_MESSAGE_TYPE_STARTTLS        },
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    55
	{ "unknown",         LM_MESSAGE_TYPE_UNKNOWN         },
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    56
	{ "stream:stream",   LM_MESSAGE_TYPE_STREAM          },
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    57
	{ "stream:error",    LM_MESSAGE_TYPE_STREAM_ERROR    },
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    58
	{ "stream:features", LM_MESSAGE_TYPE_STREAM_FEATURES },
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
    59
	{ "stream_error",    LM_MESSAGE_TYPE_STREAM_ERROR    },
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
    60
	{ "stream_features", LM_MESSAGE_TYPE_STREAM_FEATURES },
17
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
    61
	{ NULL,              LM_MESSAGE_TYPE_MESSAGE         },
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
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    64
/// message sub type
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    65
/// Message subtype, not all combinations of type and subtype are possible.
4
5770be2d5f3f Documentation updates
Myhailo Danylenko <isbear@ukrpost.net>
parents: 0
diff changeset
    66
/// G:
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
    67
const string2enum_t sub_type_lm_message[] = {
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    68
	{ "not set",       LM_MESSAGE_SUB_TYPE_NOT_SET      },
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    69
	{ "available",     LM_MESSAGE_SUB_TYPE_AVAILABLE    },
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    70
	{ "normal",        LM_MESSAGE_SUB_TYPE_NORMAL       },
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    71
	{ "chat",          LM_MESSAGE_SUB_TYPE_CHAT         },
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    72
	{ "groupchat",     LM_MESSAGE_SUB_TYPE_GROUPCHAT    },
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    73
	{ "headline",      LM_MESSAGE_SUB_TYPE_HEADLINE     },
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    74
	{ "unavailable",   LM_MESSAGE_SUB_TYPE_UNAVAILABLE  },
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    75
	{ "probe",         LM_MESSAGE_SUB_TYPE_PROBE        },
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    76
	{ "subscribe",     LM_MESSAGE_SUB_TYPE_SUBSCRIBE    },
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    77
	{ "unsubscribe",   LM_MESSAGE_SUB_TYPE_UNSUBSCRIBE  },
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    78
	{ "subscribed",    LM_MESSAGE_SUB_TYPE_SUBSCRIBED   },
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    79
	{ "unsubscribed",  LM_MESSAGE_SUB_TYPE_UNSUBSCRIBED },
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    80
	{ "get",           LM_MESSAGE_SUB_TYPE_GET          },
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    81
	{ "set",           LM_MESSAGE_SUB_TYPE_SET          },
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    82
	{ "result",        LM_MESSAGE_SUB_TYPE_RESULT       },
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    83
	{ "error",         LM_MESSAGE_SUB_TYPE_ERROR        },
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    84
	{ "not_set",       LM_MESSAGE_SUB_TYPE_NOT_SET      },
17
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
    85
	{ NULL,            LM_MESSAGE_SUB_TYPE_NOT_SET      },
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    86
};
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    87
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    88
/// lm.message.new
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    89
/// Creates new message object.
12
63f06a23c235 Empty to field
Myhailo Danylenko <isbear@ukrpost.net>
parents: 11
diff changeset
    90
/// Note: you can specify nil as to argument to send message to server.
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    91
/// A: string (to), message type, message sub type (optional)
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    92
/// R: lm message object
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
    93
static int new_lm_message (lua_State *L)
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    94
{
12
63f06a23c235 Empty to field
Myhailo Danylenko <isbear@ukrpost.net>
parents: 11
diff changeset
    95
	const char *to   = NULL;
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
    96
	int         type = luaL_checkenum (L, 2, type_lm_message);
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    97
	LmMessage *message;
12
63f06a23c235 Empty to field
Myhailo Danylenko <isbear@ukrpost.net>
parents: 11
diff changeset
    98
63f06a23c235 Empty to field
Myhailo Danylenko <isbear@ukrpost.net>
parents: 11
diff changeset
    99
	if (lua_type (L, 1) != LUA_TNIL)
63f06a23c235 Empty to field
Myhailo Danylenko <isbear@ukrpost.net>
parents: 11
diff changeset
   100
		to = luaL_checkstring (L, 1);
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   101
	if (lua_gettop (L) > 2)
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   102
		message = lm_message_new_with_sub_type (to, type,
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
   103
						luaL_checkenum (L, 3, sub_type_lm_message));
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   104
	else
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   105
		message = lm_message_new (to, type);
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
   106
	bless_lm_message (L, message);
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   107
	lm_message_unref (message);
38
34a2b880615c Fix debugging pointer format character
Myhailo Danylenko <isbear@ukrpost.net>
parents: 37
diff changeset
   108
	D ("Message %p created", message);
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   109
	return 1;
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   110
}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   111
17
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   112
/// message table
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   113
/// Table describes xml structure of the message, the only exception is mtype key of root table.
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   114
/// mtype is a string of form "<message type>-<message sub type>", eg "iq-set".
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   115
/// Best way to learn how this table is organized, is just to look at next example:
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   116
/// [ lm.message.create { mtype = 'iq-result', to = 'foo@bar.xyz',
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   117
/// 	command = { xmlns = 'http://jabber.org/protocol/commands', node = 'http://jabber.org/protocol/rc#set-status', status = 'executing', sessionid = 'set-status:aaa3',
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   118
/// 		x = { xmlns = 'jabber:x:data', type = 'form',
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   119
/// 			title = { "Change Status" },
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   120
/// 			instructions = { "Choose the status and status message" },
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   121
/// 			field = {{ type = 'hidden', var = 'FORM_TYPE',
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   122
/// 				value = { "http://jabber.org/protocol/rc" },
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   123
/// 			},{ type = 'list-single', label = 'Status', var = 'status',
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   124
/// 				required = { },
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   125
/// 				value = { "online" },
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   126
/// 				option = {{ label = 'Chat',
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   127
/// 					value = { "chat" },
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   128
/// 				},{ label = 'Online',
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   129
/// 					value = { "online" },
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   130
/// 				},{ label = 'Away',
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   131
/// 					value = { "away" },
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   132
/// 				},{ label = 'Extended Away',
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   133
/// 					value = { "xa" },
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   134
/// 				},{ label = 'Do Not Disturb',
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   135
/// 					value = { "dnd" },
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   136
/// 				},{ label = 'Invisible',
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   137
/// 					value = { "invisible" },
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   138
/// 				},{ label = 'Offline',
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   139
/// 					value = { "offline" },
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   140
/// 				}},
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   141
/// 			},{ type = 'text-single', label = 'Priority', var = 'status-priority',
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   142
/// 				value = { "5" },
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   143
/// 			},{ type = 'text-multi', label = 'Message', var = 'status-message' }},
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   144
/// 		},
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   145
/// 	},
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   146
/// }
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   147
/// ]
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   148
static void fill_lm_node (lua_State *L, LmMessageNode *node, int index)
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   149
{
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   150
	int top = lua_gettop (L); // 0
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   151
	for (lua_pushnil (L); lua_next (L, index) != 0; lua_pop (L, lua_gettop (L) - top - 1)) // 2 value
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   152
		if (lua_type (L, top + 2) == LUA_TTABLE) {
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   153
			const char *name = lua_tostring (L, top + 1);
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   154
			lua_pushinteger (L, 1); // 3 1
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   155
			lua_gettable (L, top + 2); // 3 value[1]
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   156
			if (lua_type (L, top + 3) == LUA_TTABLE) {
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   157
				int i = 1;
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   158
				do {
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   159
					fill_lm_node (L, lm_message_node_add_child (node, name, NULL), top + 3);
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   160
					lua_pop (L, 1); // 2 value
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   161
					lua_pushinteger (L, ++i); // 3 i
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   162
					lua_gettable (L, top + 2); // 3 value[i]
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   163
				} while (lua_type (L, top + 3) == LUA_TTABLE);
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   164
			} else
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   165
				fill_lm_node (L, lm_message_node_add_child (node, name, NULL), top + 2);
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   166
		} else if (lua_type (L, top + 1) == LUA_TNUMBER && lua_tointeger (L, top + 1) == 1)
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   167
			lm_message_node_set_value (node, lua_tostring (L, top + 2));
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   168
		else
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   169
			lm_message_node_set_attribute (node, lua_tostring (L, top + 1), lua_tostring (L, top + 2));
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   170
}
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   171
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   172
/// lm.message.create
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   173
/// Creates new message object and fills it from message table.
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   174
/// Note, that table fields are not checked for their types, so, on wrong input results may be undefined.
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   175
/// A: message table
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   176
/// R: lm message object
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   177
static int create_lm_message (lua_State *L)
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   178
{
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   179
	const char *mtype;
37
6e425a8e245e Fixed segfault in message.create if mtype is not specified
Myhailo Danylenko <isbear@ukrpost.net>
parents: 23
diff changeset
   180
	const char *st      = NULL;
17
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   181
	const char *to      = NULL;
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   182
	LmMessage  *message;
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   183
	luaL_checktype (L, 1, LUA_TTABLE);
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   184
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   185
	lua_getfield (L, 1, "mtype");
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   186
	mtype = lua_tostring (L, -1);
37
6e425a8e245e Fixed segfault in message.create if mtype is not specified
Myhailo Danylenko <isbear@ukrpost.net>
parents: 23
diff changeset
   187
	if (mtype)
6e425a8e245e Fixed segfault in message.create if mtype is not specified
Myhailo Danylenko <isbear@ukrpost.net>
parents: 23
diff changeset
   188
		st = strchr (mtype, '-');
17
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   189
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   190
	lua_getfield (L, 1, "to");
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   191
	if (lua_type (L, -1) == LUA_TSTRING)
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   192
		to = lua_tostring (L, -1);
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   193
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   194
	if (st) {
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   195
		LmMessageType mt;
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   196
		lua_pushlstring (L, mtype, st - mtype);
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   197
		mt = luaL_checkenum (L, -1, type_lm_message);
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   198
		lua_pop (L, 1);
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   199
		message = lm_message_new_with_sub_type (to, mt, string2enum (st + 1, sub_type_lm_message));
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   200
	} else
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   201
		message = lm_message_new (to, luaL_checkenum (L, -2, type_lm_message));
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   202
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   203
	lua_pop (L, 2);
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   204
	lua_pushnil (L);
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   205
	lua_setfield (L, 1, "mtype");
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   206
	lua_pushnil (L);
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   207
	lua_setfield (L, 1, "to");
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   208
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   209
	fill_lm_node (L, lm_message_get_node (message), 1);
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   210
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   211
	bless_lm_message (L, message);
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   212
	lm_message_unref (message);
38
34a2b880615c Fix debugging pointer format character
Myhailo Danylenko <isbear@ukrpost.net>
parents: 37
diff changeset
   213
	D ("Message %p created", message);
17
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   214
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   215
	return 1;
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   216
}
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   217
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   218
/// lm.message.bless
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   219
/// Blesses given pointer to lm message object.
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   220
/// A: lightuserdata (C lm message object)
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   221
/// R: lm message object
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
   222
static int bless_lua_lm_message (lua_State *L)
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   223
{
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   224
	luaL_argcheck (L, lua_islightuserdata (L, 1), 1, "lm message lightuserdata expected");
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
   225
	bless_lm_message (L, lua_touserdata (L, 1));
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   226
	return 1;
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   227
}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   228
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   229
/// message:node
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   230
/// Returns root node object of message.
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   231
/// R: lm message node object
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
   232
static int node_lm_message (lua_State *L)
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   233
{
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   234
	llm_message_t *object = luaL_checklm_message (L, 1);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   235
	LmMessageNode *node = lm_message_get_node (object->message);
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
   236
	bless_lm_node (L, node);
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   237
	// XXX lm_message_node_unref (node);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   238
	return 1;
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   239
}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   240
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   241
/// message:type
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   242
/// Returns two strings: message type and message sub type.
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   243
/// R: message type, message sub type
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
   244
static int kind_lm_message (lua_State *L)
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   245
{
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   246
	llm_message_t *object = luaL_checklm_message (L, 1);
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
   247
	luaL_pushenum (L, lm_message_get_type (object->message), type_lm_message);
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
   248
	luaL_pushenum (L, lm_message_get_sub_type (object->message), sub_type_lm_message);
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   249
	return 2;
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   250
}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   251
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   252
/// message:pointer
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   253
/// Returns pointer to underlying C loudmouth structure.
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   254
/// R: lightuserdata
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
   255
static int pointer_lm_message (lua_State *L)
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   256
{
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   257
	llm_message_t *object = luaL_checklm_message (L, 1);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   258
	lua_pushlightuserdata (L, object->message);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   259
	return 1;
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   260
}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   261
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
   262
static int gc_lm_message (lua_State *L)
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   263
{
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   264
	llm_message_t *message = luaL_checklm_message (L, 1);
38
34a2b880615c Fix debugging pointer format character
Myhailo Danylenko <isbear@ukrpost.net>
parents: 37
diff changeset
   265
	D ("Message %p gc called", message);
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   266
	lm_message_unref (message->message);
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   267
	return 0;
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   268
}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   269
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
   270
static const luaL_Reg reg_f_lm_message[] = {
17
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   271
	{ "new",    new_lm_message       },
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   272
	{ "create", create_lm_message    },
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   273
	{ "bless",  bless_lua_lm_message },
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   274
	{ NULL,     NULL                 },
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   275
};
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   276
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
   277
static const luaL_Reg reg_m_lm_message[] = {
12
63f06a23c235 Empty to field
Myhailo Danylenko <isbear@ukrpost.net>
parents: 11
diff changeset
   278
	{ "node",       node_lm_message    },
63f06a23c235 Empty to field
Myhailo Danylenko <isbear@ukrpost.net>
parents: 11
diff changeset
   279
	{ "type",       kind_lm_message    },
7
5db1448eb857 Message have node methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
   280
	// These methods are common for message and message node
17
ab4470465a0c Create message in C
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   281
	{ "name",       name_lm_node       },
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
   282
	{ "next",       next_lm_node       },
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
   283
	{ "prev",       prev_lm_node       },
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
   284
	{ "parent",     parent_lm_node     },
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
   285
	{ "value",      value_lm_node      },
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
   286
	{ "child",      child_lm_node      },
39
c5a487f2fd7f Add message/message_node children iterator method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 38
diff changeset
   287
	{ "children",   children_lm_node   },
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
   288
	{ "find_child", find_child_lm_node },
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
   289
	{ "attribute",  attribute_lm_node  },
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
   290
	{ "raw",        raw_lm_node        },
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
   291
	{ "xml",        xml_lm_node        },
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
   292
	{ "path",       path_lm_node       },
7
5db1448eb857 Message have node methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
   293
	// End common methods
12
63f06a23c235 Empty to field
Myhailo Danylenko <isbear@ukrpost.net>
parents: 11
diff changeset
   294
	{ "pointer",    pointer_lm_message },
63f06a23c235 Empty to field
Myhailo Danylenko <isbear@ukrpost.net>
parents: 11
diff changeset
   295
	{ "__gc",       gc_lm_message      },
63f06a23c235 Empty to field
Myhailo Danylenko <isbear@ukrpost.net>
parents: 11
diff changeset
   296
	{ NULL,         NULL               },
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   297
};
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   298
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   299
int luaopen_lm_message (lua_State *L)
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   300
{
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   301
	luaL_newmetatable (L, "loudmouth.message");
19
d775d7289fe4 Use lua_pushliteral and lua_setfield
Myhailo Danylenko <isbear@ukrpost.net>
parents: 18
diff changeset
   302
	lua_pushvalue (L, -1);
d775d7289fe4 Use lua_pushliteral and lua_setfield
Myhailo Danylenko <isbear@ukrpost.net>
parents: 18
diff changeset
   303
	lua_setfield (L, -2, "__index");
54
6bef2082e5f9 v0.9.2 Support for lua 5.2
Myhailo Danylenko <isbear@ukrpost.net>
parents: 39
diff changeset
   304
	luaL_setfuncs (L, reg_m_lm_message, 0);
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   305
	lua_pop (L, 1);
16
09b375e9ce32 Switch to new module organization scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents: 12
diff changeset
   306
	lua_newtable (L); // XXX we can specify here exact amount of fields
54
6bef2082e5f9 v0.9.2 Support for lua 5.2
Myhailo Danylenko <isbear@ukrpost.net>
parents: 39
diff changeset
   307
	luaL_setfuncs (L, reg_f_lm_message, 0);
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   308
	return 1;
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   309
}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   310