From 748ad97ef02fa9ff4c0e97d6546864f75f0b4753 Mon Sep 17 00:00:00 2001 From: Boris Nagaev Date: Fri, 5 Dec 2014 15:22:14 +0300 Subject: fix luabind close #570 --- src/luabind-6-iterator-equality.patch | 85 +++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 src/luabind-6-iterator-equality.patch 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 +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 dereference() const + { + return adl::iterator_proxy(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 const& x \ +- , basic_iterator const& y) \ +- { \ +- return boost::operator op(x, y); \ +- } \ +- \ +- inline bool operator op( \ +- basic_iterator const& x \ +- , basic_iterator const& y) \ +- { \ +- return boost::operator op(x, y); \ ++ inline bool operator ==( ++ basic_iterator const& x ++ , basic_iterator const& y) ++ { ++ return x.equal(y); ++ } ++ ++ inline bool operator ==( ++ basic_iterator const& x ++ , basic_iterator const& y) ++ { ++ return x.equal(y); + } + +- LUABIND_OPERATOR_ADL_WKND(==) +- LUABIND_OPERATOR_ADL_WKND(!=) ++ inline bool operator !=( ++ basic_iterator const& x ++ , basic_iterator const& y) ++ { ++ return !(x.equal(y)); ++ } ++ ++ inline bool operator !=( ++ basic_iterator const& x ++ , basic_iterator const& y) ++ { ++ return !(x.equal(y)); ++ } + +-#undef LUABIND_OPERATOR_ADL_WKND +- + } // namespace detail + + namespace adl +-- +1.7.10.4 + -- cgit v0.12 From bba46dda8b3ca1491775cd6abd06b7c622fbd20a Mon Sep 17 00:00:00 2001 From: Boris Nagaev Date: Sat, 6 Dec 2014 18:47:57 +0300 Subject: luabind-test: test class binding --- src/luabind-test.cpp | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/luabind-test.cpp b/src/luabind-test.cpp index 45efb3d..0df7f19 100644 --- a/src/luabind-test.cpp +++ b/src/luabind-test.cpp @@ -1,4 +1,6 @@ #include +#include + #include #include @@ -7,6 +9,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 +31,10 @@ extern "C" int init(lua_State* L) module(L) [ - def("greet", &greet) + def("greet", &greet), + class_("Test") + .def(constructor()) + .def("name", &Test::name) ]; return 0; @@ -26,4 +45,5 @@ int main() lua_State* L = luaL_newstate(); init(L); luaL_dostring(L, "greet()"); + luaL_dostring(L, "t = Test('123'); assert(t:name() == '123'"); } -- cgit v0.12 From 600fc832c0d0dbd950442b4e36ef1ecfe23d8346 Mon Sep 17 00:00:00 2001 From: Boris Nagaev Date: Sat, 6 Dec 2014 21:59:05 +0300 Subject: luabind: test iterating list of numbers --- src/luabind-test.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/luabind-test.cpp b/src/luabind-test.cpp index 0df7f19..bbb4f2a 100644 --- a/src/luabind-test.cpp +++ b/src/luabind-test.cpp @@ -1,3 +1,4 @@ +#include #include #include @@ -44,6 +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(item); + } + assert(sum == 6); } -- cgit v0.12