Lines Matching refs:state
54 get_global_tree(lutok::state& state) in get_global_tree() argument
56 lutok::stack_cleaner cleaner(state); in get_global_tree()
58 state.push_value(lutok::registry_index); in get_global_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()
64 config::tree& tree = **state.to_userdata< config::tree* >(-1); in get_global_tree()
65 state.pop(1); in get_global_tree()
83 get_tree_key(lutok::state& state, const int table_index, const int field_index) in get_tree_key() argument
85 PRE(state.is_string(field_index)); in get_tree_key()
86 const std::string field = state.to_string(field_index); in get_tree_key()
93 if (state.get_metafield(table_index, "tree_key")) { in get_tree_key()
94 tree_key = state.to_string(-1) + "." + state.to_string(field_index - 1); in get_tree_key()
95 state.pop(1); in get_tree_key()
97 tree_key = state.to_string(field_index); in get_tree_key()
102 static int redirect_newindex(lutok::state&);
103 static int redirect_index(lutok::state&);
113 new_table_for_key(lutok::state& state, const std::string& tree_key) in new_table_for_key() argument
115 state.new_table(); in new_table_for_key()
117 state.new_table(); in new_table_for_key()
119 state.push_string("__index"); in new_table_for_key()
120 state.push_cxx_function(redirect_index); in new_table_for_key()
121 state.set_table(-3); in new_table_for_key()
123 state.push_string("__newindex"); in new_table_for_key()
124 state.push_cxx_function(redirect_newindex); in new_table_for_key()
125 state.set_table(-3); in new_table_for_key()
127 state.push_string("tree_key"); in new_table_for_key()
128 state.push_string(tree_key); 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()
153 redirect_newindex(lutok::state& state) in redirect_newindex() argument
155 if (!state.is_table(-3)) in redirect_newindex()
157 if (!state.is_string(-2)) 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()
164 tree.set_lua(dotted_key, state, -1); 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()
194 redirect_index(lutok::state& state) in redirect_index() argument
196 if (!state.is_table(-2)) in redirect_index()
198 if (!state.is_string(-1)) 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()
207 state.pop(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()
212 state.pop(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()
221 const std::string tree_key = get_tree_key(state, -2, -1); 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()
229 state.pop(1); in redirect_index()
231 new_table_for_key(state, tree_key); 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()
240 state.pop(1); in redirect_index()
260 config::redirect(lutok::state& state, tree& out_tree) in redirect() argument
262 lutok::stack_cleaner cleaner(state); in redirect()
264 state.get_global_table(); in redirect()
266 state.push_string("__index"); in redirect()
267 state.push_cxx_function(redirect_index); in redirect()
268 state.set_table(-3); in redirect()
270 state.push_string("__newindex"); in redirect()
271 state.push_cxx_function(redirect_newindex); in redirect()
272 state.set_table(-3); in redirect()
274 state.set_metatable(-1); in redirect()
276 state.push_value(lutok::registry_index); in redirect()
277 state.push_string("tree"); in redirect()
278 config::tree** tree = state.new_userdata< config::tree* >(); in redirect()
280 state.set_table(-3); in redirect()
281 state.pop(1); in redirect()