lm_message_node.c
author Myhailo Danylenko <isbear@ukrpost.net>
Sun, 08 Mar 2009 00:48:19 +0200
changeset 11 a8c6460d612b
parent 8 951f92c66821
child 12 63f06a23c235
permissions -rw-r--r--
Naming scheme change to more ld-friendly
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
     1
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
     2
#include <lua.h>
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
     3
#include <lauxlib.h>
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
     4
#include <loudmouth/loudmouth.h>
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
     5
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 0
diff changeset
     6
#include "config.h"
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
     7
#include "lm_types.h"
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
     8
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
     9
/// lm.message_node
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    10
/// Object, representing xml node of the message.
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    11
/// Cannot be created directly, only as a part of message tree.
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    12
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    13
/// lm.message_node.bless
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    14
/// Blesses given pointer to lm message node object.
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    15
/// A: lightuserdata (C lm message node object)
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    16
/// R: lm message node object
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
    17
static int bless_lua_lm_node (lua_State *L)
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
	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
    20
	bless_lm_node (L, lua_touserdata (L, 1));
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    21
	return 1;
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    22
}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    23
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    24
/// message_node:name
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    25
/// Gets a name of message node.
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    26
/// R: string
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
    27
int name_lm_node (lua_State *L)
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    28
{
7
5db1448eb857 Message have node methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
    29
	LmMessageNode *node = luaL_checkLmMessageNode (L, 1);
5db1448eb857 Message have node methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
    30
	lua_pushstring (L, node->name);
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    31
	return 1;
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    32
}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    33
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    34
/// message_node:next
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    35
/// Gets next message node.
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    36
/// 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
    37
int next_lm_node (lua_State *L)
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    38
{
7
5db1448eb857 Message have node methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
    39
	LmMessageNode *node = luaL_checkLmMessageNode (L, 1);
5db1448eb857 Message have node methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
    40
	LmMessageNode *next = node->next;
5db1448eb857 Message have node methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
    41
	if (next)
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
    42
		bless_lm_node (L, next);
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    43
	else
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    44
		lua_pushnil (L);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    45
	return 1;
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    46
}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    47
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    48
/// message_node:prev
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    49
/// Gets previous message node.
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    50
/// 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
    51
int prev_lm_node (lua_State *L)
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    52
{
7
5db1448eb857 Message have node methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
    53
	LmMessageNode *node = luaL_checkLmMessageNode (L, 1);
5db1448eb857 Message have node methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
    54
	LmMessageNode *prev = node->prev;
5db1448eb857 Message have node methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
    55
	if (prev)
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
    56
		bless_lm_node (L, prev);
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    57
	else
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    58
		lua_pushnil (L);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    59
	return 1;
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    60
}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    61
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    62
/// message_node:children
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    63
/// Gets first child node (raw access used).
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    64
/// 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
    65
int children_lm_node (lua_State *L)
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    66
{
7
5db1448eb857 Message have node methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
    67
	LmMessageNode *node = luaL_checkLmMessageNode (L, 1);
5db1448eb857 Message have node methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
    68
	LmMessageNode *child = node->children;
5db1448eb857 Message have node methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
    69
	if (child)
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
    70
		bless_lm_node (L, child);
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    71
	else
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    72
		lua_pushnil (L);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    73
	return 1;
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    74
}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    75
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    76
/// message_node:parent
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    77
/// Gets parent message node.
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    78
/// 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
    79
int parent_lm_node (lua_State *L)
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    80
{
7
5db1448eb857 Message have node methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
    81
	LmMessageNode *node = luaL_checkLmMessageNode (L, 1);
5db1448eb857 Message have node methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
    82
	LmMessageNode *parent = node->parent;
5db1448eb857 Message have node methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
    83
	if (parent)
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
    84
		bless_lm_node (L, parent);
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    85
	else
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    86
		lua_pushnil (L);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    87
	return 1;
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    88
}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    89
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    90
/// message_node:value
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    91
/// Gets or sets a value of message node.
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    92
/// A: string (optional value)
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 0
diff changeset
    93
/// 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
    94
int value_lm_node (lua_State *L)
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    95
{
7
5db1448eb857 Message have node methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
    96
	LmMessageNode *node = luaL_checkLmMessageNode (L, 1);
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    97
	if (lua_gettop (L) > 1) { // Set
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    98
		const char *value = luaL_checkstring (L, 2);
7
5db1448eb857 Message have node methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
    99
		lm_message_node_set_value (node, value);
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 0
diff changeset
   100
		lua_pop (L, 1);
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 0
diff changeset
   101
	} else // Get
7
5db1448eb857 Message have node methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
   102
		lua_pushstring (L, lm_message_node_get_value (node));
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 0
diff changeset
   103
	return 1;
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   104
}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   105
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   106
/// message_node:child
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   107
/// Gets or creates child node object with given name.
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   108
/// A: string (name), string (optional value)
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   109
/// 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
   110
int child_lm_node (lua_State *L)
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   111
{
7
5db1448eb857 Message have node methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
   112
	LmMessageNode *node = luaL_checkLmMessageNode (L, 1);
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   113
	const char *name = luaL_checkstring (L, 2);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   114
	LmMessageNode *child;
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   115
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 0
diff changeset
   116
	if (lua_gettop (L) > 2) // Add
7
5db1448eb857 Message have node methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
   117
		child = lm_message_node_add_child (node, name,
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   118
						   luaL_checkstring (L, 3));
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 0
diff changeset
   119
	else { // Get
7
5db1448eb857 Message have node methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
   120
		child = lm_message_node_get_child (node, name);
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   121
		if (!child) {
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   122
			lua_pushnil (L);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   123
			return 1;
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   124
		}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   125
	}
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
   126
	bless_lm_node (L, child);
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   127
	// XXX lm_message_node_unref (child);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   128
	return 1;
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   129
}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   130
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   131
/// message_node:find_child
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   132
/// Searches for node with a given name over all node subtree.
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   133
/// A: string (name)
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   134
/// 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
   135
int find_child_lm_node (lua_State *L)
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   136
{
7
5db1448eb857 Message have node methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
   137
	LmMessageNode *node = luaL_checkLmMessageNode (L, 1);
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   138
	const char *name = luaL_checkstring (L, 2);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   139
	LmMessageNode *child;
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   140
7
5db1448eb857 Message have node methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
   141
	child = lm_message_node_get_child (node, name);
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   142
	if (!child)
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   143
		lua_pushnil (L);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   144
	else {
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
   145
		bless_lm_node (L, child);
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   146
		// XXX lm_message_node_unref (child);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   147
	}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   148
	return 1;
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   149
}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   150
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   151
/// message_node:raw
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   152
/// Gets or sets raw mode flag for node.
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   153
/// When set, value of node will not be escaped.
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   154
/// A: boolean (optional)
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 0
diff changeset
   155
/// 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
   156
int raw_lm_node (lua_State *L)
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   157
{
7
5db1448eb857 Message have node methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
   158
	LmMessageNode *node = luaL_checkLmMessageNode (L, 1);
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   159
	if (lua_gettop (L) > 1) { // Set
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   160
		luaL_checktype (L, 2, LUA_TBOOLEAN);
7
5db1448eb857 Message have node methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
   161
		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
   162
		lua_pop (L, 1);
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 0
diff changeset
   163
	} else // Get
7
5db1448eb857 Message have node methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
   164
		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
   165
	return 1;
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   166
}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   167
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   168
/// message_node:attribute
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   169
/// Gets or sets value of node attribute with a given name.
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   170
/// A: string (name), string (optional value)
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 0
diff changeset
   171
/// 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
   172
int attribute_lm_node (lua_State *L)
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   173
{
7
5db1448eb857 Message have node methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
   174
	LmMessageNode *node = luaL_checkLmMessageNode (L, 1);
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   175
	const char *name = luaL_checkstring (L, 2);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   176
	if (lua_gettop (L) > 2) { // Set
7
5db1448eb857 Message have node methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
   177
		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
   178
		lua_pop (L, 2);
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 0
diff changeset
   179
	} else // Get
7
5db1448eb857 Message have node methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
   180
		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
   181
	return 1;
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   182
}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   183
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   184
/// message_node:xml
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   185
/// Returns node representation in xml.
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   186
/// R: string
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
   187
int xml_lm_node (lua_State *L)
0
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
	LmMessageNode *node = luaL_checkLmMessageNode (L, 1);
5db1448eb857 Message have node methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
   190
	lua_pushstring (L, lm_message_node_to_string (node));
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   191
	return 1;
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   192
}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   193
8
951f92c66821 Path method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 7
diff changeset
   194
/// message_node:path
951f92c66821 Path method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 7
diff changeset
   195
/// Returns node with specified path to it.
951f92c66821 Path method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 7
diff changeset
   196
/// If any element in a path cannot be found, it returns nil.
951f92c66821 Path method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 7
diff changeset
   197
/// A: string (node name), ...
951f92c66821 Path method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 7
diff changeset
   198
/// 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
   199
int path_lm_node (lua_State *L)
8
951f92c66821 Path method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 7
diff changeset
   200
{
951f92c66821 Path method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 7
diff changeset
   201
	LmMessageNode *node = luaL_checkLmMessageNode (L, 1);
951f92c66821 Path method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 7
diff changeset
   202
	int i = 1;
951f92c66821 Path method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 7
diff changeset
   203
	while (i++ < lua_gettop (L)) {
951f92c66821 Path method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 7
diff changeset
   204
		node = lm_message_node_get_child (node, luaL_checkstring (L, i));
951f92c66821 Path method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 7
diff changeset
   205
		if (node == NULL) {
951f92c66821 Path method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 7
diff changeset
   206
			lua_pushnil (L);
951f92c66821 Path method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 7
diff changeset
   207
			return 1;
951f92c66821 Path method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 7
diff changeset
   208
		}
951f92c66821 Path method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 7
diff changeset
   209
	}
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
   210
	bless_lm_node (L, node);
8
951f92c66821 Path method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 7
diff changeset
   211
	// XXX lm_message_node_unref (child);
951f92c66821 Path method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 7
diff changeset
   212
	return 1;
951f92c66821 Path method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 7
diff changeset
   213
}
951f92c66821 Path method
Myhailo Danylenko <isbear@ukrpost.net>
parents: 7
diff changeset
   214
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   215
/// message_node:pointer
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   216
/// Returns pointer to underlying C structure.
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   217
/// R: lightuserdata
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
   218
static int pointer_lm_node (lua_State *L)
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   219
{
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
   220
	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
   221
	lua_pushlightuserdata (L, object->node);
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   222
	return 1;
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   223
}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   224
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
   225
static int gc_lm_node (lua_State *L)
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   226
{
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
   227
	llm_node_t *object = luaL_checklm_node (L, 1);
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 0
diff changeset
   228
	D ("Message node %X gc called", (int) object);
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
   229
	lm_message_node_unref (object->node);
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   230
	return 0;
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   231
}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   232
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
   233
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
   234
	{ "bless", bless_lua_lm_node },
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   235
	{ NULL,    NULL                       },
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   236
};
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   237
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
   238
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
   239
	{ "name",       name_lm_node       },
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
   240
	{ "next",       next_lm_node       },
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
   241
	{ "prev",       prev_lm_node       },
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
   242
	{ "children",   children_lm_node   },
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
   243
	{ "parent",     parent_lm_node     },
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
   244
	{ "value",      value_lm_node      },
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
   245
	{ "child",      child_lm_node      },
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
   246
	{ "find_child", find_child_lm_node },
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
   247
	{ "attribute",  attribute_lm_node  },
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
   248
	{ "raw",        raw_lm_node        },
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
   249
	{ "xml",        xml_lm_node        },
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
   250
	{ "path",       path_lm_node       },
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
   251
	{ "pointer",    pointer_lm_node    },
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
   252
	{ "__gc",       gc_lm_node         },
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   253
	{ NULL,         NULL                        },
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   254
};
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   255
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   256
int luaopen_lm_message_node (lua_State *L)
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   257
{
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   258
	luaL_newmetatable (L, "loudmouth.message_node");
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   259
	lua_pushstring (L, "__index");
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   260
	lua_pushvalue (L, -2);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   261
	lua_settable (L, -3);
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
   262
	luaL_register (L, NULL, reg_m_lm_node);
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   263
	lua_pop (L, 1);
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 8
diff changeset
   264
	luaL_register (L, "lm.message_node", reg_f_lm_node);
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   265
	return 1;
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   266
}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   267