소스 검색

Work around missing 'luaL_setmetatable' in Lua <= 5.1

Ole 10 년 전
부모
커밋
df2ae8721e
2개의 변경된 파일16개의 추가작업 그리고 1개의 파일을 삭제
  1. 15 0
      lib/luwra/auxiliary.hpp
  2. 1 1
      lib/luwra/usertypes.hpp

+ 15 - 0
lib/luwra/auxiliary.hpp

@@ -30,6 +30,21 @@ bool equal(State* state, int index1, int index2) {
 #endif
 }
 
+/**
+ * A registered metatable for the value on top of the stack.
+ * \param state Lua state
+ * \param name  Metatable name
+ */
+static inline
+void setMetatable(State* state, const char* name) {
+#if LUA_VERSION_NUM <= 501
+	luaL_getmetatable(state, name);
+	lua_setmetatable(state, -2);
+#else
+	luaL_setmetatable(state, name);
+#endif
+}
+
 /**
  * Register a value as a global.
  * \param state Lua state

+ 1 - 1
lib/luwra/usertypes.hpp

@@ -67,7 +67,7 @@ namespace internal {
 	 */
 	template <typename U> static inline
 	void apply_user_type_meta_table(State* state) {
-		luaL_setmetatable(state, UserTypeReg<StripUserType<U>>::name.c_str());
+		setMetatable(state, UserTypeReg<StripUserType<U>>::name.c_str());
 	}
 
 	/**