blob: c7a71676d2fa8541211d9b9306e67516ed345326 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
$NetBSD: patch-utils_config_lua_module.cpp,v 1.1 2013/06/15 00:31:34 jmmv Exp $
Support Lutok 0.3 (and therefore Lua 5.2).
This comes from upstream change df971a616a4cf930f00c836f837449d5a42589ec.
--- utils/config/lua_module.cpp
+++ utils/config/lua_module.cpp
@@ -42,7 +42,7 @@ namespace {
/// Gets the tree singleton stored in the Lua state.
///
-/// \param state The Lua state. The metadata of _G must contain a key named
+/// \param state The Lua state. The registry must contain a key named
/// "tree" with a pointer to the singleton.
///
/// \return A reference to the tree associated with the Lua state.
@@ -53,10 +53,15 @@ get_global_tree(lutok::state& state)
{
lutok::stack_cleaner cleaner(state);
- if (!state.get_metafield(lutok::globals_index, "tree"))
+ state.push_value(lutok::registry_index);
+ state.push_string("tree");
+ state.get_table(-2);
+ if (state.is_nil())
throw config::syntax_error("Cannot find tree singleton; global state "
"corrupted?");
- return **state.to_userdata< config::tree* >();
+ config::tree& tree = **state.to_userdata< config::tree* >();
+ state.pop(1);
+ return tree;
}
@@ -254,7 +259,7 @@ config::redirect(lutok::state& state, tree& out_tree)
{
lutok::stack_cleaner cleaner(state);
- state.new_table();
+ state.get_global_table();
{
state.push_string("__index");
state.push_cxx_function(redirect_index);
@@ -263,11 +268,13 @@ config::redirect(lutok::state& state, tree& out_tree)
state.push_string("__newindex");
state.push_cxx_function(redirect_newindex);
state.set_table(-3);
-
- state.push_string("tree");
- config::tree** tree = state.new_userdata< config::tree* >();
- *tree = &out_tree;
- state.set_table(-3);
}
- state.set_metatable(lutok::globals_index);
+ state.set_metatable(-1);
+
+ state.push_value(lutok::registry_index);
+ state.push_string("tree");
+ config::tree** tree = state.new_userdata< config::tree* >();
+ *tree = &out_tree;
+ state.set_table(-3);
+ state.pop(1);
}
|