Lines Matching +full:in +full:- +full:tree
4 // Redistribution and use in source and binary forms, with or without
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 #include "utils/config/tree.ipp"
45 /// Gets the tree singleton stored in the Lua state.
48 /// "tree" with a pointer to the singleton.
50 /// \return A reference to the tree associated with the Lua state.
52 /// \throw syntax_error If the tree cannot be located.
53 config::tree&
59 state.push_string("tree"); in get_global_tree()
60 state.get_table(-2); in get_global_tree()
61 if (state.is_nil(-1)) in get_global_tree()
62 throw config::syntax_error("Cannot find tree singleton; global state " in get_global_tree()
64 config::tree& tree = **state.to_userdata< config::tree* >(-1); in get_global_tree() local
66 return tree; in get_global_tree()
70 /// Gets a fully-qualified tree key from the state.
75 /// considered to be the prefix of the tree key.
94 tree_key = state.to_string(-1) + "." + state.to_string(field_index - 1); in get_tree_key()
108 /// \post state(-1) Contains the new table.
110 /// \param state The Lua state in which to push the table.
121 state.set_table(-3); in new_table_for_key()
125 state.set_table(-3); in new_table_for_key()
129 state.set_table(-3); in new_table_for_key()
131 state.set_metatable(-2); in new_table_for_key()
138 /// \pre state(-3) The table to index. If this is not _G, then the table
141 /// \pre state(-2) The field to index into the table. Must be a string.
142 /// \pre state(-1) The value to set the indexed table field to.
144 /// \param state The Lua state in which to operate.
155 if (!state.is_table(-3)) in redirect_newindex()
157 if (!state.is_string(-2)) in redirect_newindex()
158 throw config::value_error("Invalid field in configuration object " in redirect_newindex()
161 const std::string dotted_key = get_tree_key(state, -3, -2); in redirect_newindex()
163 config::tree& tree = get_global_tree(state); in redirect_newindex() local
164 tree.set_lua(dotted_key, state, -1); in redirect_newindex()
170 // Now really set the key in the Lua table, but prevent direct accesses from in redirect_newindex()
171 // the user by prefixing it. We do this to ensure that re-setting the same in redirect_newindex()
172 // key of the tree results in a call to __newindex instead of __index. in redirect_newindex()
173 state.push_string("_" + state.to_string(-2)); in redirect_newindex()
174 state.push_value(-2); in redirect_newindex()
175 state.raw_set(-5); in redirect_newindex()
183 /// \pre state(-3) The table to index. If this is not _G, then the table
186 /// \pre state(-1) The field to index into the table. Must be a string.
188 /// \param state The Lua state in which to operate.
196 if (!state.is_table(-2)) in redirect_index()
198 if (!state.is_string(-1)) in redirect_index()
199 throw config::value_error("Invalid field in configuration object " in redirect_index()
203 state.push_string("_" + state.to_string(-1)); in redirect_index()
204 state.raw_get(-3); in redirect_index()
205 if (!state.is_nil(-1)) in redirect_index()
209 state.push_value(-1); // Duplicate the field name. in redirect_index()
210 state.raw_get(-3); // Get table[field] to see if it's defined. in redirect_index()
211 if (state.is_nil(-1)) { in redirect_index()
217 INV(state.is_table(-2)); in redirect_index()
218 INV(state.is_string(-1)); in redirect_index()
220 const config::tree& tree = get_global_tree(state); in redirect_index() local
221 const std::string tree_key = get_tree_key(state, -2, -1); in redirect_index()
222 if (tree.is_set(tree_key)) { in redirect_index()
223 // Publish the pre-recorded value in the tree to the Lua state, in redirect_index()
225 tree.push_lua(tree_key, state); in redirect_index()
227 state.push_string("_" + state.to_string(-1)); in redirect_index()
228 state.insert(-2); in redirect_index()
233 // Duplicate the newly created table and place it deep in the stack in redirect_index()
236 state.push_value(-1); in redirect_index()
237 state.insert(-4); in redirect_index()
239 state.raw_set(-3); in redirect_index()
250 /// Install wrappers for globals to set values in the configuration tree.
257 /// \param out_tree The tree with the layout definition and where the
260 config::redirect(lutok::state& state, tree& out_tree) in redirect()
268 state.set_table(-3); in redirect()
272 state.set_table(-3); in redirect()
274 state.set_metatable(-1); in redirect()
277 state.push_string("tree"); in redirect()
278 config::tree** tree = state.new_userdata< config::tree* >(); in redirect() local
279 *tree = &out_tree; in redirect()
280 state.set_table(-3); in redirect()