From 91ffce574dad5e45a16bb2a1c3e684cdeb213193 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Mon, 12 May 2003 20:02:16 +0000 Subject: [PATCH] updated the examples to work among other things --- config | 8 +-- examples/any_converter/makefile | 3 +- examples/cln/cln_test.cpp | 8 ++- examples/cln/makefile | 4 +- examples/glut/glut_bind.cpp | 1 - examples/glut/makefile | 7 ++- examples/intrusive_ptr/intrusive_ptr.cpp | 4 +- examples/intrusive_ptr/makefile | 6 +-- examples/regexp/makefile | 4 +- examples/regexp/regex_wrap.cpp | 6 ++- luabind/class.hpp | 87 ++++++++------------------------ luabind/function.hpp | 4 +- luabind/scope.hpp | 45 ++++++++++++++++- test/makefile | 2 +- test/test_attributes.cpp | 6 ++- test/test_const.cpp | 6 ++- test/test_construction.cpp | 12 +++-- test/test_exceptions.cpp | 6 ++- test/test_free_functions.cpp | 6 ++- test/test_held_type.cpp | 3 +- test/test_implicit_cast.cpp | 17 ++++--- test/test_iterator.cpp | 3 +- test/test_lua_classes.cpp | 10 ++-- test/test_null_pointer.cpp | 6 ++- test/test_object.cpp | 3 +- test/test_operators.cpp | 15 ++++-- test/test_policies.cpp | 3 +- test/test_scope.cpp | 18 +++++-- test/test_yield.cpp | 24 ++++++--- 29 files changed, 192 insertions(+), 135 deletions(-) rewrite examples/glut/makefile (79%) diff --git a/config b/config index 5a3ebce..09e802c 100644 --- a/config +++ b/config @@ -4,8 +4,8 @@ #CONFIG = \ # -DLUABIND_DONT_COPY_STRINGS \ # -DLUABIND_NO_EXCEPTIONS \ -# -DLUABIND_NO_ERROR_CHECKING - +# -DLUABIND_NO_ERROR_CHECKING \ +# -DNDEBUG # if boost and lua are installed in system # include paths, you don't have to set these @@ -13,8 +13,10 @@ #BOOST_PATH = -I/scratch/boost_1_30_0 #LUA_PATH = -I/scratch/lua-5.0/include -#LUA_LIB_PATH = -L/scratch/lua-5.0/lib +#lua lib path is used for the test program + +#LUA_LIB_PATH = -L/scratch/lua-5.0/lib LUA_LIB_PATH = -L/usr/local/lib CXX = g++ diff --git a/examples/any_converter/makefile b/examples/any_converter/makefile index 26a02d3..47038c0 100644 --- a/examples/any_converter/makefile +++ b/examples/any_converter/makefile @@ -1,4 +1,3 @@ any_converter: any_converter.cpp - g++ any_converter.cpp -O3 -o any_converter -I- -I../../ -ftemplate-depth-50 -L/usr/local/lib -llua -llualib -L../../src -lluabind -# g++ any_converter.cpp -g -o any_converter -I- -I../../ -I/scratch/lua-5.0/include -I/scratch/boost_1_30_0 -ftemplate-depth-50 -L/scratch/lua-5.0/lib -llua -llualib + g++ any_converter.cpp -O3 -o any_converter -I- -I../../ -ftemplate-depth-50 -L../../lib -L/usr/local/lib -lluabind -llua -llualib diff --git a/examples/cln/cln_test.cpp b/examples/cln/cln_test.cpp index c6c3877..48cfe73 100644 --- a/examples/cln/cln_test.cpp +++ b/examples/cln/cln_test.cpp @@ -2,13 +2,11 @@ #include -#define LUABIND_DONT_COPY_STRINGS -//#define LUABIND_NO_ERROR_CHECKING - extern "C" { -#include "lua.h" -#include "lualib.h" + #include "lua.h" + #include "lualib.h" + #include "lauxlib.h" } #include diff --git a/examples/cln/makefile b/examples/cln/makefile index 96d2744..9003a7f 100644 --- a/examples/cln/makefile +++ b/examples/cln/makefile @@ -1,3 +1,5 @@ +include ../../config + cln_test: cln_test.cpp - g++ -g cln_test.cpp -o cln_test -I- -I../../ -ftemplate-depth-50 -llua -llualib -lcln -L/usr/local/lib + g++ cln_test.cpp -o cln_test $(LUA_PATH) -I- $(BOOST_PATH) -I../../ $(LUA_LIB_PATH) -L../../lib -lluabind -llua -llualib -lcln diff --git a/examples/glut/glut_bind.cpp b/examples/glut/glut_bind.cpp index 05ffa7b..705a1f7 100644 --- a/examples/glut/glut_bind.cpp +++ b/examples/glut/glut_bind.cpp @@ -5,7 +5,6 @@ extern "C" #include "lualib.h" } - #include #include #include diff --git a/examples/glut/makefile b/examples/glut/makefile dissimilarity index 79% index 523dff0..0777ab5 100644 --- a/examples/glut/makefile +++ b/examples/glut/makefile @@ -1,4 +1,3 @@ -glut_test: glut_bind.cpp - g++ glut_bind.cpp -o glut_bind -I- -I../../ -ftemplate-depth-50 -I/usr/X11R6/include -L/usr/X11R6/lib -L/usr/local/lib -lX11 -lXi -lXmu -lglut -lGL -lGLU -lm -llua -llualib -# g++ glut_bind.cpp -g -o glut_bind -I- -I../../ -I/scratch/lua-5.0-beta/include -I/scratch/boost_1_30_0 -ftemplate-depth-50 -I/usr/X11R6/include -L/usr/X11R6/lib -L/scratch/lua-5.0-beta/lib -lX11 -lXi -lXmu -lglut -lGL -lGLU -lm -llua -llualib - +glut_test: glut_bind.cpp + g++ glut_bind.cpp -o glut_bind -I- -I../../ -ftemplate-depth-50 -I/usr/X11R6/include -L/usr/X11R6/lib -L/usr/local/lib -L../../lib -lluabind -lX11 -lXi -lXmu -lglut -lGL -lGLU -lm -llua -llualib + diff --git a/examples/intrusive_ptr/intrusive_ptr.cpp b/examples/intrusive_ptr/intrusive_ptr.cpp index db64503..5bd8525 100644 --- a/examples/intrusive_ptr/intrusive_ptr.cpp +++ b/examples/intrusive_ptr/intrusive_ptr.cpp @@ -58,7 +58,9 @@ namespace luabind intrusive_ptr_add_ref(raw_ptr); detail::class_registry* registry = luabind::detail::class_registry::get_registry(L); - detail::class_rep* crep = registry->classes[LUABIND_TYPEID(T)]; + detail::class_rep* crep = registry->find_class(LUABIND_TYPEID(T)); + + assert(crep != 0 && "You are trying to convert an unregistered type"); // create the struct to hold the object void* obj = lua_newuserdata(L, sizeof(detail::object_rep)); diff --git a/examples/intrusive_ptr/makefile b/examples/intrusive_ptr/makefile index 1e106f0..c365b5d 100644 --- a/examples/intrusive_ptr/makefile +++ b/examples/intrusive_ptr/makefile @@ -1,4 +1,4 @@ -intrusive_ptr: intrusive_ptr.cpp - g++ intrusive_ptr.cpp -o intrusive_ptr -I- -I../../ -ftemplate-depth-50 -L/usr/local/lib -llua -llualib -# g++ intrusive_ptr.cpp -g -o intrusive_ptr -I- -I../../ -I/scratch/lua-5.0/include -I/scratch/boost_1_30_0 -ftemplate-depth-50 -L/scratch/lua-5.0/lib -llua -llualib +include ../../config +intrusive_ptr: intrusive_ptr.cpp + $(CXX) intrusive_ptr.cpp -o intrusive_ptr $(LUA_PATH) -I- $(BOOST_PATH) -I../../ -L../../lib $(LUA_LIB_PATH) -lluabind -llua -llualib diff --git a/examples/regexp/makefile b/examples/regexp/makefile index 02168f6..a680764 100644 --- a/examples/regexp/makefile +++ b/examples/regexp/makefile @@ -1,3 +1,5 @@ +include ../../config + regexp: regex_wrap.cpp - g++ regex_wrap.cpp -o regex_wrap -I- -I../../ -ftemplate-depth-50 -L/usr/local/lib -lboost -llua -llualib + g++ regex_wrap.cpp -o regex_wrap $(LUA_PATH) -I- $(BOOST_PATH) -I../../ -L../../lib $(LUA_LIB_PATH) -lluabind -lboost_regex -llua -llualib diff --git a/examples/regexp/regex_wrap.cpp b/examples/regexp/regex_wrap.cpp index 54afe91..a107240 100644 --- a/examples/regexp/regex_wrap.cpp +++ b/examples/regexp/regex_wrap.cpp @@ -1,13 +1,15 @@ #include -#include - extern "C" { + #include "lua.h" #include "lauxlib.h" #include "lualib.h" } +#include + + void wrap_regex(lua_State* L) { using boost::RegEx; diff --git a/luabind/class.hpp b/luabind/class.hpp index 9e2fa46..0dc354f 100644 --- a/luabind/class.hpp +++ b/luabind/class.hpp @@ -25,14 +25,8 @@ #define LUABIND_CLASS_HPP_INCLUDED /* - Issues: - ------- - * done * - move all exceptions to the exception.hpp header - - * done * - Since functions can be overridden, the constness of the member functions - must be taken into account. + ISSUES: + ------------------------------------------------------ * solved for member functions, not application operator * if we have a base class that defines a function a derived class must be able to @@ -53,52 +47,28 @@ defined by the base class, it is a legal operation, to override it. we cannot look at the pointer offset, since it always will be zero for one of the bases. - * done * - We do not currently run unwrap_other<> on the parameters given to the application - operators when we register them. - - * done * - if the first matched binary operator does not match the parameters we have to manually - check if the right parameter has a matching operator. - - * I think this is resolved * - There is currently a restriction that operators must take their parameters as const references - or as copies. This could be solved by specifying special wrapper types for const references and - non-const references. Binary operators shouldn't implicitly convert it's parameters to const&. - * done * - The application operator do not currently work on const objects. Again, to solve this we need - some kind of wrapper to say that the self object is const. - - Make sure we don't have any memory leaks when we use lua_error() - - We should avoid names that begins with lua_ (in our own scopes) since the lua distribution - have plenty of defines with that prefix. - Optimize by calling lua_rawset/get instead of lua_settable/gettable + TODO: + ------------------------------------------------------ - * done * - use ordinary function pointers instead of boost::function. - the boost::function is only used on member functions now, We have to use it in order - to support free functions as member functions. + add access to the keys on iterators - * solved * - when we register classes we should import all methods and properties - from the base classes into the class. We will then need to offset the object pointer - on a per method/property basis. This will allow methods from the base class to be - overloaded without shadowing the base class. The method lookup will also be - more efficient. + finish scopes - remove methods from methodtable of classrep when overloading them in lua + finish smart pointer support - * done * - we currently set uninitialized references to -1, they should be set to LUA_NOREF! + chache operators and finalizers in the class_rep. For lua classes + we currently do a lookup each time we need to know if a lua class + has a finalizer or an operator. - * done * - the error exception class should avoid heap allocations + instead of registering the name of free functions and make a lookup in + the register to see if we are overloading, look in the actual namespace + where we are registering the function to see if there already is a function + with the same name there, and in that case, add an overload to it. - Todo: - ----- + static functions, this could be implemented by letting classes contain + other declarations (classes or functions) document custom policies, custom converters @@ -107,18 +77,7 @@ support the __concat metamethod. This is a bit tricky, since it cannot be treated as a normal operator. It is a binary operator but we want to use the __tostring implementation for both arguments. - - smart pointer support - - chache operators and finalizers in the class_rep. For lua classes - we currently do a lookup each time we need to know if a lua class - has a finalizer or an operator. - scopes - - static functions, this could be implemented by letting classes contain - other declarations (classes or functions) - */ #include @@ -553,6 +512,8 @@ namespace luabind // pushes the class_rep on the lua stack virtual void commit(lua_State* L) { + assert(!m_cloned && "class already commited"); + scope::init(L); detail::getref(L, scope_stack::top(L)); @@ -670,10 +631,10 @@ namespace luabind { typedef class_ self_t; - private: - lua_State* m_L; + private: + template class_(const class_&); @@ -810,18 +771,14 @@ namespace luabind } }; - - class_(lua_State* L_, const char* name): class_base(name), m_L(L_) { init(); } + class_(lua_State* L, const char* name): class_base(name), m_L(L) { init(); } class_(const char* name): class_base(name), m_L(0) { init(); } - // TODO: we sould probably commit the object someplace else ~class_() { - if (m_L) + if (m_L != 0) { - // lua_pushstring(m_L, name()); commit(m_L); - // lua_settable(m_L, LUA_GLOBALSINDEX); } } diff --git a/luabind/function.hpp b/luabind/function.hpp index 3c00741..91480c0 100644 --- a/luabind/function.hpp +++ b/luabind/function.hpp @@ -23,8 +23,8 @@ #if !BOOST_PP_IS_ITERATING -#ifndef LUABIND_FUNCTIONS_HPP_INCLUDED -#define LUABIND_FUNCTIONS_HPP_INCLUDED +#ifndef LUABIND_FUNCTION_HPP_INCLUDED +#define LUABIND_FUNCTION_HPP_INCLUDED #include diff --git a/luabind/scope.hpp b/luabind/scope.hpp index 66410b4..fac0d1a 100755 --- a/luabind/scope.hpp +++ b/luabind/scope.hpp @@ -54,11 +54,19 @@ namespace luabind { scoped_sequence(scoped_object* a, scoped_object* b) { +#ifndef NDEBUG + m_cloned = false; +#endif this->objects.push_back(a); this->objects.push_back(b); } - scoped_sequence() {} + scoped_sequence() + { +#ifndef NDEBUG + m_cloned = false; +#endif + } virtual ~scoped_sequence() { @@ -82,11 +90,18 @@ namespace luabind { scoped_sequence* copy = new scoped_sequence(); copy->objects.swap(this->objects); + + assert(!m_cloned && "You cannot register the scoped_object twice"); +#ifndef NDEBUG + m_cloned = true; +#endif return copy; } virtual void commit(lua_State* L) { + assert(!m_cloned && "You cannot register the scoped_object twice"); + for (std::vector ::const_iterator i = this->objects.begin() ; i != this->objects.end() @@ -95,15 +110,25 @@ namespace luabind scoped_object* ptr = *i; ptr->commit(L); } +#ifndef NDEBUG + m_cloned = false; +#endif + } + private: +#ifndef NDEBUG + bool m_cloned; +#endif mutable std::vector objects; + }; inline scoped_sequence scoped_object::operator,(const scoped_object& rhs) const { return scoped_sequence(const_cast(this)->clone(), const_cast(rhs).clone()); } + } struct scope_stack @@ -217,6 +242,9 @@ namespace luabind : m_state(L) , m_name(name) { +#ifndef NDEBUG + m_cloned = false; +#endif init(L); } @@ -224,6 +252,9 @@ namespace luabind : m_state(0) , m_name(name) { +#ifndef NDEBUG + m_cloned = false; +#endif } virtual ~scope() @@ -263,6 +294,10 @@ namespace luabind virtual detail::scoped_object* clone() { + assert(!m_cloned && "cannot register the same namespace twice"); +#ifndef NDEBUG + m_cloned = true; +#endif std::vector tmp; tmp.swap(this->m_children); scope* copy = new scope(m_name.c_str()); @@ -272,6 +307,10 @@ namespace luabind virtual void commit(lua_State* L) { + assert(!m_cloned && "cannot register the same namespace twice"); +#ifndef NDEBUG + m_cloned = true; +#endif init(L); detail::getref(L, scope_stack::top(L)); // get current scope @@ -306,7 +345,9 @@ namespace luabind } private: - +#ifndef NDEBUG + bool m_cloned; +#endif mutable std::vector m_children; lua_State* m_state; std::string m_name; diff --git a/test/makefile b/test/makefile index b873712..03ca7e8 100644 --- a/test/makefile +++ b/test/makefile @@ -29,7 +29,7 @@ OBJECTS = $(SOURCES:.cpp=.o) all: $(TARGET) $(TARGET): $(OBJECTS) - $(CXX) -O3 $? $(LUA_LIB_PATH) -L../lib -lluabind -llua -llualib -o $@ + $(CXX) -O3 $(OBJECTS) $(LUA_LIB_PATH) -L../lib -lluabind -llua -llualib -o $@ %.o:%.cpp $(CXX) -Wall -ftemplate-depth-50 -O3 $(CONFIG) $(LUA_PATH) -I. -I- -I../ $(BOOST_PATH) -c $? -o $@ diff --git a/test/test_attributes.cpp b/test/test_attributes.cpp index 4df7b07..85961ca 100644 --- a/test/test_attributes.cpp +++ b/test/test_attributes.cpp @@ -73,11 +73,12 @@ bool test_attributes() lua_pushcfunction(L, tester); lua_settable(L, LUA_GLOBALSINDEX); - luabind::class_(L, "internal") + luabind::class_("internal") .def_readonly("name", &internal::name_) + .commit(L) ; - luabind::class_(L, "property") + luabind::class_("property") .def(luabind::constructor<>()) .def("get", &property_test::get) .def("get_name", &property_test::get_name) @@ -87,6 +88,7 @@ bool test_attributes() //#ifndef BOOST_MSVC .property("internal", &property_test::get_internal, luabind::dependency(luabind::result, luabind::self)) //#endif + .commit(L) ; if (dostring(L, "test = property()")) return false; diff --git a/test/test_const.cpp b/test/test_const.cpp index 76e87aa..7b2b92b 100644 --- a/test/test_const.cpp +++ b/test/test_const.cpp @@ -30,11 +30,13 @@ bool test_const() g1_t g1 = &A::g; g2_t g2 = &A::g; - class_(L, "A") + class_("A") .def(constructor<>()) .def("f", &A::f) .def("g", /*(void(A::*)() const) &A::g*/ g1) - .def("g", /*(void(A::*)()) &A::g*/ g2); + .def("g", /*(void(A::*)()) &A::g*/ g2) + .commit(L) + ; if (dostring(L, "a = A()")) return false; if (dostring(L, "a:g()")) return false; diff --git a/test/test_construction.cpp b/test/test_construction.cpp index 9c0ed7d..e687c8a 100644 --- a/test/test_construction.cpp +++ b/test/test_construction.cpp @@ -35,15 +35,19 @@ bool test_construction() open(L); - class_(L, "A") + class_("A") .def("f", &f) .def(constructor()) .def(constructor()) - .def(constructor<>()); + .def(constructor<>()) + .commit(L) + ; - class_(L, "B") + class_("B") .def(constructor()) - .def(constructor<>()); + .def(constructor<>()) + .commit(L) + ; if (dostring(L, "a = A(4)")) return false; if (feedback != 4) return false; diff --git a/test/test_exceptions.cpp b/test/test_exceptions.cpp index f66eb2d..62b30c1 100644 --- a/test/test_exceptions.cpp +++ b/test/test_exceptions.cpp @@ -35,14 +35,16 @@ bool test_exceptions() open(L); - class_(L, "exception_thrower") + class_("exception_thrower") .def(constructor<>()) .def(constructor()) .def(constructor()) .def(constructor()) .def("f", &exception_thrower::f) .def("g", &exception_thrower::g) - .def("h", &exception_thrower::h); + .def("h", &exception_thrower::h) + .commit(L) + ; if (dostring2(L, "a = exception_thrower(1)") != 1) throw 0; if (std::string("exception description") != lua_tostring(L, -1)) throw 0; diff --git a/test/test_free_functions.cpp b/test/test_free_functions.cpp index 6156cb7..dbce57d 100644 --- a/test/test_free_functions.cpp +++ b/test/test_free_functions.cpp @@ -89,12 +89,14 @@ bool test_free_functions() open(L); - class_(L, "copy_me") + class_("copy_me") .def(constructor<>()) + .commit(L) ; - class_(L, "base") + class_("base") .def("f", &base::f) + .commit(L) ; diff --git a/test/test_held_type.cpp b/test/test_held_type.cpp index 9b41d49..5d16156 100644 --- a/test/test_held_type.cpp +++ b/test/test_held_type.cpp @@ -45,8 +45,9 @@ bool test_held_type() function(L, "tester", &tester); - class_ >(L, "held_type_test") + class_ >("held_type_test") .def(constructor<>()) + .commit(L) ; object g = get_globals(L); diff --git a/test/test_implicit_cast.cpp b/test/test_implicit_cast.cpp index 2da3eda..dbc096b 100644 --- a/test/test_implicit_cast.cpp +++ b/test/test_implicit_cast.cpp @@ -25,19 +25,24 @@ bool test_implicit_cast() open(L); - class_(L, "A") - .def(constructor<>()); + class_("A") + .def(constructor<>()) + .commit(L) + ; - class_(L, "B") - .def(constructor<>()); + class_("B") + .def(constructor<>()) + .commit(L); typedef void (test_implicit::*f1)(A*); typedef void (test_implicit::*f2)(B*); - class_(L, "test") + class_("test") .def(constructor<>()) .def("f", (f1) &test_implicit::f) - .def("f", (f2) &test_implicit::f); + .def("f", (f2) &test_implicit::f) + .commit(L) + ; if (dostring(L, "a = A()")) return false; if (dostring(L, "b = B()")) return false; diff --git a/test/test_iterator.cpp b/test/test_iterator.cpp index d0ce6ba..bcc7359 100755 --- a/test/test_iterator.cpp +++ b/test/test_iterator.cpp @@ -37,9 +37,10 @@ bool test_iterator() open(L); - class_(L, "A") + class_("A") .def(constructor<>()) .def_readonly("names", &IteratorTest::names, return_stl_iterator) + .commit(L) ; dostring(L, "a = A()"); diff --git a/test/test_lua_classes.cpp b/test/test_lua_classes.cpp index faf7ed7..c13be6c 100644 --- a/test/test_lua_classes.cpp +++ b/test/test_lua_classes.cpp @@ -72,16 +72,20 @@ bool test_lua_classes() open(L); - class_(L, "no copy"); + class_("no copy") + .commit(L) + ; - class_(L, "base") + class_("base") .def(constructor<>()) .def("f", &baseWrap::fS) + .commit(L) ; - class_(L, "simple_class") + class_("simple_class") .def(constructor<>()) .def("f", &simple_class::f) + .commit(L) ; function(L, "set_feedback", &set_feedback); diff --git a/test/test_null_pointer.cpp b/test/test_null_pointer.cpp index 6fccbab..d703e32 100644 --- a/test/test_null_pointer.cpp +++ b/test/test_null_pointer.cpp @@ -26,9 +26,11 @@ bool test_null_pointer() open(L); - class_(L, "A") + class_("A") .def(constructor<>()) - .def("f", &A::f); + .def("f", &A::f) + .commit(L) + ; function(L, "get_pointer", get_pointer); if (dostring(L, "e = get_pointer()")) return false; diff --git a/test/test_object.cpp b/test/test_object.cpp index 4231d95..0191f7e 100644 --- a/test/test_object.cpp +++ b/test/test_object.cpp @@ -89,8 +89,9 @@ bool test_object() function(L, "test_fun", &test_fun); function(L, "test_match", (void(*)(const luabind::object&))&test_match); function(L, "test_match", (void(*)(int))&test_match); - class_(L, "test_param") + class_("test_param") .def(constructor<>()) + .commit(L) ; dostring(L, "t = 2"); diff --git a/test/test_operators.cpp b/test/test_operators.cpp index c91ee89..ae0e174 100644 --- a/test/test_operators.cpp +++ b/test/test_operators.cpp @@ -90,7 +90,7 @@ bool test_operators() if (feedback != 0) return false; - class_(L, "operator_tester") + class_("operator_tester") .def(constructor<>()) .def(tostring(const_self)) .def(self + int()) @@ -99,14 +99,19 @@ bool test_operators() .def(self()) .def(const_self(int())) .def(self(int())) + .commit(L) ; - class_(L, "operator_tester2") + class_("operator_tester2") .def(constructor<>()) - .def(other() + self); + .def(other() + self) + .commit(L) + ; - class_ >(L, "operator_tester3") - .def(constructor<>()); + class_ >("operator_tester3") + .def(constructor<>()) + .commit(L) + ; function(L, "make_const_test", &make_const_test); diff --git a/test/test_policies.cpp b/test/test_policies.cpp index 27e4a0e..7c7a589 100644 --- a/test/test_policies.cpp +++ b/test/test_policies.cpp @@ -62,12 +62,13 @@ bool test_policies() luabind::open(L); - class_(L, "test") + class_("test") .def(constructor<>()) .def("f", &policies_test_class::f, adopt(_1)) .def("make", &policies_test_class::make, adopt(return_value)) .def("internal_ref", &policies_test_class::internal_ref, dependency(return_value, self)) .def("self_ref", &policies_test_class::self_ref, return_reference_to(self)) + .commit(L) ; function(L, "out_val", &out_val, pure_out_value(_1)); diff --git a/test/test_scope.cpp b/test/test_scope.cpp index c02cf8a..2fdceba 100755 --- a/test/test_scope.cpp +++ b/test/test_scope.cpp @@ -10,6 +10,11 @@ namespace feedback = 123; } + void g() + { + feedback = 2; + } + struct test_class { test_class() @@ -17,8 +22,6 @@ namespace feedback = 321; } }; - - void g(test_class) {}; } bool test_scope() @@ -40,8 +43,13 @@ bool test_scope() value("val2", 2) ], - def("f", &f) -// def("g", &g, adopt(_1)) + def("f", &f), + + namespace_("inner") + [ + def("g", &g) + ] + ]; if (dostring(L, "test.f()")) return false; @@ -49,6 +57,8 @@ bool test_scope() if (dostring(L, "a = test.test_class()")) return false; if (feedback != 321) return false; if (dostring(L, "b = test.test_class.val2")) return false; + if (dostring(L, "test.inner.g()")) return false; + if (feedback != 2) return false; } return true; diff --git a/test/test_yield.cpp b/test/test_yield.cpp index 0f9ec6f..9c6e6f9 100755 --- a/test/test_yield.cpp +++ b/test/test_yield.cpp @@ -22,6 +22,8 @@ namespace lua_pushnumber(L, 9); return lua_yield(L, 1); } + + void f() {} } #include @@ -35,12 +37,22 @@ bool test_yield() lua_closer c(L); open(L); - - class_(L, "test") - .def(constructor<>()) - .property("f", &test_class::f, yield); - - dostring(L, "function g() a = test() for i = 1, 10 do print(a.f) end end"); +/* + namespace_(L, "namespace") + [ + namespace_("inner") + [ + ] + ]; +*/ + class_("test") + .def(constructor<>()) + .def("f", &test_class::f, yield) + .commit(L) + ; + + + dostring(L, "function g() a = test() for i = 1, 10 do print(a:f()) end end"); lua_pushstring(L, "j"); lua_pushcclosure(L, j, 0); -- 2.11.4.GIT