lm_message_node.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
66
a40beb82130c node: Use new loudmouth feature - public attribute list (v0.9.7)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 54
diff changeset
     2
/* Copyright 2009-2016 Myhailo Danylenko
23
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>
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    22
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 0
diff changeset
    23
#include "config.h"
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    24
#include "lm_types.h"
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    25
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    26
/// lm.message_node
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    27
/// Object, representing xml node of the message.
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    28
/// Cannot be created directly, only as a part of message tree.
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    29
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    30
/// lm.message_node.bless
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    31
/// Blesses given pointer to lm message node object.
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    32
/// A: lightuserdata (C lm message node object)
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    33
/// R: lm message node object
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
    34
static int bless_lua_lm_node (lua_State *L)
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    35
{
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    36
	luaL_argcheck (L, lua_islightuserdata (L, 1), 1, "loudmouth message node lightuserdata expected");
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
    37
	bless_lm_node (L, lua_touserdata (L, 1));
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    38
	return 1;
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    39
}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    40
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    41
/// message_node:name
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    42
/// Gets a name of message node.
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    43
/// R: string
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
    44
int name_lm_node (lua_State *L)
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    45
{
7
5db1448eb857 Message have node methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
    46
	LmMessageNode *node = luaL_checkLmMessageNode (L, 1);
5db1448eb857 Message have node methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
    47
	lua_pushstring (L, node->name);
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    48
	return 1;
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    49
}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    50
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    51
/// message_node:next
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    52
/// Gets next message node.
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    53
/// R: lm message node object or nil
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
    54
int next_lm_node (lua_State *L)
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    55
{
7
5db1448eb857 Message have node methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
    56
	LmMessageNode *node = luaL_checkLmMessageNode (L, 1);
5db1448eb857 Message have node methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
    57
	LmMessageNode *next = node->next;
5db1448eb857 Message have node methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
    58
	if (next)
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
    59
		bless_lm_node (L, next);
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    60
	else
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    61
		lua_pushnil (L);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    62
	return 1;
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    63
}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    64
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    65
/// message_node:prev
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    66
/// Gets previous message node.
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    67
/// R: lm message node object or nil
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
    68
int prev_lm_node (lua_State *L)
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    69
{
7
5db1448eb857 Message have node methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
    70
	LmMessageNode *node = luaL_checkLmMessageNode (L, 1);
5db1448eb857 Message have node methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
    71
	LmMessageNode *prev = node->prev;
5db1448eb857 Message have node methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
    72
	if (prev)
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
    73
		bless_lm_node (L, prev);
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    74
	else
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    75
		lua_pushnil (L);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    76
	return 1;
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    77
}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    78
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    79
/// message_node:parent
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    80
/// Gets parent message node.
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    81
/// R: lm message node object or nil
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
    82
int parent_lm_node (lua_State *L)
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    83
{
7
5db1448eb857 Message have node methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
    84
	LmMessageNode *node = luaL_checkLmMessageNode (L, 1);
5db1448eb857 Message have node methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
    85
	LmMessageNode *parent = node->parent;
5db1448eb857 Message have node methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
    86
	if (parent)
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
    87
		bless_lm_node (L, parent);
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    88
	else
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    89
		lua_pushnil (L);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    90
	return 1;
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    91
}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    92
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    93
/// message_node:value
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    94
/// Gets or sets a value of message node.
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    95
/// A: string (optional value)
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 0
diff changeset
    96
/// R: string (if called without arguments) or lm message node object
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
    97
int value_lm_node (lua_State *L)
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    98
{
7
5db1448eb857 Message have node methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
    99
	LmMessageNode *node = luaL_checkLmMessageNode (L, 1);
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   100
	if (lua_gettop (L) > 1) { // Set
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   101
		const char *value = luaL_checkstring (L, 2);
7
5db1448eb857 Message have node methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
   102
		lm_message_node_set_value (node, value);
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 0
diff changeset
   103
		lua_pop (L, 1);
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 0
diff changeset
   104
	} else // Get
7
5db1448eb857 Message have node methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
   105
		lua_pushstring (L, lm_message_node_get_value (node));
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 0
diff changeset
   106
	return 1;
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   107
}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   108
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   109
/// message_node:child
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   110
/// Gets or creates child node object with given name.
14
4cb715fed99b Merge children and child node methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 12
diff changeset
   111
/// If name is omitted, first child node is returned.
4cb715fed99b Merge children and child node methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 12
diff changeset
   112
/// A: string (name, optional), string (optional value)
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   113
/// R: lm message node object or nil
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
   114
int child_lm_node (lua_State *L)
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   115
{
7
5db1448eb857 Message have node methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
   116
	LmMessageNode *node = luaL_checkLmMessageNode (L, 1);
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   117
	LmMessageNode *child;
14
4cb715fed99b Merge children and child node methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 12
diff changeset
   118
	int            top  = lua_gettop (L);
4cb715fed99b Merge children and child node methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 12
diff changeset
   119
	if (top > 1) {
4cb715fed99b Merge children and child node methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 12
diff changeset
   120
		const char *name = luaL_checkstring (L, 2);
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   121
14
4cb715fed99b Merge children and child node methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 12
diff changeset
   122
		if (top > 2) // Add
4cb715fed99b Merge children and child node methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 12
diff changeset
   123
			child = lm_message_node_add_child (node, name,
4cb715fed99b Merge children and child node methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 12
diff changeset
   124
							   luaL_checkstring (L, 3));
4cb715fed99b Merge children and child node methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 12
diff changeset
   125
		else // Get
4cb715fed99b Merge children and child node methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 12
diff changeset
   126
			child = lm_message_node_get_child (node, name);
4cb715fed99b Merge children and child node methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 12
diff changeset
   127
	} else
4cb715fed99b Merge children and child node methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 12
diff changeset
   128
		child = node->children;
4cb715fed99b Merge children and child node methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 12
diff changeset
   129
4cb715fed99b Merge children and child node methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 12
diff changeset
   130
	if (child)
4cb715fed99b Merge children and child node methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 12
diff changeset
   131
		bless_lm_node (L, child);
4cb715fed99b Merge children and child node methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 12
diff changeset
   132
		// XXX lm_message_node_unref (child); // may be necessary on _get/_add'ed nodes
4cb715fed99b Merge children and child node methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 12
diff changeset
   133
	else
4cb715fed99b Merge children and child node methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 12
diff changeset
   134
		lua_pushnil (L);
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   135
	return 1;
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   136
}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   137
39
c5a487f2fd7f Add message/message_node children iterator method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 38
diff changeset
   138
static int children_iterator_lm_node (lua_State *L)
c5a487f2fd7f Add message/message_node children iterator method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 38
diff changeset
   139
{
c5a487f2fd7f Add message/message_node children iterator method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 38
diff changeset
   140
	const char    *name = lua_tostring (L, lua_upvalueindex (1));
c5a487f2fd7f Add message/message_node children iterator method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 38
diff changeset
   141
	LmMessageNode *node;
c5a487f2fd7f Add message/message_node children iterator method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 38
diff changeset
   142
	if (lua_type (L, 2) == LUA_TUSERDATA) {
c5a487f2fd7f Add message/message_node children iterator method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 38
diff changeset
   143
		node = luaL_checkLmMessageNode (L, 2);
c5a487f2fd7f Add message/message_node children iterator method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 38
diff changeset
   144
		node = node -> next;
c5a487f2fd7f Add message/message_node children iterator method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 38
diff changeset
   145
	} else {
c5a487f2fd7f Add message/message_node children iterator method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 38
diff changeset
   146
		node = luaL_checkLmMessageNode (L, 1);
c5a487f2fd7f Add message/message_node children iterator method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 38
diff changeset
   147
		node = node -> children;
c5a487f2fd7f Add message/message_node children iterator method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 38
diff changeset
   148
	}
c5a487f2fd7f Add message/message_node children iterator method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 38
diff changeset
   149
c5a487f2fd7f Add message/message_node children iterator method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 38
diff changeset
   150
	if (name)
c5a487f2fd7f Add message/message_node children iterator method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 38
diff changeset
   151
		while (node && g_strcmp0 (node -> name, name))
c5a487f2fd7f Add message/message_node children iterator method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 38
diff changeset
   152
			node = node -> next;
c5a487f2fd7f Add message/message_node children iterator method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 38
diff changeset
   153
c5a487f2fd7f Add message/message_node children iterator method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 38
diff changeset
   154
	if (node)
c5a487f2fd7f Add message/message_node children iterator method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 38
diff changeset
   155
		bless_lm_node (L, node);
c5a487f2fd7f Add message/message_node children iterator method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 38
diff changeset
   156
		// XXX lm_message_node_unref (child); // may be necessary on _get/_add'ed nodes
c5a487f2fd7f Add message/message_node children iterator method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 38
diff changeset
   157
	else
c5a487f2fd7f Add message/message_node children iterator method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 38
diff changeset
   158
		lua_pushnil (L);
c5a487f2fd7f Add message/message_node children iterator method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 38
diff changeset
   159
c5a487f2fd7f Add message/message_node children iterator method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 38
diff changeset
   160
	return 1;
c5a487f2fd7f Add message/message_node children iterator method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 38
diff changeset
   161
}
c5a487f2fd7f Add message/message_node children iterator method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 38
diff changeset
   162
c5a487f2fd7f Add message/message_node children iterator method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 38
diff changeset
   163
/// message_node:children
c5a487f2fd7f Add message/message_node children iterator method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 38
diff changeset
   164
/// Returns iterator over child nodes of given node. Optionally filters childs by name.
c5a487f2fd7f Add message/message_node children iterator method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 38
diff changeset
   165
/// A: string (name, optional)
c5a487f2fd7f Add message/message_node children iterator method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 38
diff changeset
   166
/// R: iterator function, lm message node object, nil
c5a487f2fd7f Add message/message_node children iterator method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 38
diff changeset
   167
int children_lm_node (lua_State *L)
c5a487f2fd7f Add message/message_node children iterator method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 38
diff changeset
   168
{
c5a487f2fd7f Add message/message_node children iterator method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 38
diff changeset
   169
	if (lua_type (L, 2) != LUA_TSTRING)
c5a487f2fd7f Add message/message_node children iterator method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 38
diff changeset
   170
		lua_pushnil (L);
c5a487f2fd7f Add message/message_node children iterator method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 38
diff changeset
   171
c5a487f2fd7f Add message/message_node children iterator method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 38
diff changeset
   172
	lua_pushcclosure (L, children_iterator_lm_node, 1);
c5a487f2fd7f Add message/message_node children iterator method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 38
diff changeset
   173
	lua_pushvalue (L, 1);
c5a487f2fd7f Add message/message_node children iterator method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 38
diff changeset
   174
	lua_pushnil (L);
c5a487f2fd7f Add message/message_node children iterator method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 38
diff changeset
   175
	
c5a487f2fd7f Add message/message_node children iterator method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 38
diff changeset
   176
	return 3;
c5a487f2fd7f Add message/message_node children iterator method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 38
diff changeset
   177
}
c5a487f2fd7f Add message/message_node children iterator method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 38
diff changeset
   178
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   179
/// message_node:find_child
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   180
/// Searches for node with a given name over all node subtree.
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   181
/// A: string (name)
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   182
/// R: lm message node object or nil
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
   183
int find_child_lm_node (lua_State *L)
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   184
{
39
c5a487f2fd7f Add message/message_node children iterator method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 38
diff changeset
   185
	LmMessageNode *node  = luaL_checkLmMessageNode (L, 1);
c5a487f2fd7f Add message/message_node children iterator method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 38
diff changeset
   186
	const char    *name  = luaL_checkstring (L, 2);
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   187
	LmMessageNode *child;
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   188
7
5db1448eb857 Message have node methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
   189
	child = lm_message_node_get_child (node, name);
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   190
	if (!child)
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   191
		lua_pushnil (L);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   192
	else {
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
   193
		bless_lm_node (L, child);
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   194
		// XXX lm_message_node_unref (child);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   195
	}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   196
	return 1;
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   197
}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   198
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   199
/// message_node:raw
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   200
/// Gets or sets raw mode flag for node.
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   201
/// When set, value of node will not be escaped.
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   202
/// A: boolean (optional)
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 0
diff changeset
   203
/// V: boolean (if called with no apguments) or lm message node object
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
   204
int raw_lm_node (lua_State *L)
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   205
{
7
5db1448eb857 Message have node methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
   206
	LmMessageNode *node = luaL_checkLmMessageNode (L, 1);
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   207
	if (lua_gettop (L) > 1) { // Set
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   208
		luaL_checktype (L, 2, LUA_TBOOLEAN);
7
5db1448eb857 Message have node methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
   209
		lm_message_node_set_raw_mode (node, lua_toboolean (L, 2));
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 0
diff changeset
   210
		lua_pop (L, 1);
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 0
diff changeset
   211
	} else // Get
7
5db1448eb857 Message have node methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
   212
		lua_pushboolean (L, lm_message_node_get_raw_mode (node));
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 0
diff changeset
   213
	return 1;
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   214
}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   215
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   216
/// message_node:attribute
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   217
/// Gets or sets value of node attribute with a given name.
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   218
/// A: string (name), string (optional value)
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 0
diff changeset
   219
/// R: string (when called with one aprgument) or lm message node object
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
   220
int attribute_lm_node (lua_State *L)
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   221
{
7
5db1448eb857 Message have node methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
   222
	LmMessageNode *node = luaL_checkLmMessageNode (L, 1);
39
c5a487f2fd7f Add message/message_node children iterator method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 38
diff changeset
   223
	const char    *name = luaL_checkstring (L, 2);
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   224
	if (lua_gettop (L) > 2) { // Set
7
5db1448eb857 Message have node methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
   225
		lm_message_node_set_attribute (node, name, luaL_checkstring (L, 3));
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 0
diff changeset
   226
		lua_pop (L, 2);
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 0
diff changeset
   227
	} else // Get
7
5db1448eb857 Message have node methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
   228
		lua_pushstring (L, lm_message_node_get_attribute (node, name));
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 0
diff changeset
   229
	return 1;
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   230
}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   231
66
a40beb82130c node: Use new loudmouth feature - public attribute list (v0.9.7)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 54
diff changeset
   232
/// message_node:attributes
a40beb82130c node: Use new loudmouth feature - public attribute list (v0.9.7)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 54
diff changeset
   233
/// Returns a table with message node attributes.
a40beb82130c node: Use new loudmouth feature - public attribute list (v0.9.7)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 54
diff changeset
   234
/// R: table
a40beb82130c node: Use new loudmouth feature - public attribute list (v0.9.7)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 54
diff changeset
   235
int attributes_lm_node (lua_State *L)
a40beb82130c node: Use new loudmouth feature - public attribute list (v0.9.7)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 54
diff changeset
   236
{
a40beb82130c node: Use new loudmouth feature - public attribute list (v0.9.7)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 54
diff changeset
   237
	lua_newtable (L);
a40beb82130c node: Use new loudmouth feature - public attribute list (v0.9.7)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 54
diff changeset
   238
#ifdef HAVE_LM_MESSAGE_NODE_ATTRIBUTE
a40beb82130c node: Use new loudmouth feature - public attribute list (v0.9.7)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 54
diff changeset
   239
	LmMessageNode          *node = luaL_checkLmMessageNode (L, 1);
a40beb82130c node: Use new loudmouth feature - public attribute list (v0.9.7)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 54
diff changeset
   240
	LmMessageNodeAttribute *attribute;
a40beb82130c node: Use new loudmouth feature - public attribute list (v0.9.7)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 54
diff changeset
   241
	for (attribute = node -> attributes; attribute; attribute = attribute -> next) {
a40beb82130c node: Use new loudmouth feature - public attribute list (v0.9.7)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 54
diff changeset
   242
		lua_pushstring (L, attribute -> value);
a40beb82130c node: Use new loudmouth feature - public attribute list (v0.9.7)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 54
diff changeset
   243
		lua_setfield (L, -2, attribute -> name);
a40beb82130c node: Use new loudmouth feature - public attribute list (v0.9.7)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 54
diff changeset
   244
	}
a40beb82130c node: Use new loudmouth feature - public attribute list (v0.9.7)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 54
diff changeset
   245
#endif
a40beb82130c node: Use new loudmouth feature - public attribute list (v0.9.7)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 54
diff changeset
   246
	return 1;
a40beb82130c node: Use new loudmouth feature - public attribute list (v0.9.7)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 54
diff changeset
   247
}
a40beb82130c node: Use new loudmouth feature - public attribute list (v0.9.7)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 54
diff changeset
   248
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   249
/// message_node:xml
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   250
/// Returns node representation in xml.
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   251
/// R: string
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
   252
int xml_lm_node (lua_State *L)
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   253
{
7
5db1448eb857 Message have node methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
   254
	LmMessageNode *node = luaL_checkLmMessageNode (L, 1);
5db1448eb857 Message have node methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
   255
	lua_pushstring (L, lm_message_node_to_string (node));
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   256
	return 1;
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   257
}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   258
8
951f92c66821 Path method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 7
diff changeset
   259
/// message_node:path
951f92c66821 Path method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 7
diff changeset
   260
/// Returns node with specified path to it.
951f92c66821 Path method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 7
diff changeset
   261
/// If any element in a path cannot be found, it returns nil.
951f92c66821 Path method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 7
diff changeset
   262
/// A: string (node name), ...
951f92c66821 Path method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 7
diff changeset
   263
/// R: lm message node object or nil
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
   264
int path_lm_node (lua_State *L)
8
951f92c66821 Path method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 7
diff changeset
   265
{
951f92c66821 Path method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 7
diff changeset
   266
	LmMessageNode *node = luaL_checkLmMessageNode (L, 1);
951f92c66821 Path method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 7
diff changeset
   267
	int i = 1;
951f92c66821 Path method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 7
diff changeset
   268
	while (i++ < lua_gettop (L)) {
951f92c66821 Path method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 7
diff changeset
   269
		node = lm_message_node_get_child (node, luaL_checkstring (L, i));
951f92c66821 Path method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 7
diff changeset
   270
		if (node == NULL) {
951f92c66821 Path method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 7
diff changeset
   271
			lua_pushnil (L);
951f92c66821 Path method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 7
diff changeset
   272
			return 1;
951f92c66821 Path method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 7
diff changeset
   273
		}
951f92c66821 Path method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 7
diff changeset
   274
	}
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
   275
	bless_lm_node (L, node);
8
951f92c66821 Path method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 7
diff changeset
   276
	// XXX lm_message_node_unref (child);
951f92c66821 Path method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 7
diff changeset
   277
	return 1;
951f92c66821 Path method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 7
diff changeset
   278
}
951f92c66821 Path method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 7
diff changeset
   279
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   280
/// message_node:pointer
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   281
/// Returns pointer to underlying C structure.
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   282
/// R: lightuserdata
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
   283
static int pointer_lm_node (lua_State *L)
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   284
{
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
   285
	llm_node_t *object = luaL_checklm_node (L, 1);
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
   286
	lua_pushlightuserdata (L, object->node);
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   287
	return 1;
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   288
}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   289
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
   290
static int gc_lm_node (lua_State *L)
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   291
{
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
   292
	llm_node_t *object = luaL_checklm_node (L, 1);
38
34a2b880615c Fix debugging pointer format character
Myhailo Danylenko <isbear@ukrpost.net>
parents: 23
diff changeset
   293
	D ("Message node %p gc called", object);
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
   294
	lm_message_node_unref (object->node);
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   295
	return 0;
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   296
}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   297
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
   298
static const luaL_Reg reg_f_lm_node[] = {
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
   299
	{ "bless", bless_lua_lm_node },
12
63f06a23c235 Empty to field
Myhailo Danylenko <isbear@ukrpost.net>
parents: 11
diff changeset
   300
	{ NULL,    NULL              },
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   301
};
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   302
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
   303
static const luaL_Reg reg_m_lm_node[] = {
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
   304
	{ "name",       name_lm_node       },
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
   305
	{ "next",       next_lm_node       },
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
   306
	{ "prev",       prev_lm_node       },
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
   307
	{ "parent",     parent_lm_node     },
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
   308
	{ "value",      value_lm_node      },
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
   309
	{ "child",      child_lm_node      },
39
c5a487f2fd7f Add message/message_node children iterator method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 38
diff changeset
   310
	{ "children",   children_lm_node   },
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
   311
	{ "find_child", find_child_lm_node },
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
   312
	{ "attribute",  attribute_lm_node  },
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
   313
	{ "raw",        raw_lm_node        },
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
   314
	{ "xml",        xml_lm_node        },
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
   315
	{ "path",       path_lm_node       },
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
   316
	{ "pointer",    pointer_lm_node    },
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
   317
	{ "__gc",       gc_lm_node         },
12
63f06a23c235 Empty to field
Myhailo Danylenko <isbear@ukrpost.net>
parents: 11
diff changeset
   318
	{ NULL,         NULL               },
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   319
};
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   320
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   321
int luaopen_lm_message_node (lua_State *L)
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   322
{
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   323
	luaL_newmetatable (L, "loudmouth.message_node");
19
d775d7289fe4 Use lua_pushliteral and lua_setfield
Myhailo Danylenko <isbear@ukrpost.net>
parents: 18
diff changeset
   324
	lua_pushvalue (L, -1);
d775d7289fe4 Use lua_pushliteral and lua_setfield
Myhailo Danylenko <isbear@ukrpost.net>
parents: 18
diff changeset
   325
	lua_setfield (L, -2, "__index");
54
6bef2082e5f9 v0.9.2 Support for lua 5.2
Myhailo Danylenko <isbear@ukrpost.net>
parents: 45
diff changeset
   326
	luaL_setfuncs (L, reg_m_lm_node, 0);
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   327
	lua_pop (L, 1);
16
09b375e9ce32 Switch to new module organization scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents: 14
diff changeset
   328
	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: 45
diff changeset
   329
	luaL_setfuncs (L, reg_f_lm_node, 0);
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   330
	return 1;
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   331
}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   332