summarylogtreecommitdiffstats
path: root/003-luabind-use-lua_rawlen.patch
blob: 6a89638c93b73bcb6e2b326c677bcbe46e9ccb54 (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
From c6f38b86ce9593cacd73f359e68f3377cd71f053 Mon Sep 17 00:00:00 2001
From: Peter Colberg <peter.colberg@utoronto.ca>
Date: Wed, 21 Dec 2011 13:32:47 -0500
Subject: [PATCH] Lua 5.2: replace lua_strlen with lua_rawlen

lua_strlen was a macro for lua_objlen, which is superseded by lua_rawlen.

http://www.lua.org/manual/5.2/manual.html#8.3

This commit drops support for Lua 5.0, since Luabind is incompatible
with Lua 5.0 anyway, e.g. commit 7dc37f9 requires lua_Integer added
in Lua 5.1.
---
 luabind/detail/policy.hpp | 10 +++++++++-
 luabind/object.hpp        |  4 +++-
 src/class_rep.cpp         |  6 +++++-
 src/create_class.cpp      |  3 ++-
 4 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/luabind/detail/policy.hpp b/luabind/detail/policy.hpp
index 689c733..bd0feec 100644
--- a/luabind/detail/policy.hpp
+++ b/luabind/detail/policy.hpp
@@ -66,6 +66,10 @@
 #include <luabind/from_stack.hpp>
 #include <luabind/typeid.hpp>
 
+#if LUA_VERSION_NUM < 502
+# define lua_rawlen lua_objlen
+#endif
+
 namespace luabind
 {
 	namespace detail
@@ -745,7 +749,7 @@ struct default_converter<std::string>
 
     std::string from(lua_State* L, int index)
     {
-        return std::string(lua_tostring(L, index), lua_strlen(L, index));
+        return std::string(lua_tostring(L, index), lua_rawlen(L, index));
     }
 
     void to(lua_State* L, std::string const& value)
@@ -1017,5 +1021,9 @@ struct default_converter<lua_State*>
 #endif
 }}
 
+#if LUA_VERSION_NUM < 502
+# undef lua_rawlen
+#endif
+
 #endif // LUABIND_POLICY_HPP_INCLUDED
 
diff --git a/luabind/object.hpp b/luabind/object.hpp
index 698d236..4c877b9 100644
--- a/luabind/object.hpp
+++ b/luabind/object.hpp
@@ -49,6 +49,7 @@
 # define lua_compare(L, index1, index2, fn) fn(L, index1, index2)
 # define LUA_OPEQ lua_equal
 # define LUA_OPLT lua_lessthan
+# define lua_rawlen lua_objlen
 #endif
 
 namespace luabind {
@@ -231,7 +232,7 @@
       value_wrapper_traits<ValueWrapper>::unwrap(interpreter
         , static_cast<ValueWrapper const&>(v));
 		char const* p = lua_tostring(interpreter, -1);
-        std::size_t len = lua_strlen(interpreter, -1);
+        std::size_t len = lua_rawlen(interpreter, -1);
 		std::copy(p, p + len, std::ostream_iterator<char>(os));
 		return os;
 	}
@@ -1420,6 +1421,7 @@ object property(GetValueWrapper const& get, SetValueWrapper const& set)
 # undef lua_compare
 # undef LUA_OPEQ
 # undef LUA_OPLT
+# undef lua_rawlen
 #endif
 
 #endif // LUABIND_OBJECT_050419_HPP
diff --git a/src/class_rep.cpp b/src/class_rep.cpp
index 5f03f39..23c58b3 100755
--- a/src/class_rep.cpp
+++ b/src/class_rep.cpp
@@ -31,6 +31,10 @@
 #include <luabind/get_main_thread.hpp>
 #include <utility>
 
+#if LUA_VERSION_NUM < 502
+# define lua_rawlen lua_objlen
+#endif
+
 using namespace luabind::detail;
 
 namespace luabind { namespace detail
@@ -287,7 +291,7 @@ int luabind::detail::class_rep::static_class_gettable(lua_State* L)
 
 	const char* key = lua_tostring(L, 2);
 
-	if (std::strlen(key) != lua_strlen(L, 2))
+	if (std::strlen(key) != lua_rawlen(L, 2))
 	{
 		lua_pushnil(L);
 		return 1;
diff --git a/src/create_class.cpp b/src/create_class.cpp
index 738cf9b..7bce6dd 100755
--- a/src/create_class.cpp
+++ b/src/create_class.cpp
@@ -29,6 +29,7 @@
 #if LUA_VERSION_NUM < 502
 # define lua_compare(L, index1, index2, fn) fn(L, index1, index2)
 # define LUA_OPEQ lua_equal
+# define lua_rawlen lua_objlen
 #endif
 
 namespace luabind { namespace detail
@@ -117,7 +118,7 @@
 			lua_error(L);
 		}
 
-		if (std::strlen(lua_tostring(L, 1)) != lua_strlen(L, 1))
+		if (std::strlen(lua_tostring(L, 1)) != lua_rawlen(L, 1))
 		{
 			lua_pushstring(L, "luabind does not support class names with extra nulls");
 			lua_error(L);
-- 
1.8.1.6