133 else |
133 else |
134 lua_pushnil (L); |
134 lua_pushnil (L); |
135 return 1; |
135 return 1; |
136 } |
136 } |
137 |
137 |
|
138 static int children_iterator_lm_node (lua_State *L) |
|
139 { |
|
140 const char *name = lua_tostring (L, lua_upvalueindex (1)); |
|
141 LmMessageNode *node; |
|
142 if (lua_type (L, 2) == LUA_TUSERDATA) { |
|
143 node = luaL_checkLmMessageNode (L, 2); |
|
144 node = node -> next; |
|
145 } else { |
|
146 node = luaL_checkLmMessageNode (L, 1); |
|
147 node = node -> children; |
|
148 } |
|
149 |
|
150 if (name) |
|
151 while (node && g_strcmp0 (node -> name, name)) |
|
152 node = node -> next; |
|
153 |
|
154 if (node) |
|
155 bless_lm_node (L, node); |
|
156 // XXX lm_message_node_unref (child); // may be necessary on _get/_add'ed nodes |
|
157 else |
|
158 lua_pushnil (L); |
|
159 |
|
160 return 1; |
|
161 } |
|
162 |
|
163 /// message_node:children |
|
164 /// Returns iterator over child nodes of given node. Optionally filters childs by name. |
|
165 /// A: string (name, optional) |
|
166 /// R: iterator function, lm message node object, nil |
|
167 int children_lm_node (lua_State *L) |
|
168 { |
|
169 LmMessageNode *node = luaL_checkLmMessageNode (L, 1); |
|
170 |
|
171 if (lua_type (L, 2) != LUA_TSTRING) |
|
172 lua_pushnil (L); |
|
173 |
|
174 lua_pushcclosure (L, children_iterator_lm_node, 1); |
|
175 lua_pushvalue (L, 1); |
|
176 lua_pushnil (L); |
|
177 |
|
178 return 3; |
|
179 } |
|
180 |
138 /// message_node:find_child |
181 /// message_node:find_child |
139 /// Searches for node with a given name over all node subtree. |
182 /// Searches for node with a given name over all node subtree. |
140 /// A: string (name) |
183 /// A: string (name) |
141 /// R: lm message node object or nil |
184 /// R: lm message node object or nil |
142 int find_child_lm_node (lua_State *L) |
185 int find_child_lm_node (lua_State *L) |
143 { |
186 { |
144 LmMessageNode *node = luaL_checkLmMessageNode (L, 1); |
187 LmMessageNode *node = luaL_checkLmMessageNode (L, 1); |
145 const char *name = luaL_checkstring (L, 2); |
188 const char *name = luaL_checkstring (L, 2); |
146 LmMessageNode *child; |
189 LmMessageNode *child; |
147 |
190 |
148 child = lm_message_node_get_child (node, name); |
191 child = lm_message_node_get_child (node, name); |
149 if (!child) |
192 if (!child) |
150 lua_pushnil (L); |
193 lua_pushnil (L); |
177 /// A: string (name), string (optional value) |
220 /// A: string (name), string (optional value) |
178 /// R: string (when called with one aprgument) or lm message node object |
221 /// R: string (when called with one aprgument) or lm message node object |
179 int attribute_lm_node (lua_State *L) |
222 int attribute_lm_node (lua_State *L) |
180 { |
223 { |
181 LmMessageNode *node = luaL_checkLmMessageNode (L, 1); |
224 LmMessageNode *node = luaL_checkLmMessageNode (L, 1); |
182 const char *name = luaL_checkstring (L, 2); |
225 const char *name = luaL_checkstring (L, 2); |
183 if (lua_gettop (L) > 2) { // Set |
226 if (lua_gettop (L) > 2) { // Set |
184 lm_message_node_set_attribute (node, name, luaL_checkstring (L, 3)); |
227 lm_message_node_set_attribute (node, name, luaL_checkstring (L, 3)); |
185 lua_pop (L, 2); |
228 lua_pop (L, 2); |
186 } else // Get |
229 } else // Get |
187 lua_pushstring (L, lm_message_node_get_attribute (node, name)); |
230 lua_pushstring (L, lm_message_node_get_attribute (node, name)); |
247 { "next", next_lm_node }, |
290 { "next", next_lm_node }, |
248 { "prev", prev_lm_node }, |
291 { "prev", prev_lm_node }, |
249 { "parent", parent_lm_node }, |
292 { "parent", parent_lm_node }, |
250 { "value", value_lm_node }, |
293 { "value", value_lm_node }, |
251 { "child", child_lm_node }, |
294 { "child", child_lm_node }, |
|
295 { "children", children_lm_node }, |
252 { "find_child", find_child_lm_node }, |
296 { "find_child", find_child_lm_node }, |
253 { "attribute", attribute_lm_node }, |
297 { "attribute", attribute_lm_node }, |
254 { "raw", raw_lm_node }, |
298 { "raw", raw_lm_node }, |
255 { "xml", xml_lm_node }, |
299 { "xml", xml_lm_node }, |
256 { "path", path_lm_node }, |
300 { "path", path_lm_node }, |