Bläddra i källkod

Add Lua 5.1 support on Linux

Ole 10 år sedan
förälder
incheckning
408e78f6d3
4 ändrade filer med 22 tillägg och 10 borttagningar
  1. 8 8
      README.md
  2. 1 1
      lib/luwra/common.hpp
  3. 12 0
      lib/luwra/stack.hpp
  4. 1 1
      tests/types.cpp

+ 8 - 8
README.md

@@ -6,15 +6,15 @@ A header-only C++ library which provides a Lua wrapper with minimal overhead.
 ## Requirements
 You need will need a C++14-compliant compiler and a compatible Lua version.
 
- Platform                                | Lua 5.1  | Lua 5.2 <sup>1)</sup> | Lua 5.3
------------------------------------------|----------|-----------------------|---------
- Linux (clang++ 3.6)                     | untested | works                 | works
- Linux (g++ 5.1)                         | untested | works                 | works
- FreeBSD <sup>2)</sup> (clang++ 3.6)     | untested | works                 | works
- FreeBSD <sup>2)</sup> (g++ 5.1)         | untested | works                 | works
- Everything else                         | untested | untested              | untested
+ Platform                                | Lua 5.1 <sup>1)</sup> | Lua 5.2 <sup>1)</sup> | Lua 5.3
+-----------------------------------------|-----------------------|-----------------------|---------
+ Linux (clang++ 3.6)                     | works                 | works                 | works
+ Linux (g++ 5.1)                         | works                 | works                 | works
+ FreeBSD <sup>2)</sup> (clang++ 3.6)     | untested              | works                 | works
+ FreeBSD <sup>2)</sup> (g++ 5.1)         | untested              | works                 | works
+ Everything else                         | untested              | untested              | untested
 
-<sup>**1)**</sup> Inherits the integer quirks that come with Lua 5.2, that why the `types_numeric`
+<sup>**1)**</sup> Inherits the integer quirks that come with Lua 5.1, that why the `types_numeric`
 test case fails.
 <sup>**2)**</sup> You need GNU make (devel/gmake) to use the attached Makefile.
 

+ 1 - 1
lib/luwra/common.hpp

@@ -15,7 +15,7 @@
 #include <lua.hpp>
 
 // Check for proper Lua version
-#if !defined(LUA_VERSION_NUM) || LUA_VERSION_NUM < 502 || LUA_VERSION_NUM >= 600
+#if !defined(LUA_VERSION_NUM) || LUA_VERSION_NUM < 501 || LUA_VERSION_NUM >= 600
 	#error Luwra has not been tested against your installed version of Lua
 #endif
 

+ 12 - 0
lib/luwra/stack.hpp

@@ -96,6 +96,18 @@ R apply(State* state, std::function<R(A...)> function_object) {
 	return apply(state, 1, function_object);
 }
 
+/**
+ * Check if two values are equal.
+ */
+static inline
+bool equal(State* state, int index1, int index2) {
+#if LUA_VERSION_NUM <= 501
+	return lua_equal(state, index1, index2);
+#else
+	return lua_compare(state, index1, index2, LUA_OPEQ);
+#endif
+}
+
 LUWRA_NS_END
 
 #endif

+ 1 - 1
tests/types.cpp

@@ -78,7 +78,7 @@ TEST_CASE("types_string") {
 	REQUIRE(luwra::Value<std::string>::push(state, test_str) == 1);
 
 	// They must be equal to Lua
-	REQUIRE(lua_compare(state, -1, -2, LUA_OPEQ));
+	REQUIRE(luwra::equal(state, -1, -2));
 
 	// Extraction as C string must not change the string's value
 	const char* l_cstr1 = luwra::Value<const char*>::read(state, -1);