diff options
author | Timothy Gu <timothygu99@gmail.com> | 2014-12-06 22:23:14 (GMT) |
---|---|---|
committer | Timothy Gu <timothygu99@gmail.com> | 2014-12-06 22:23:14 (GMT) |
commit | c85476ccd45ada1d593cc56180242006dd063794 (patch) | |
tree | 96453e9fd9189d7d0eea95f01d4127ce7b3d162e | |
parent | 3aeb6a04af05c2a746e604c9d20809227ba31a62 (diff) | |
parent | 600fc832c0d0dbd950442b4e36ef1ecfe23d8346 (diff) | |
download | mxe-c85476ccd45ada1d593cc56180242006dd063794.zip mxe-c85476ccd45ada1d593cc56180242006dd063794.tar.gz mxe-c85476ccd45ada1d593cc56180242006dd063794.tar.bz2 |
Merge pull request #577 from starius/master
fix luabind for MinGW-w64
-rw-r--r-- | src/luabind-6-iterator-equality.patch | 85 | ||||
-rw-r--r-- | src/luabind-test.cpp | 36 |
2 files changed, 120 insertions, 1 deletions
diff --git a/src/luabind-6-iterator-equality.patch b/src/luabind-6-iterator-equality.patch new file mode 100644 index 0000000..843276b --- /dev/null +++ b/src/luabind-6-iterator-equality.patch @@ -0,0 +1,85 @@ +From c7e9fd61a8b928ca570b73fa6fa23cd68fefc61e Mon Sep 17 00:00:00 2001 +From: Boris Nagaev <bnagaev@gmail.com> +Date: Fri, 5 Dec 2014 14:36:52 +0300 +Subject: [PATCH] fix luabind::detail::basic_iterator == and != + +MinGW-w64, boost 1.57 +--- + luabind/object.hpp | 44 +++++++++++++++++++++++++++----------------- + 1 file changed, 27 insertions(+), 17 deletions(-) + +diff --git a/luabind/object.hpp b/luabind/object.hpp +index b288171..4ba0519 100644 +--- a/luabind/object.hpp ++++ b/luabind/object.hpp +@@ -512,6 +512,7 @@ namespace detail + } + } + ++ public: + bool equal(basic_iterator const& other) const + { + if (m_interpreter == 0 && other.m_interpreter == 0) +@@ -526,6 +527,7 @@ namespace detail + return lua_equal(m_interpreter, -2, -1) != 0; + } + ++ private: + adl::iterator_proxy<AccessPolicy> dereference() const + { + return adl::iterator_proxy<AccessPolicy>(m_interpreter, m_table, m_key); +@@ -538,26 +540,34 @@ namespace detail + + // Needed because of some strange ADL issues. + +-#define LUABIND_OPERATOR_ADL_WKND(op) \ +- inline bool operator op( \ +- basic_iterator<basic_access> const& x \ +- , basic_iterator<basic_access> const& y) \ +- { \ +- return boost::operator op(x, y); \ +- } \ +- \ +- inline bool operator op( \ +- basic_iterator<raw_access> const& x \ +- , basic_iterator<raw_access> const& y) \ +- { \ +- return boost::operator op(x, y); \ ++ inline bool operator ==( ++ basic_iterator<basic_access> const& x ++ , basic_iterator<basic_access> const& y) ++ { ++ return x.equal(y); ++ } ++ ++ inline bool operator ==( ++ basic_iterator<raw_access> const& x ++ , basic_iterator<raw_access> const& y) ++ { ++ return x.equal(y); + } + +- LUABIND_OPERATOR_ADL_WKND(==) +- LUABIND_OPERATOR_ADL_WKND(!=) ++ inline bool operator !=( ++ basic_iterator<basic_access> const& x ++ , basic_iterator<basic_access> const& y) ++ { ++ return !(x.equal(y)); ++ } ++ ++ inline bool operator !=( ++ basic_iterator<raw_access> const& x ++ , basic_iterator<raw_access> const& y) ++ { ++ return !(x.equal(y)); ++ } + +-#undef LUABIND_OPERATOR_ADL_WKND +- + } // namespace detail + + namespace adl +-- +1.7.10.4 + diff --git a/src/luabind-test.cpp b/src/luabind-test.cpp index 45efb3d..bbb4f2a 100644 --- a/src/luabind-test.cpp +++ b/src/luabind-test.cpp @@ -1,4 +1,7 @@ +#include <cassert> #include <iostream> +#include <string> + #include <luabind/luabind.hpp> #include <lua.hpp> @@ -7,6 +10,20 @@ void greet() std::cout << "hello world!\n"; } +class Test { +public: + Test(std::string name): + name_(name) { + } + + std::string name() const { + return name_; + } + +private: + std::string name_; +}; + extern "C" int init(lua_State* L) { using namespace luabind; @@ -15,7 +32,10 @@ extern "C" int init(lua_State* L) module(L) [ - def("greet", &greet) + def("greet", &greet), + class_<Test>("Test") + .def(constructor<std::string>()) + .def("name", &Test::name) ]; return 0; @@ -25,5 +45,19 @@ int main() { lua_State* L = luaL_newstate(); init(L); + // hello world luaL_dostring(L, "greet()"); + // class + luaL_dostring(L, "t = Test('123'); assert(t:name() == '123'"); + // iterate Lua table in C++ + luaL_dostring(L, "list123 = {1, 2, 3}"); + int sum = 0; + lua_getglobal(L, "list123"); + luabind::object list123(luabind::from_stack(L, -1)); + lua_pop(L, 1); + for (luabind::iterator it(list123), end; it != end; ++it) { + luabind::object item = *it; + sum += luabind::object_cast<int>(item); + } + assert(sum == 6); } |