Lines Matching refs:state
52 get_global_tree(lutok::state& state) in get_global_tree() argument
54 lutok::stack_cleaner cleaner(state); in get_global_tree()
56 state.push_value(lutok::registry_index); in get_global_tree()
57 state.push_string("tree"); in get_global_tree()
58 state.get_table(-2); in get_global_tree()
59 if (state.is_nil()) in get_global_tree()
62 config::tree& tree = **state.to_userdata< config::tree* >(); in get_global_tree()
63 state.pop(1); in get_global_tree()
81 get_tree_key(lutok::state& state, const int table_index, const int field_index) in get_tree_key() argument
83 PRE(state.is_string(field_index)); in get_tree_key()
84 const std::string field = state.to_string(field_index); in get_tree_key()
91 if (state.get_metafield(table_index, "tree_key")) { in get_tree_key()
92 tree_key = state.to_string(-1) + "." + state.to_string(field_index - 1); in get_tree_key()
93 state.pop(1); in get_tree_key()
95 tree_key = state.to_string(field_index); in get_tree_key()
100 static int redirect_newindex(lutok::state&);
101 static int redirect_index(lutok::state&);
111 new_table_for_key(lutok::state& state, const std::string& tree_key) in new_table_for_key() argument
113 state.new_table(); in new_table_for_key()
115 state.new_table(); in new_table_for_key()
117 state.push_string("__index"); in new_table_for_key()
118 state.push_cxx_function(redirect_index); in new_table_for_key()
119 state.set_table(-3); in new_table_for_key()
121 state.push_string("__newindex"); in new_table_for_key()
122 state.push_cxx_function(redirect_newindex); in new_table_for_key()
123 state.set_table(-3); in new_table_for_key()
125 state.push_string("tree_key"); in new_table_for_key()
126 state.push_string(tree_key); in new_table_for_key()
127 state.set_table(-3); in new_table_for_key()
129 state.set_metatable(-2); in new_table_for_key()
151 redirect_newindex(lutok::state& state) in redirect_newindex() argument
153 if (!state.is_table(-3)) in redirect_newindex()
155 if (!state.is_string(-2)) in redirect_newindex()
159 const std::string dotted_key = get_tree_key(state, -3, -2); in redirect_newindex()
161 config::tree& tree = get_global_tree(state); in redirect_newindex()
162 tree.set_lua(dotted_key, state, -1); in redirect_newindex()
171 state.push_string("_" + state.to_string(-2)); in redirect_newindex()
172 state.push_value(-2); in redirect_newindex()
173 state.raw_set(-5); in redirect_newindex()
192 redirect_index(lutok::state& state) in redirect_index() argument
194 if (!state.is_table(-2)) in redirect_index()
196 if (!state.is_string(-1)) in redirect_index()
201 state.push_string("_" + state.to_string(-1)); in redirect_index()
202 state.raw_get(-3); in redirect_index()
203 if (!state.is_nil(-1)) in redirect_index()
205 state.pop(1); in redirect_index()
207 state.push_value(-1); // Duplicate the field name. in redirect_index()
208 state.raw_get(-3); // Get table[field] to see if it's defined. in redirect_index()
209 if (state.is_nil(-1)) { in redirect_index()
210 state.pop(1); in redirect_index()
215 INV(state.is_table(-2)); in redirect_index()
216 INV(state.is_string(-1)); in redirect_index()
218 const config::tree& tree = get_global_tree(state); in redirect_index()
219 const std::string tree_key = get_tree_key(state, -2, -1); in redirect_index()
223 tree.push_lua(tree_key, state); in redirect_index()
225 state.push_string("_" + state.to_string(-1)); in redirect_index()
226 state.insert(-2); in redirect_index()
227 state.pop(1); in redirect_index()
229 new_table_for_key(state, tree_key); in redirect_index()
234 state.push_value(-1); in redirect_index()
235 state.insert(-4); in redirect_index()
237 state.raw_set(-3); in redirect_index()
238 state.pop(1); in redirect_index()
258 config::redirect(lutok::state& state, tree& out_tree) in redirect() argument
260 lutok::stack_cleaner cleaner(state); in redirect()
262 state.get_global_table(); in redirect()
264 state.push_string("__index"); in redirect()
265 state.push_cxx_function(redirect_index); in redirect()
266 state.set_table(-3); in redirect()
268 state.push_string("__newindex"); in redirect()
269 state.push_cxx_function(redirect_newindex); in redirect()
270 state.set_table(-3); in redirect()
272 state.set_metatable(-1); in redirect()
274 state.push_value(lutok::registry_index); in redirect()
275 state.push_string("tree"); in redirect()
276 config::tree** tree = state.new_userdata< config::tree* >(); in redirect()
278 state.set_table(-3); in redirect()
279 state.pop(1); in redirect()