Преглед изворни кода

Fix compatibility issue for Lua 5.1

Ole пре 9 година
родитељ
комит
44a7f57dc4
2 измењених фајлова са 16 додато и 2 уклоњено
  1. 2 2
      lib/luwra/state.hpp
  2. 14 0
      lib/luwra/tables.hpp

+ 2 - 2
lib/luwra/state.hpp

@@ -28,7 +28,7 @@ struct StateWrapper: Table {
 	 */
 	inline
 	StateWrapper(State* state):
-		Table({state, LUA_RIDX_GLOBALS, false}),
+		Table(getGlobalsTable(state)),
 		state(state),
 		close_state(false)
 	{}
@@ -38,7 +38,7 @@ struct StateWrapper: Table {
 	 */
 	inline
 	StateWrapper():
-		Table({luaL_newstate(), LUA_RIDX_GLOBALS, false}),
+		Table(getGlobalsTable(luaL_newstate())),
 		state(ref.impl->state),
 		close_state(true)
 	{}

+ 14 - 0
lib/luwra/tables.hpp

@@ -145,6 +145,20 @@ struct Value<Table> {
 	}
 };
 
+/**
+ * Retrieve the table containing all global values.
+ * \param state Lua state
+ * \returns Reference to the globals table.
+ */
+static inline
+Table getGlobalsTable(State* state) {
+#if LUA_VERSION_NUM <= 501
+	return {state, LUA_GLOBALSINDEX};
+#else
+	return {{state, LUA_RIDX_GLOBALS, false}};
+#endif
+}
+
 LUWRA_NS_END
 
 #endif