summaryrefslogtreecommitdiffstats
path: root/src/luabind-3-globalsindex.patch
blob: 74a2687acd19286076392f35653cd3c1e3464f99 (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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
This file is part of MXE. See LICENSE.md for licensing information.

commit 7325c469a8eb443cd2d46c9860f278cd2672dace
Author: Boris Nagaev <bnagaev@gmail.com>
Date:   Fri Aug 22 15:27:11 2014 +0400

    LUA_GLOBALSINDEX

diff --git a/luabind/detail/call_function.hpp b/luabind/detail/call_function.hpp
index 8f5afff..cb56dc0 100644
--- a/luabind/detail/call_function.hpp
+++ b/luabind/detail/call_function.hpp
@@ -347,8 +347,7 @@ namespace luabind
 			, luabind::detail::proxy_function_void_caller<boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> >
 			, luabind::detail::proxy_function_caller<Ret, boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> > >::type proxy_type;
 
-		lua_pushstring(L, name);
-		lua_gettable(L, LUA_GLOBALSINDEX);
+		lua_getglobal(L, name);
 
 		return proxy_type(L, 1, &detail::pcall, args);
 	}
@@ -390,8 +389,7 @@ namespace luabind
 			, luabind::detail::proxy_function_void_caller<boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> >
 			, luabind::detail::proxy_function_caller<Ret, boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> > >::type proxy_type;
 
-		lua_pushstring(L, name);
-		lua_gettable(L, LUA_GLOBALSINDEX);
+		lua_getglobal(L, name);
 
 		return proxy_type(L, 1, &detail::resume_impl, args);
 	}
diff --git a/luabind/detail/object_funs.hpp b/luabind/detail/object_funs.hpp
index 2600238..f826d7a 100644
--- a/luabind/detail/object_funs.hpp
+++ b/luabind/detail/object_funs.hpp
@@ -184,7 +184,11 @@ namespace luabind
 
 	inline object get_globals(lua_State* L)
 	{
+#ifdef LUA_GLOBALSINDEX
 		lua_pushvalue(L, LUA_GLOBALSINDEX);
+#else
+		lua_rawgeti(L, LUA_REGISTRYINDEX, LUA_RIDX_GLOBALS);
+#endif
 		detail::lua_reference ref;
 		ref.set(L);
 		return object(L, ref, true/*object::reference()*/);
diff --git a/luabind/object.hpp b/luabind/object.hpp
index f7b7ca5..b288171 100644
--- a/luabind/object.hpp
+++ b/luabind/object.hpp
@@ -1207,7 +1207,12 @@ inline object newtable(lua_State* interpreter)
 // this could be optimized by returning a proxy
 inline object globals(lua_State* interpreter)
 {
+#ifdef LUA_GLOBALSINDEX
     lua_pushvalue(interpreter, LUA_GLOBALSINDEX);
+#else
+    lua_rawgeti(interpreter, LUA_REGISTRYINDEX,
+            LUA_RIDX_GLOBALS);
+#endif
     detail::stack_pop pop(interpreter, 1);
     return object(from_stack(interpreter, -1));
 }
diff --git a/src/class_rep.cpp b/src/class_rep.cpp
index 70bb623..912df95 100755
--- a/src/class_rep.cpp
+++ b/src/class_rep.cpp
@@ -146,11 +146,10 @@ int luabind::detail::class_rep::constructor_dispatcher(lua_State* L)
         && cls->get_class_type() == class_rep::lua_class
         && !cls->bases().empty())
     {
-        lua_pushstring(L, "super");
         lua_pushvalue(L, 1);
         lua_pushvalue(L, -3);
         lua_pushcclosure(L, super_callback, 2);
-        lua_settable(L, LUA_GLOBALSINDEX);
+        lua_setglobal(L, "super");
     }
 
     lua_pushvalue(L, -1);
@@ -169,9 +168,8 @@ int luabind::detail::class_rep::constructor_dispatcher(lua_State* L)
 
     if (super_deprecation_disabled)
     {
-        lua_pushstring(L, "super");
         lua_pushnil(L);
-        lua_settable(L, LUA_GLOBALSINDEX);
+        lua_setglobal(L, "super");
     }
 
     return 1;
@@ -214,17 +212,15 @@ int luabind::detail::class_rep::super_callback(lua_State* L)
 
 	if (base->bases().empty())
 	{
-		lua_pushstring(L, "super");
 		lua_pushnil(L);
-		lua_settable(L, LUA_GLOBALSINDEX);
+		lua_setglobal(L, "super");
 	}
 	else
 	{
-		lua_pushstring(L, "super");
 		lua_pushlightuserdata(L, base);
 		lua_pushvalue(L, lua_upvalueindex(2));
 		lua_pushcclosure(L, super_callback, 2);
-		lua_settable(L, LUA_GLOBALSINDEX);
+		lua_setglobal(L, "super");
 	}
 
 	base->get_table(L);
@@ -241,9 +237,8 @@ int luabind::detail::class_rep::super_callback(lua_State* L)
 	// TODO: instead of clearing the global variable "super"
 	// store it temporarily in the registry. maybe we should
 	// have some kind of warning if the super global is used?
-	lua_pushstring(L, "super");
 	lua_pushnil(L);
-	lua_settable(L, LUA_GLOBALSINDEX);
+	lua_setglobal(L, "super");
 
 	return 0;
 }
diff --git a/src/create_class.cpp b/src/create_class.cpp
index c0eb719..47251ef 100755
--- a/src/create_class.cpp
+++ b/src/create_class.cpp
@@ -126,9 +126,8 @@ namespace luabind { namespace detail
 		new(c) class_rep(L, name);
 
 		// make the class globally available
-		lua_pushstring(L, name);
-		lua_pushvalue(L, -2);
-		lua_settable(L, LUA_GLOBALSINDEX);
+		lua_pushvalue(L, -1);
+		lua_setglobal(L, name);
 
 		// also add it to the closure as return value
 		lua_pushcclosure(L, &stage2, 1);
diff --git a/src/open.cpp b/src/open.cpp
index f20dcfc..ec8e4ff 100755
--- a/src/open.cpp
+++ b/src/open.cpp
@@ -178,21 +178,18 @@ namespace
         lua_settable(L, LUA_REGISTRYINDEX);
 
         // add functions (class, cast etc...)
-        lua_pushstring(L, "class");
         lua_pushcclosure(L, detail::create_class::stage1, 0);
-        lua_settable(L, LUA_GLOBALSINDEX);
+        lua_setglobal(L, "class");
 
-        lua_pushstring(L, "property");
         lua_pushcclosure(L, &make_property, 0);
-        lua_settable(L, LUA_GLOBALSINDEX);
+        lua_setglobal(L, "property");
 
         lua_pushlightuserdata(L, &main_thread_tag);
         lua_pushlightuserdata(L, L);
         lua_rawset(L, LUA_REGISTRYINDEX);
 
-        lua_pushstring(L, "super");
         lua_pushcclosure(L, &deprecated_super, 0);
-        lua_settable(L, LUA_GLOBALSINDEX);
+        lua_setglobal(L, "super");
     }
 
 } // namespace luabind
diff --git a/src/scope.cpp b/src/scope.cpp
index 6495687..d4d1f24 100755
--- a/src/scope.cpp
+++ b/src/scope.cpp
@@ -136,22 +136,25 @@ namespace luabind {
     {
         if (m_name)
         {
-            lua_pushstring(m_state, m_name);
-            lua_gettable(m_state, LUA_GLOBALSINDEX);
+            lua_getglobal(m_state, m_name);
 
             if (!lua_istable(m_state, -1))
             {
                 lua_pop(m_state, 1);
 
                 lua_newtable(m_state);
-                lua_pushstring(m_state, m_name);
-                lua_pushvalue(m_state, -2);
-                lua_settable(m_state, LUA_GLOBALSINDEX);
+                lua_pushvalue(m_state, -1);
+                lua_setglobal(m_state, m_name);
             }
         }
         else
         {
+#ifdef LUA_GLOBALSINDEX
             lua_pushvalue(m_state, LUA_GLOBALSINDEX);
+#else
+            lua_rawgeti(m_state, LUA_REGISTRYINDEX,
+                    LUA_RIDX_GLOBALS);
+#endif
         }
 
         lua_pop_stack guard(m_state);