luabind-cvs Mailing List for luabind (Page 3)
Brought to you by:
arvidn,
daniel_wallin
You can subscribe to this list here.
2005 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(7) |
Oct
(53) |
Nov
(13) |
Dec
(14) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2006 |
Jan
(15) |
Feb
(1) |
Mar
(6) |
Apr
|
May
(5) |
Jun
(7) |
Jul
(5) |
Aug
|
Sep
(2) |
Oct
(5) |
Nov
|
Dec
|
From: Arvid N. <ar...@us...> - 2005-12-22 03:07:09
|
Update of /cvsroot/luabind/luabind/luabind/doc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26306/luabind/doc Modified Files: docs.html out_value.rst pure_out_value.rst Log Message: added more documentation to out_value policy and pure_out_value policy Index: docs.html =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/doc/docs.html,v retrieving revision 1.53 retrieving revision 1.54 diff -u -d -r1.53 -r1.54 --- docs.html 28 Nov 2005 20:55:33 -0000 1.53 +++ docs.html 22 Dec 2005 03:06:54 -0000 1.54 @@ -7,7 +7,7 @@ <title>luabind</title> <meta name="author" content="Daniel Wallin, Arvid Norberg" /> <meta name="copyright" content="Copyright Daniel Wallin, Arvid Norberg 2003." /> -<meta name="date" content="2005-10-26" /> +<meta name="date" content="2005-11-28" /> <link rel="stylesheet" href="style.css" type="text/css" /> </head> <body> @@ -22,9 +22,9 @@ <tr><th class="docinfo-name">Copyright:</th> <td>Copyright Daniel Wallin, Arvid Norberg 2003.</td></tr> <tr><th class="docinfo-name">Date:</th> -<td>2005-10-26</td></tr> +<td>2005-11-28</td></tr> <tr><th class="docinfo-name">Revision:</th> -<td>1.25.2.13</td></tr> +<td>1.26</td></tr> <tr class="field"><th class="docinfo-name">License:</th><td class="field-body"><p class="first">Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation @@ -767,7 +767,7 @@ <p>There's one special operator. In Lua it's called <tt class="docutils literal"><span class="pre">__tostring</span></tt>, it's not really an operator. It is used for converting objects to strings in a standard way in Lua. If you register this functionality, you will be able to use the lua -standard function <tt class="docutils literal"><span class="pre">tostring()</span></tt> for converting you object to a string.</p> +standard function <tt class="docutils literal"><span class="pre">tostring()</span></tt> for converting your object to a string.</p> <p>To implement this operator in C++ you should supply an <tt class="docutils literal"><span class="pre">operator<<</span></tt> for std::ostream. Like this example:</p> <pre class="literal-block"> @@ -1671,7 +1671,7 @@ </ul> </div> <div class="section" id="adopt"> -<h2><a class="toc-backref" href="#id93" name="adopt">12.1 adopt</a></h2> +<h2><a name="adopt">12.1 adopt</a></h2> <div class="section" id="motivation"> <h3><a name="motivation">12.1.1 Motivation</a></h3> <p>Used to transfer ownership across language boundaries.</p> @@ -1725,7 +1725,7 @@ </div> </div> <div class="section" id="dependency"> -<h2><a class="toc-backref" href="#id94" name="dependency">12.2 dependency</a></h2> +<h2><a name="dependency">12.2 dependency</a></h2> <div class="section" id="id2"> <h3><a name="id2">12.2.1 Motivation</a></h3> <p>The dependency policy is used to create life-time dependencies between values. @@ -1783,12 +1783,16 @@ </div> </div> <div class="section" id="out-value"> -<h2><a class="toc-backref" href="#id95" name="out-value">12.3 out_value</a></h2> +<h2><a name="out-value">12.3 out_value</a></h2> <div class="section" id="id7"> <h3><a name="id7">12.3.1 Motivation</a></h3> <p>This policy makes it possible to wrap functions that take non-const references or pointer to non-const as it's parameters with the intention to write return -values to them.</p> +values to them. Since it's impossible to pass references to primitive types +in lua, this policy will add another return value with the value after the +call. If the function already has one return value, one instance of this +policy will add another return value (read about multiple return values in +the lua manual).</p> </div> <div class="section" id="id8"> <h3><a name="id8">12.3.2 Defined in</a></h3> @@ -1846,12 +1850,13 @@ </div> </div> <div class="section" id="pure-out-value"> -<h2><a class="toc-backref" href="#id96" name="pure-out-value">12.4 pure_out_value</a></h2> +<h2><a name="pure-out-value">12.4 pure_out_value</a></h2> <div class="section" id="id12"> <h3><a name="id12">12.4.1 Motivation</a></h3> <p>This works exactly like <tt class="docutils literal"><span class="pre">out_value</span></tt>, except that it will pass a default constructed object instead of converting an argument from -Lua.</p> +Lua. This means that the parameter will be removed from the lua +signature.</p> </div> <div class="section" id="id13"> <h3><a name="id13">12.4.2 Defined in</a></h3> @@ -1890,6 +1895,7 @@ </div> <div class="section" id="id16"> <h3><a name="id16">12.4.5 Example</a></h3> +<p>Note that no values are passed to the calls to <tt class="docutils literal"><span class="pre">f1</span></tt> and <tt class="docutils literal"><span class="pre">f2</span></tt>.</p> <pre class="literal-block"> void f1(float& val) { val = 10.f; } void f2(float* val) { *val = 10.f; } @@ -1908,7 +1914,7 @@ </div> </div> <div class="section" id="return-reference-to"> -<h2><a class="toc-backref" href="#id97" name="return-reference-to">12.5 return_reference_to</a></h2> +<h2><a name="return-reference-to">12.5 return_reference_to</a></h2> <div class="section" id="id17"> <h3><a name="id17">12.5.1 Motivation</a></h3> <p>It is very common to return references to arguments or the this-pointer to @@ -1992,7 +1998,7 @@ </div> </div> <div class="section" id="copy"> -<h2><a class="toc-backref" href="#id98" name="copy">12.6 copy</a></h2> +<h2><a name="copy">12.6 copy</a></h2> <div class="section" id="id22"> <h3><a name="id22">12.6.1 Motivation</a></h3> <p>This will make a copy of the parameter. This is the default behavior when @@ -2051,7 +2057,7 @@ </div> </div> <div class="section" id="discard-result"> -<h2><a class="toc-backref" href="#id99" name="discard-result">12.7 discard_result</a></h2> +<h2><a name="discard-result">12.7 discard_result</a></h2> <div class="section" id="id27"> <h3><a name="id27">12.7.1 Motivation</a></h3> <p>This is a very simple policy which makes it possible to throw away @@ -2093,7 +2099,7 @@ </div> </div> <div class="section" id="return-stl-iterator"> -<h2><a class="toc-backref" href="#id100" name="return-stl-iterator">12.8 return_stl_iterator</a></h2> +<h2><a name="return-stl-iterator">12.8 return_stl_iterator</a></h2> <div class="section" id="id31"> <h3><a name="id31">12.8.1 Motivation</a></h3> <p>This policy converts an STL container to a generator function that can be used @@ -2138,7 +2144,7 @@ </div> </div> <div class="section" id="raw"> -<h2><a class="toc-backref" href="#id101" name="raw">12.9 raw</a></h2> +<h2><a name="raw">12.9 raw</a></h2> <div class="section" id="id35"> <h3><a name="id35">12.9.1 Motivation</a></h3> <p>This converter policy will pass through the <tt class="docutils literal"><span class="pre">lua_State*</span></tt> unmodified. @@ -2198,7 +2204,7 @@ </div> </div> <div class="section" id="yield"> -<h2><a class="toc-backref" href="#id102" name="yield">12.10 yield</a></h2> +<h2><a name="yield">12.10 yield</a></h2> <div class="section" id="id40"> <h3><a name="id40">12.10.1 Motivation</a></h3> <p>Makes a C++ function yield when returning.</p> Index: out_value.rst =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/doc/out_value.rst,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- out_value.rst 7 Aug 2004 13:37:09 -0000 1.2 +++ out_value.rst 22 Dec 2005 03:06:55 -0000 1.3 @@ -6,7 +6,11 @@ This policy makes it possible to wrap functions that take non-const references or pointer to non-const as it's parameters with the intention to write return -values to them. +values to them. Since it's impossible to pass references to primitive types +in lua, this policy will add another return value with the value after the +call. If the function already has one return value, one instance of this +policy will add another return value (read about multiple return values in +the lua manual). Defined in ~~~~~~~~~~ Index: pure_out_value.rst =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/doc/pure_out_value.rst,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- pure_out_value.rst 10 Aug 2004 20:56:18 -0000 1.3 +++ pure_out_value.rst 22 Dec 2005 03:06:55 -0000 1.4 @@ -6,7 +6,8 @@ This works exactly like ``out_value``, except that it will pass a default constructed object instead of converting an argument from -Lua. +Lua. This means that the parameter will be removed from the lua +signature. Defined in ~~~~~~~~~~ @@ -37,6 +38,8 @@ Example ~~~~~~~ +Note that no values are passed to the calls to ``f1`` and ``f2``. + .. parsed-literal:: void f1(float& val) { val = 10.f; } |
From: Arvid N. <ar...@us...> - 2005-12-21 23:09:57
|
Update of /cvsroot/luabind/luabind/luabind/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32481/luabind/test Modified Files: test_abstract_base.cpp test_policies.cpp Log Message: fixed problem with returning const-references to abstract classes. The const_reference_policy was copying the objects. Also added a test to verify that the fix actually works Index: test_abstract_base.cpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/test/test_abstract_base.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- test_abstract_base.cpp 15 Apr 2005 13:46:17 -0000 1.4 +++ test_abstract_base.cpp 21 Dec 2005 23:09:47 -0000 1.5 @@ -34,6 +34,14 @@ COUNTER_GUARD(abstract); +struct concrete : abstract +{ + std::string hello() + { + return "test string"; + } +}; + struct abstract_wrap : abstract, wrap_base { std::string hello() @@ -52,6 +60,19 @@ return a.hello(); } +abstract& return_abstract_ref() +{ + static concrete c; + return c; +} + +abstract const& return_const_abstract_ref() +{ + static concrete c; + return c; +} + + void test_main(lua_State* L) { module(L) @@ -60,7 +81,9 @@ .def(constructor<>()) .def("hello", &abstract::hello), - def("call_hello", &call_hello) + def("call_hello", &call_hello), + def("return_abstract_ref", &return_abstract_ref), + def("return_const_abstract_ref", &return_const_abstract_ref) ]; DOSTRING_EXPECTED(L, Index: test_policies.cpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/test/test_policies.cpp,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- test_policies.cpp 28 Nov 2005 20:55:34 -0000 1.11 +++ test_policies.cpp 21 Dec 2005 23:09:47 -0000 1.12 @@ -67,7 +67,7 @@ policies_test_class(policies_test_class const& c): name_(c.name_) { ++count; } - void member_out_val(int* v) { *v = 5; } + void member_out_val(int a, int* v) { *v = a * 2; } secret_type* member_secret() { return &sec_; } }; @@ -112,7 +112,7 @@ [ class_<policies_test_class>("test") .def(constructor<>()) - .def("member_out_val", &policies_test_class::member_out_val, pure_out_value(_2)) + .def("member_out_val", &policies_test_class::member_out_val, pure_out_value(_3)) .def("member_secret", &policies_test_class::member_secret, discard_result) .def("f", &policies_test_class::f, adopt(_2)) .def("make", &policies_test_class::make, adopt(return_value)) @@ -195,7 +195,7 @@ TEST_CHECK(policies_test_class::count == 2); DOSTRING(L, "b = a:make('tjosan')"); - DOSTRING(L, "assert(a:member_out_val() == 5)"); + DOSTRING(L, "assert(a:member_out_val(3) == 6)"); DOSTRING(L, "a:member_secret()"); // make instantiated a new policies_test_class |
From: Arvid N. <ar...@us...> - 2005-12-21 23:09:56
|
Update of /cvsroot/luabind/luabind/luabind/luabind/detail In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32481/luabind/luabind/detail Modified Files: policy.hpp Log Message: fixed problem with returning const-references to abstract classes. The const_reference_policy was copying the objects. Also added a test to verify that the fix actually works Index: policy.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/detail/policy.hpp,v retrieving revision 1.53 retrieving revision 1.54 diff -u -d -r1.53 -r1.54 --- policy.hpp 10 Dec 2005 16:52:54 -0000 1.53 +++ policy.hpp 21 Dec 2005 23:09:47 -0000 1.54 @@ -853,7 +853,7 @@ typedef const_ref_converter type; template<class T> - void apply(lua_State* L, const T& ref) + void apply(lua_State* L, T const& ref) { if (luabind::get_back_reference(L, ref)) return; @@ -864,32 +864,12 @@ // trying to use an unregistered type assert(crep && "you are trying to use an unregistered type"); + T const* ptr = &ref; - void* obj_rep; - void* held; - - boost::tie(obj_rep,held) = crep->allocate(L); - - void* object_ptr; - void(*destructor)(void*); - destructor = crep->destructor(); - int flags = 0; - if (crep->has_holder()) - { - flags = object_rep::owner; - new(held) T(ref); - object_ptr = held; - if (LUABIND_TYPE_INFO_EQUAL(LUABIND_TYPEID(T), crep->const_holder_type())) - { - flags |= object_rep::constant; - destructor = crep->const_holder_destructor(); - } - } - else - { - object_ptr = new T(ref); - } - new(obj_rep) object_rep(object_ptr, crep, flags, destructor); + // create the struct to hold the object + void* obj = lua_newuserdata(L, sizeof(object_rep)); + assert(obj && "internal error, please report"); + new(obj) object_rep(const_cast<T*>(ptr), crep, object_rep::constant, 0); // set the meta table detail::getref(L, crep->metatable_ref()); |
From: Daniel W. <dan...@us...> - 2005-12-16 18:52:32
|
Update of /cvsroot/luabind/luabind/luabind/luabind In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7869 Modified Files: object.hpp Log Message: Operators should only be enabled for object and it's proxy classes, not all value wrappers. Index: object.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/object.hpp,v retrieving revision 1.37 retrieving revision 1.38 diff -u -d -r1.37 -r1.38 --- object.hpp 16 Dec 2005 17:51:47 -0000 1.37 +++ object.hpp 16 Dec 2005 18:52:23 -0000 1.38 @@ -92,16 +92,44 @@ namespace adl { - namespace mpl = boost::mpl; + template <class T> + class object_interface; + + namespace is_object_interface_aux + { + typedef char (&yes)[1]; + typedef char (&no)[2]; + + template <class T> + yes check(object_interface<T>*); + no check(void*); + + template <class T> + struct impl + { + BOOST_STATIC_CONSTANT(bool, value = + sizeof(is_object_interface_aux::check((T*)0)) == sizeof(yes) + ); + + typedef mpl::bool_<value> type; + }; + + } // namespace detail + + template <class T> + struct is_object_interface + : is_object_interface_aux::impl<T>::type + {}; + template <class R, class T, class U> struct enable_binary # ifndef BOOST_NO_SFINAE : boost::enable_if< mpl::or_< - is_value_wrapper<T> - , is_value_wrapper<U> + is_object_interface<T> + , is_object_interface<U> > , R > |
From: Daniel W. <dan...@us...> - 2005-12-16 17:51:58
|
Update of /cvsroot/luabind/luabind/luabind/luabind In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22688 Modified Files: object.hpp Log Message: Object operators are now using SFINAE. Index: object.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/object.hpp,v retrieving revision 1.36 retrieving revision 1.37 diff -u -d -r1.36 -r1.37 --- object.hpp 4 Dec 2005 13:56:15 -0000 1.36 +++ object.hpp 16 Dec 2005 17:51:47 -0000 1.37 @@ -42,6 +42,7 @@ #include <boost/python/detail/is_xxx.hpp> #include <boost/preprocessor/iteration/iterate.hpp> +#include <boost/utility/enable_if.hpp> namespace luabind { @@ -92,6 +93,25 @@ namespace adl { + namespace mpl = boost::mpl; + + template <class R, class T, class U> + struct enable_binary +# ifndef BOOST_NO_SFINAE + : boost::enable_if< + mpl::or_< + is_value_wrapper<T> + , is_value_wrapper<U> + > + , R + > + {}; +# else + { + typedef R type; + }; +# endif + template<class T, class U, class V> lua_State* binary_interpreter(T const& x, U const&, boost::mpl::true_, V) { @@ -117,7 +137,8 @@ #define LUABIND_BINARY_OP_DEF(op, fn) \ template<class LHS, class RHS> \ - bool operator op(LHS const& lhs, RHS const& rhs) \ + typename enable_binary<bool,LHS,RHS>::type \ + operator op(LHS const& lhs, RHS const& rhs) \ { \ lua_State* L = binary_interpreter(lhs, rhs); \ \ @@ -137,25 +158,29 @@ #undef LUABIND_BINARY_OP_DEF template<class LHS, class RHS> - bool operator>(LHS const& lhs, RHS const& rhs) + typename enable_binary<bool,LHS,RHS>::type + operator>(LHS const& lhs, RHS const& rhs) { return !(lhs < rhs || lhs == rhs); } template<class LHS, class RHS> - bool operator<=(LHS const& lhs, RHS const& rhs) + typename enable_binary<bool,LHS,RHS>::type + operator<=(LHS const& lhs, RHS const& rhs) { return lhs < rhs || lhs == rhs; } template<class LHS, class RHS> - bool operator>=(LHS const& lhs, RHS const& rhs) + typename enable_binary<bool,LHS,RHS>::type + operator>=(LHS const& lhs, RHS const& rhs) { return !(lhs < rhs); } template<class LHS, class RHS> - bool operator!=(LHS const& lhs, RHS const& rhs) + typename enable_binary<bool,LHS,RHS>::type + operator!=(LHS const& lhs, RHS const& rhs) { return !(lhs < rhs); } |
From: Daniel W. <dan...@us...> - 2005-12-16 17:51:01
|
Update of /cvsroot/luabind/luabind/luabind/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22517 Modified Files: Jamfile Added Files: test_vector_of_object.cpp Log Message: New test that verifies that ADL doesn't apply when it shouldn't. --- NEW FILE: test_vector_of_object.cpp --- // Copyright (c) 2005 Daniel Wallin // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the "Software"), // to deal in the Software without restriction, including without limitation // the rights to use, copy, modify, merge, publish, distribute, sublicense, // and/or sell copies of the Software, and to permit persons to whom the // Software is furnished to do so, subject to the following conditions: // The above copyright notice and this permission notice shall be included // in all copies or substantial portions of the Software. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF // ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A // PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT // SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR // ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE // OR OTHER DEALINGS IN THE SOFTWARE. #include "test.hpp" #include <luabind/object.hpp> using namespace luabind; void test_main(lua_State* L) { std::vector<object> v; v.push_back(object(L, 0)); for (std::vector<object>::iterator i(v.begin()), e(v.end()); i != e; ++i) {} } Index: Jamfile =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/test/Jamfile,v retrieving revision 1.16 retrieving revision 1.17 diff -u -d -r1.16 -r1.17 --- Jamfile 28 Nov 2005 20:55:34 -0000 1.16 +++ Jamfile 16 Dec 2005 17:50:51 -0000 1.17 @@ -3,6 +3,7 @@ use-project /luabind : ../ ; SOURCES = + test_vector_of_object.cpp test_back_reference.cpp test_def_from_base.cpp test_object.cpp |
From: Arvid N. <ar...@us...> - 2005-12-10 16:53:02
|
Update of /cvsroot/luabind/luabind/luabind/luabind/detail In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30137/luabind/detail Modified Files: policy.hpp Log Message: fixed incorrect boost version check Index: policy.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/detail/policy.hpp,v retrieving revision 1.52 retrieving revision 1.53 diff -u -d -r1.52 -r1.53 --- policy.hpp 4 Dec 2005 13:56:16 -0000 1.52 +++ policy.hpp 10 Dec 2005 16:52:54 -0000 1.53 @@ -1296,7 +1296,7 @@ namespace luabind { namespace { -#if defined(__BORLANDC__) || (BOOST_VERSION < 103400 && defined(__GNUC__)) +#if defined(__BORLANDC__) || (BOOST_VERSION >= 103400 && defined(__GNUC__)) static inline boost::arg<0> return_value() { return boost::arg<0>(); |
From: Daniel W. <dan...@us...> - 2005-12-04 13:57:12
|
Update of /cvsroot/luabind/luabind/luabind/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26300 Modified Files: class.cpp Log Message: Fixed for VC6.5. Index: class.cpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/src/class.cpp,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- class.cpp 7 Aug 2004 13:37:11 -0000 1.10 +++ class.cpp 4 Dec 2005 13:57:04 -0000 1.11 @@ -233,7 +233,7 @@ } void class_base::init( - LUABIND_TYPE_INFO type_ + LUABIND_TYPE_INFO type_id , LUABIND_TYPE_INFO holder_type , LUABIND_TYPE_INFO const_holder_type , void*(*extractor)(void*) @@ -249,7 +249,7 @@ , int holder_size , int holder_alignment) { - m_registration->m_type = type_; + m_registration->m_type = type_id; m_registration->m_holder_type = holder_type; m_registration->m_const_holder_type = const_holder_type; m_registration->m_extractor = extractor; |
From: Daniel W. <dan...@us...> - 2005-12-04 13:56:28
|
Update of /cvsroot/luabind/luabind/luabind/luabind In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25897 Modified Files: adopt_policy.hpp back_reference.hpp container_policy.hpp copy_policy.hpp dependency_policy.hpp discard_result_policy.hpp function.hpp iterator_policy.hpp object.hpp operator.hpp out_value_policy.hpp raw_policy.hpp return_reference_to_policy.hpp Log Message: Made it work on VC6.5 again. This involves changing generate_converter into apply. Index: object.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/object.hpp,v retrieving revision 1.35 retrieving revision 1.36 diff -u -d -r1.35 -r1.36 --- object.hpp 28 Nov 2005 20:55:34 -0000 1.35 +++ object.hpp 4 Dec 2005 13:56:15 -0000 1.36 @@ -26,6 +26,7 @@ #include <boost/implicit_cast.hpp> // detail::push() #include <boost/ref.hpp> // detail::push() #include <boost/mpl/bool.hpp> // value_wrapper_traits specializations +#include <boost/mpl/apply_wrap.hpp> #include <boost/tuple/tuple.hpp> #include <boost/optional.hpp> @@ -46,7 +47,8 @@ namespace detail { - + namespace mpl = boost::mpl; + template<class T, class ConverterGenerator> void push_aux(lua_State* interpreter, T& value, ConverterGenerator*) { @@ -56,9 +58,8 @@ , T >::type unwrapped_type; - typename ConverterGenerator::template generate_converter< - unwrapped_type - , cpp_to_lua + typename mpl::apply_wrap2< + ConverterGenerator,unwrapped_type,cpp_to_lua >::type cv; cv.apply( @@ -739,14 +740,14 @@ , class ValueWrapper , class Policies , class ErrorPolicy - , class ReturnType + , class ReturnType > ReturnType object_cast_aux( ValueWrapper const& value_wrapper , T* , Policies* , ErrorPolicy* - , ReturnType* + , ReturnType* ) { lua_State* interpreter = value_wrapper_traits<ValueWrapper>::interpreter( @@ -767,10 +768,7 @@ , Policies >::type converter_generator; - typename converter_generator::template generate_converter< - T - , lua_to_cpp - >::type cv; + typename mpl::apply_wrap2<converter_generator, T, lua_to_cpp>::type cv; #ifndef LUABIND_NO_ERROR_CHECKING if (cv.match(interpreter, LUABIND_DECORATE_TYPE(T), -1) < 0) @@ -831,7 +829,7 @@ , (T*)0 , (Policies*)0 , (detail::throw_error_policy<T>*)0 - , (T*)0 + , (T*)0 ); } Index: out_value_policy.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/out_value_policy.hpp,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- out_value_policy.hpp 7 Aug 2004 13:37:10 -0000 1.5 +++ out_value_policy.hpp 4 Dec 2005 13:56:15 -0000 1.6 @@ -26,6 +26,7 @@ #include <luabind/config.hpp> #include <luabind/detail/policy.hpp> +#include <boost/mpl/apply_wrap.hpp> namespace luabind { namespace detail { @@ -77,6 +78,8 @@ BOOST_STATIC_CONSTANT(int, value = sizeof(indirect_sizeof_test(LUABIND_DECORATE_TYPE(T)))); }; + namespace mpl = boost::mpl; + template<int Size, class Policies = detail::null_type> struct out_value_converter { @@ -84,7 +87,7 @@ T& apply(lua_State* L, by_reference<T>, int index) { typedef typename find_conversion_policy<1, Policies>::type converter_policy; - typename converter_policy::template generate_converter<T, lua_to_cpp>::type converter; + typename mpl::apply_wrap2<converter_policy,T,lua_to_cpp>::type converter; new (m_storage) T(converter.apply(L, LUABIND_DECORATE_TYPE(T), index)); return *reinterpret_cast<T*>(m_storage); } @@ -93,7 +96,7 @@ static int match(lua_State* L, by_reference<T>, int index) { typedef typename find_conversion_policy<1, Policies>::type converter_policy; - typedef typename converter_policy::template generate_converter<T, lua_to_cpp>::type converter; + typedef typename mpl::apply_wrap2<converter_policy,T,lua_to_cpp>::type converter; return converter::match(L, LUABIND_DECORATE_TYPE(T), index); } @@ -101,7 +104,7 @@ void converter_postcall(lua_State* L, by_reference<T>, int) { typedef typename find_conversion_policy<2, Policies>::type converter_policy; - typename converter_policy::template generate_converter<T, cpp_to_lua>::type converter; + typename mpl::apply_wrap2<converter_policy,T,cpp_to_lua>::type converter; converter.apply(L, *reinterpret_cast<T*>(m_storage)); reinterpret_cast<T*>(m_storage)->~T(); } @@ -110,7 +113,7 @@ T* apply(lua_State* L, by_pointer<T>, int index) { typedef typename find_conversion_policy<1, Policies>::type converter_policy; - typename converter_policy::template generate_converter<T, lua_to_cpp>::type converter; + typename mpl::apply_wrap2<converter_policy,T,lua_to_cpp>::type converter; new (m_storage) T(converter.apply(L, LUABIND_DECORATE_TYPE(T), index)); return reinterpret_cast<T*>(m_storage); } @@ -119,7 +122,7 @@ static int match(lua_State* L, by_pointer<T>, int index) { typedef typename find_conversion_policy<1, Policies>::type converter_policy; - typedef typename converter_policy::template generate_converter<T, lua_to_cpp>::type converter; + typedef typename mpl::apply_wrap2<converter_policy,T,lua_to_cpp>::type converter; return converter::match(L, LUABIND_DECORATE_TYPE(T), index); } @@ -127,7 +130,7 @@ void converter_postcall(lua_State* L, by_pointer<T>, int) { typedef typename find_conversion_policy<2, Policies>::type converter_policy; - typename converter_policy::template generate_converter<T, cpp_to_lua>::type converter; + typename mpl::apply_wrap2<converter_policy,T,cpp_to_lua>::type converter; converter.apply(L, *reinterpret_cast<T*>(m_storage)); reinterpret_cast<T*>(m_storage)->~T(); } @@ -145,7 +148,7 @@ struct can_only_convert_from_lua_to_cpp {}; template<class T, class Direction> - struct generate_converter + struct apply { typedef typename boost::mpl::if_<boost::is_same<lua_to_cpp, Direction> , typename boost::mpl::if_<boost::mpl::or_<is_nonconst_reference<T>, is_nonconst_pointer<T> > @@ -177,7 +180,7 @@ void converter_postcall(lua_State* L, by_reference<T>, int) { typedef typename find_conversion_policy<1, Policies>::type converter_policy; - typename converter_policy::template generate_converter<T, cpp_to_lua>::type converter; + typename mpl::apply_wrap2<converter_policy,T,cpp_to_lua>::type converter; converter.apply(L, *reinterpret_cast<T*>(m_storage)); reinterpret_cast<T*>(m_storage)->~T(); } @@ -199,7 +202,7 @@ void converter_postcall(lua_State* L, by_pointer<T>, int) { typedef typename find_conversion_policy<1, Policies>::type converter_policy; - typename converter_policy::template generate_converter<T, cpp_to_lua>::type converter; + typename mpl::apply_wrap2<converter_policy,T,cpp_to_lua>::type converter; converter.apply(L, *reinterpret_cast<T*>(m_storage)); reinterpret_cast<T*>(m_storage)->~T(); } @@ -218,7 +221,7 @@ struct can_only_convert_from_lua_to_cpp {}; template<class T, class Direction> - struct generate_converter + struct apply { typedef typename boost::mpl::if_<boost::is_same<lua_to_cpp, Direction> , typename boost::mpl::if_<boost::mpl::or_<is_nonconst_reference<T>, is_nonconst_pointer<T> > @@ -236,19 +239,31 @@ { template<int N> detail::policy_cons<detail::out_value_policy<N>, detail::null_type> - out_value(boost::arg<N>) { return detail::policy_cons<detail::out_value_policy<N>, detail::null_type>(); } + out_value(LUABIND_PLACEHOLDER_ARG(N)) + { + return detail::policy_cons<detail::out_value_policy<N>, detail::null_type>(); + } template<int N, class Policies> detail::policy_cons<detail::out_value_policy<N, Policies>, detail::null_type> - out_value(boost::arg<N>, const Policies&) { return detail::policy_cons<detail::out_value_policy<N, Policies>, detail::null_type>(); } + out_value(LUABIND_PLACEHOLDER_ARG(N), const Policies&) + { + return detail::policy_cons<detail::out_value_policy<N, Policies>, detail::null_type>(); + } template<int N> detail::policy_cons<detail::pure_out_value_policy<N>, detail::null_type> - pure_out_value(boost::arg<N>) { return detail::policy_cons<detail::pure_out_value_policy<N>, detail::null_type>(); } + pure_out_value(LUABIND_PLACEHOLDER_ARG(N)) + { + return detail::policy_cons<detail::pure_out_value_policy<N>, detail::null_type>(); + } template<int N, class Policies> detail::policy_cons<detail::pure_out_value_policy<N, Policies>, detail::null_type> - pure_out_value(boost::arg<N>, const Policies&) { return detail::policy_cons<detail::pure_out_value_policy<N, Policies>, detail::null_type>(); } + pure_out_value(LUABIND_PLACEHOLDER_ARG(N), const Policies&) + { + return detail::policy_cons<detail::pure_out_value_policy<N, Policies>, detail::null_type>(); + } } #endif // LUABIND_OUT_VALUE_POLICY_HPP_INCLUDED Index: raw_policy.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/raw_policy.hpp,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- raw_policy.hpp 7 Aug 2004 13:37:10 -0000 1.2 +++ raw_policy.hpp 4 Dec 2005 13:56:15 -0000 1.3 @@ -51,7 +51,7 @@ static void postcall(lua_State*, const index_map&) {} template<class T, class Direction> - struct generate_converter + struct apply { typedef raw_converter type; }; @@ -66,7 +66,7 @@ detail::raw_policy<N> , detail::null_type > - inline raw(boost::arg<N>) + inline raw(LUABIND_PLACEHOLDER_ARG(N)) { return detail::policy_cons< detail::raw_policy<N> Index: operator.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/operator.hpp,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- operator.hpp 3 Jan 2005 11:15:21 -0000 1.6 +++ operator.hpp 4 Dec 2005 13:56:15 -0000 1.7 @@ -25,6 +25,7 @@ #include <boost/mpl/eval_if.hpp> #include <boost/mpl/identity.hpp> +#include <boost/mpl/apply_wrap.hpp> #include <boost/type_traits/is_same.hpp> #include <luabind/detail/other.hpp> #include <luabind/raw_policy.hpp> @@ -175,6 +176,8 @@ { } + namespace mpl = boost::mpl; + template<class T, class Policies> inline void operator_result(lua_State* L, T const& x, Policies*) { @@ -183,10 +186,7 @@ , Policies >::type cv_policy; - typename cv_policy::template generate_converter< - T - , cpp_to_lua - >::type cv; + typename mpl::apply_wrap2<cv_policy,T,cpp_to_lua>::type cv; cv.apply(L, x); } Index: back_reference.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/back_reference.hpp,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- back_reference.hpp 28 Nov 2005 20:55:34 -0000 1.3 +++ back_reference.hpp 4 Dec 2005 13:56:15 -0000 1.4 @@ -50,27 +50,27 @@ } template<class T> - wrap_base const* get_back_reference_aux(T const* p) + wrap_base const* get_back_reference_aux1(T const* p) { return get_back_reference_aux0(p, boost::is_polymorphic<T>()); } template<class T> - wrap_base const* get_back_reference_aux(T const& x, mpl::true_) + wrap_base const* get_back_reference_aux2(T const& x, mpl::true_) { - return get_back_reference_aux(get_pointer(x)); + return get_back_reference_aux1(get_pointer(x)); } template<class T> - wrap_base const* get_back_reference_aux(T const& x, mpl::false_) + wrap_base const* get_back_reference_aux2(T const& x, mpl::false_) { - return get_back_reference_aux(&x); + return get_back_reference_aux1(&x); } template<class T> wrap_base const* get_back_reference(T const& x) { - return detail::get_back_reference_aux( + return detail::get_back_reference_aux2( x , has_get_pointer<T>() ); Index: discard_result_policy.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/discard_result_policy.hpp,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- discard_result_policy.hpp 14 Jun 2003 21:05:01 -0000 1.3 +++ discard_result_policy.hpp 4 Dec 2005 13:56:15 -0000 1.4 @@ -43,7 +43,7 @@ struct can_only_convert_from_cpp_to_lua {}; template<class T, class Direction> - struct generate_converter + struct apply { typedef typename boost::mpl::if_<boost::is_same<Direction, cpp_to_lua> , discard_converter Index: copy_policy.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/copy_policy.hpp,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- copy_policy.hpp 14 Jun 2003 21:05:01 -0000 1.7 +++ copy_policy.hpp 4 Dec 2005 13:56:15 -0000 1.8 @@ -99,7 +99,7 @@ static void postcall(lua_State*, const index_map&) {} template<class T, class Direction> - struct generate_converter + struct apply { typedef typename boost::mpl::if_<boost::is_same<Direction, cpp_to_lua> , typename boost::mpl::if_<boost::is_pointer<T> @@ -116,7 +116,10 @@ { template<int N> detail::policy_cons<detail::copy_policy<N>, detail::null_type> - copy(boost::arg<N>) { return detail::policy_cons<detail::copy_policy<N>, detail::null_type>(); } + copy(LUABIND_PLACEHOLDER_ARG(N)) + { + return detail::policy_cons<detail::copy_policy<N>, detail::null_type>(); + } } #endif // LUABIND_COPY_POLICY_HPP_INCLUDED Index: function.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/function.hpp,v retrieving revision 1.24 retrieving revision 1.25 diff -u -d -r1.24 -r1.25 --- function.hpp 7 Aug 2004 13:37:10 -0000 1.24 +++ function.hpp 4 Dec 2005 13:56:15 -0000 1.25 @@ -35,6 +35,7 @@ #include <boost/preprocessor/repetition/enum.hpp> #include <boost/preprocessor/repetition/enum_params.hpp> #include <boost/preprocessor/cat.hpp> +#include <boost/mpl/apply_wrap.hpp> #include <luabind/detail/signature_match.hpp> #include <luabind/detail/call_function.hpp> @@ -48,6 +49,8 @@ namespace detail { + namespace mpl = boost::mpl; + namespace free_functions { @@ -107,7 +110,9 @@ // returns generates functions that calls function pointers #define LUABIND_DECL(z, n, text) typedef typename find_conversion_policy<n + 1, Policies>::type BOOST_PP_CAT(converter_policy,n); \ - typename BOOST_PP_CAT(converter_policy,n)::template generate_converter<A##n, lua_to_cpp>::type BOOST_PP_CAT(c,n); + typename mpl::apply_wrap2< \ + BOOST_PP_CAT(converter_policy,n), BOOST_PP_CAT(A,n), lua_to_cpp \ + >::type BOOST_PP_CAT(c,n); #define LUABIND_ADD_INDEX(z,n,text) + BOOST_PP_CAT(converter_policy,n)::has_arg #define LUABIND_INDEX_MAP(z,n,text) 1 BOOST_PP_REPEAT(n, LUABIND_ADD_INDEX, _) @@ -333,16 +338,10 @@ template<class Policies BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), class A)> static int call(T(*f)(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), A)), lua_State* L, const Policies*) { -/* typedef typename get_policy<0, Policies>::type ret_policy; - typedef typename ret_policy::head return_value_converter_intermediate; - typedef typename return_value_converter_intermediate::template generate_converter<T, cpp_to_lua>::type ret_conv;*/ - int nargs = lua_gettop(L); -// typedef typename get_policy_list<0, Policies>::type policy_list_ret; -// typedef typename find_converter_policy<policy_list_ret>::type converter_policy_ret; typedef typename find_conversion_policy<0, Policies>::type converter_policy_ret; - typename converter_policy_ret::template generate_converter<T, cpp_to_lua>::type converter_ret; + typename mpl::apply_wrap2<converter_policy_ret,T,cpp_to_lua>::type converter_ret; BOOST_PP_REPEAT(BOOST_PP_ITERATION(), LUABIND_DECL, _) converter_ret.apply(L, f Index: container_policy.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/container_policy.hpp,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- container_policy.hpp 14 Jun 2003 21:05:01 -0000 1.2 +++ container_policy.hpp 4 Dec 2005 13:56:15 -0000 1.3 @@ -26,9 +26,12 @@ #include <luabind/config.hpp> #include <luabind/detail/policy.hpp> +#include <boost/mpl/apply_wrap.hpp> namespace luabind { namespace detail { + namespace mpl = boost::mpl; + template<class Policies> struct container_converter_lua_to_cpp { @@ -38,7 +41,7 @@ typedef typename T::value_type value_type; typedef typename find_conversion_policy<1, Policies>::type converter_policy; - typename converter_policy::template generate_converter<value_type, lua_to_cpp>::type converter; + typename mpl::apply_wrap2<converter_policy,value_type,lua_to_cpp>::type converter; T container; @@ -77,7 +80,7 @@ typedef typename T::value_type value_type; typedef typename find_conversion_policy<1, Policies>::type converter_policy; - typename converter_policy::template generate_converter<value_type, cpp_to_lua>::type converter; + typename mpl::apply_wrap2<converter_policy,value_type,lua_to_cpp>::type converter; lua_newtable(L); @@ -104,7 +107,7 @@ struct only_accepts_nonconst_pointers {}; template<class T, class Direction> - struct generate_converter + struct apply { typedef typename boost::mpl::if_<boost::is_same<lua_to_cpp, Direction> , container_converter_lua_to_cpp<Policies> @@ -119,11 +122,17 @@ { template<int N> detail::policy_cons<detail::container_policy<N, detail::null_type>, detail::null_type> - container(boost::arg<N>) { return detail::policy_cons<detail::container_policy<N, detail::null_type>, detail::null_type>(); } + container(LUABIND_PLACEHOLDER_ARG(N)) + { + return detail::policy_cons<detail::container_policy<N, detail::null_type>, detail::null_type>(); + } template<int N, class Policies> detail::policy_cons<detail::container_policy<N, Policies>, detail::null_type> - container(boost::arg<N>, const Policies&) { return detail::policy_cons<detail::container_policy<N, Policies>, detail::null_type>(); } + container(LUABIND_PLACEHOLDER_ARG(N), const Policies&) + { + return detail::policy_cons<detail::container_policy<N, Policies>, detail::null_type>(); + } } #endif // LUABIND_CONTAINER_POLICY_HPP_INCLUDED Index: return_reference_to_policy.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/return_reference_to_policy.hpp,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- return_reference_to_policy.hpp 14 Jun 2003 21:05:02 -0000 1.2 +++ return_reference_to_policy.hpp 4 Dec 2005 13:56:15 -0000 1.3 @@ -52,7 +52,7 @@ } template<class T, class Direction> - struct generate_converter + struct apply { typedef return_reference_to_converter<Direction> type; }; @@ -63,7 +63,10 @@ { template<int N> detail::policy_cons<detail::return_reference_to_policy<N>, detail::null_type> - return_reference_to(boost::arg<N>) { return detail::policy_cons<detail::return_reference_to_policy<N>, detail::null_type>(); } + return_reference_to(LUABIND_PLACEHOLDER_ARG(N)) + { + return detail::policy_cons<detail::return_reference_to_policy<N>, detail::null_type>(); + } } #endif // LUABIND_RETURN_REFERENCE_TO_POLICY_HPP_INCLUDED Index: dependency_policy.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/dependency_policy.hpp,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- dependency_policy.hpp 28 Nov 2005 20:55:34 -0000 1.6 +++ dependency_policy.hpp 4 Dec 2005 13:56:15 -0000 1.7 @@ -62,7 +62,7 @@ }; template<int N> - size_char_array<N> deduce_size(boost::arg<N>); + size_char_array<N> deduce_size(LUABIND_PLACEHOLDER_ARG(N)); template<class T> struct get_index_workaround @@ -97,14 +97,14 @@ { template<int A, int B> detail::policy_cons<detail::dependency_policy<A, B>, detail::null_type> - dependency(boost::arg<A>, boost::arg<B>) + dependency(LUABIND_PLACEHOLDER_ARG(A), LUABIND_PLACEHOLDER_ARG(B)) { return detail::policy_cons<detail::dependency_policy<A, B>, detail::null_type>(); } template<int A> detail::policy_cons<detail::dependency_policy<0, A>, detail::null_type> - return_internal_reference(boost::arg<A>) + return_internal_reference(LUABIND_PLACEHOLDER_ARG(A)) { return detail::policy_cons<detail::dependency_policy<0, A>, detail::null_type>(); } Index: adopt_policy.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/adopt_policy.hpp,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- adopt_policy.hpp 28 Nov 2005 20:55:34 -0000 1.11 +++ adopt_policy.hpp 4 Dec 2005 13:56:14 -0000 1.12 @@ -135,7 +135,7 @@ struct only_accepts_nonconst_pointers {}; template<class T, class Direction> - struct generate_converter + struct apply { typedef luabind::detail::is_nonconst_pointer<T> is_nonconst_p; typedef typename boost::mpl::if_<is_nonconst_p, adopt_pointer<Direction>, only_accepts_nonconst_pointers>::type type; @@ -148,7 +148,10 @@ { template<int N> detail::policy_cons<detail::adopt_policy<N>, detail::null_type> - adopt(boost::arg<N>) { return detail::policy_cons<detail::adopt_policy<N>, detail::null_type>(); } + adopt(LUABIND_PLACEHOLDER_ARG(N)) + { + return detail::policy_cons<detail::adopt_policy<N>, detail::null_type>(); + } } #endif // LUABIND_ADOPT_POLICY_HPP_INCLUDE Index: iterator_policy.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/iterator_policy.hpp,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- iterator_policy.hpp 28 Nov 2005 20:55:34 -0000 1.4 +++ iterator_policy.hpp 4 Dec 2005 13:56:15 -0000 1.5 @@ -101,7 +101,7 @@ static void postcall(lua_State*, const index_map&) {} template<class T, class Direction> - struct generate_converter + struct apply { typedef iterator_converter type; }; |
From: Daniel W. <dan...@us...> - 2005-12-04 13:56:27
|
Update of /cvsroot/luabind/luabind/luabind/luabind/detail In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25897/detail Modified Files: call.hpp call_function.hpp call_member.hpp constructor.hpp convert_to_lua.hpp object_funs.hpp policy.hpp property.hpp signature_match.hpp Log Message: Made it work on VC6.5 again. This involves changing generate_converter into apply. Index: call_member.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/detail/call_member.hpp,v retrieving revision 1.12 retrieving revision 1.13 diff -u -d -r1.12 -r1.13 --- call_member.hpp 28 Nov 2005 20:55:34 -0000 1.12 +++ call_member.hpp 4 Dec 2005 13:56:15 -0000 1.13 @@ -38,13 +38,14 @@ #include <boost/preprocessor/control/if.hpp> #include <boost/preprocessor/facilities/expand.hpp> +#include <boost/mpl/apply_wrap.hpp> + namespace luabind { namespace detail { - - + namespace mpl = boost::mpl; // if the proxy_member_caller returns non-void template<class Ret, class Tuple> @@ -102,7 +103,7 @@ operator Ret() { - typename default_policy::template generate_converter<Ret, lua_to_cpp>::type converter; + typename mpl::apply_wrap2<default_policy,Ret,lua_to_cpp>::type converter; m_called = true; @@ -155,7 +156,7 @@ Ret operator[](const Policies& p) { typedef typename find_conversion_policy<0, Policies>::type converter_policy; - typename converter_policy::template generate_converter<Ret, lua_to_cpp>::type converter; + typename mpl::apply_wrap2<converter_policy,Ret,lua_to_cpp>::type converter; m_called = true; Index: convert_to_lua.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/detail/convert_to_lua.hpp,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- convert_to_lua.hpp 14 Jun 2003 21:05:02 -0000 1.2 +++ convert_to_lua.hpp 4 Dec 2005 13:56:16 -0000 1.3 @@ -28,6 +28,8 @@ #include <luabind/detail/policy.hpp> #include <boost/ref.hpp> +#include <boost/mpl/apply_wrap.hpp> + namespace luabind { namespace detail { template<bool IsReferenceWrapper = false> @@ -56,11 +58,17 @@ }; }; + namespace mpl = boost::mpl; + template<class T> void convert_to_lua(lua_State* L, const T& v) { - typedef typename unwrap_ref<boost::is_reference_wrapper<T>::value>::template apply<T>::type value_type; - typename default_policy::template generate_converter<value_type, cpp_to_lua>::type converter; + typedef typename mpl::apply_wrap1< + unwrap_ref<boost::is_reference_wrapper<T>::value> + , T + >::type value_type; + + typename mpl::apply_wrap2<default_policy,value_type,cpp_to_lua>::type converter; converter.apply(L, unwrap_ref<boost::is_reference_wrapper<T>::value>::get(v)); } @@ -68,9 +76,13 @@ template<int Index, class T, class Policies> void convert_to_lua_p(lua_State* L, const T& v, const Policies&) { - typedef typename unwrap_ref<boost::is_reference_wrapper<T>::value>::template apply<T>::type value_type; + typedef typename mpl::apply_wrap1< + unwrap_ref<boost::is_reference_wrapper<T>::value> + , T + >::type value_type; + typedef typename find_conversion_policy<Index, Policies>::type converter_policy; - typename converter_policy::template generate_converter<value_type, cpp_to_lua>::type converter; + typename mpl::apply_wrap2<converter_policy,value_type,cpp_to_lua>::type converter; converter.apply(L, unwrap_ref<boost::is_reference_wrapper<T>::value>::get(v)); } Index: property.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/detail/property.hpp,v retrieving revision 1.12 retrieving revision 1.13 diff -u -d -r1.12 -r1.13 --- property.hpp 28 Nov 2005 20:55:34 -0000 1.12 +++ property.hpp 4 Dec 2005 13:56:16 -0000 1.13 @@ -27,10 +27,14 @@ #include <luabind/config.hpp> #include <boost/type_traits/add_reference.hpp> #include <boost/mpl/eval_if.hpp> +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/identity.hpp> #include <luabind/dependency_policy.hpp> namespace luabind { namespace detail { + namespace mpl = boost::mpl; + class object_rep; /* template<class R, class T, class Policies> @@ -112,7 +116,7 @@ static int apply(lua_State* L, int index) { typedef typename find_conversion_policy<1, Policies>::type converter_policy; - typedef typename converter_policy::template generate_converter<T, lua_to_cpp>::type converter; + typedef typename mpl::apply_wrap2<converter_policy,T,lua_to_cpp>::type converter; return converter::match(L, LUABIND_DECORATE_TYPE(T), index); } }; @@ -156,7 +160,7 @@ T* ptr = reinterpret_cast<T*>(static_cast<char*>(raw_ptr) + pointer_offset); typedef typename find_conversion_policy<1,Policies>::type converter_policy; - typename converter_policy::template generate_converter<D,lua_to_cpp>::type converter; + typename mpl::apply_wrap2<converter_policy,D,lua_to_cpp>::type converter; ptr->*member = converter.apply(L, LUABIND_DECORATE_TYPE(D), 3); int nret = lua_gettop(L) - nargs; @@ -174,8 +178,11 @@ template<class ConverterPolicy, class D> struct make_reference_converter { - typedef typename ConverterPolicy::template generate_converter< - typename boost::add_reference<D>::type, cpp_to_lua>::type type; + typedef typename mpl::apply_wrap2< + ConverterPolicy + , typename boost::add_reference<D>::type + , cpp_to_lua + >::type type; }; template<class T, class D, class Policies> @@ -204,20 +211,22 @@ T* ptr = reinterpret_cast<T*>(static_cast<char*>(raw_ptr) + pointer_offset); typedef typename find_conversion_policy<0,Policies>::type converter_policy; - typedef typename converter_policy::template generate_converter<D,cpp_to_lua>::type converter1_t; + typedef typename mpl::apply_wrap2<converter_policy,D,cpp_to_lua>::type converter1_t; // if the converter is a valua converer, return a reference instead typedef typename boost::mpl::eval_if< - typename converter1_t::is_value_converter + BOOST_DEDUCED_TYPENAME converter1_t::is_value_converter , make_reference_converter<converter_policy, D> - , converter1_t>::type converter2_t; + , mpl::identity<converter1_t> + >::type converter2_t; // If this yields a reference converter, the dependency policy // is automatically added typedef typename boost::mpl::if_< - typename converter1_t::is_value_converter + BOOST_DEDUCED_TYPENAME converter1_t::is_value_converter , policy_cons<dependency_policy<1, 0>, Policies> - , Policies>::type policy_list; + , Policies + >::type policy_list; converter2_t converter; converter.apply(L, ptr->*member); Index: signature_match.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/detail/signature_match.hpp,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- signature_match.hpp 28 Nov 2005 20:55:34 -0000 1.4 +++ signature_match.hpp 4 Dec 2005 13:56:16 -0000 1.5 @@ -88,10 +88,9 @@ , Policies \ >::type BOOST_PP_CAT(converter_policy, N); \ \ - typedef typename BOOST_PP_CAT(converter_policy, N) \ - ::template generate_converter< \ - BOOST_PP_CAT(A, N), lua_to_cpp \ - >::type BOOST_PP_CAT(converter, N); \ + typedef typename mpl::apply_wrap2< \ + BOOST_PP_CAT(converter_policy, N), BOOST_PP_CAT(A, N), lua_to_cpp \ + >::type BOOST_PP_CAT(converter, N); \ \ int BOOST_PP_CAT(r, N) = BOOST_PP_CAT(converter, N)::match( \ L \ Index: call.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/detail/call.hpp,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- call.hpp 28 Nov 2005 20:55:34 -0000 1.7 +++ call.hpp 4 Dec 2005 13:56:15 -0000 1.8 @@ -36,6 +36,7 @@ #include <boost/preprocessor/punctuation/comma_if.hpp> #include <boost/preprocessor/cat.hpp> #include <boost/mpl/bool.hpp> +#include <boost/mpl/apply_wrap.hpp> #include <luabind/config.hpp> #include <luabind/detail/policy.hpp> @@ -48,9 +49,9 @@ n + off \ , Policies \ >::type BOOST_PP_CAT(converter_policy,n); \ - typename BOOST_PP_CAT(converter_policy,n)::template generate_converter< \ - A##n \ - , lua_to_cpp \ +\ + typename mpl::apply_wrap2< \ + BOOST_PP_CAT(converter_policy,n), BOOST_PP_CAT(A,n), lua_to_cpp \ >::type BOOST_PP_CAT(c,n); #define LUABIND_ADD_INDEX(z,n,text) \ @@ -75,6 +76,9 @@ namespace luabind { namespace detail { + + namespace mpl = boost::mpl; + template<class Policies> struct maybe_yield { @@ -141,7 +145,7 @@ pointer_converter<lua_to_cpp> self_cv; typedef typename find_conversion_policy<0, Policies>::type converter_policy_ret; - typename converter_policy_ret::template generate_converter<T, cpp_to_lua>::type converter_ret; + typename mpl::apply_wrap2<converter_policy_ret,T,cpp_to_lua>::type converter_ret; BOOST_PP_REPEAT(BOOST_PP_ITERATION(), LUABIND_DECL, 2) @@ -187,7 +191,7 @@ const_pointer_converter<lua_to_cpp> self_cv; typedef typename find_conversion_policy<0, Policies>::type converter_policy_ret; - typename converter_policy_ret::template generate_converter<T, cpp_to_lua>::type converter_ret; + typename mpl::apply_wrap2<converter_policy_ret,T,cpp_to_lua>::type converter_ret; BOOST_PP_REPEAT(BOOST_PP_ITERATION(), LUABIND_DECL, 2) @@ -227,7 +231,7 @@ { int nargs = lua_gettop(L); typedef typename find_conversion_policy<0, Policies>::type converter_policy_ret; - typename converter_policy_ret::template generate_converter<T, cpp_to_lua>::type converter_ret; + typename mpl::apply_wrap2<converter_policy_ret,T,cpp_to_lua>::type converter_ret; BOOST_PP_REPEAT(BOOST_PP_ITERATION(), LUABIND_DECL, 1) converter_ret.apply(L, f ( Index: object_funs.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/detail/object_funs.hpp,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- object_funs.hpp 7 Aug 2004 13:37:10 -0000 1.14 +++ object_funs.hpp 4 Dec 2005 13:56:16 -0000 1.15 @@ -32,12 +32,16 @@ #include <luabind/detail/debug.hpp> #include <luabind/detail/stack_utils.hpp> +#include <boost/mpl/apply_wrap.hpp> + namespace luabind { namespace detail { + namespace mpl = boost::mpl; + template<class T, class Obj, class Policies> inline T object_cast_impl(const Obj& obj, const Policies&) { @@ -58,7 +62,7 @@ LUABIND_CHECK_STACK(obj.lua_state()); typedef typename detail::find_conversion_policy<0, Policies>::type converter_policy; - typename converter_policy::template generate_converter<T, lua_to_cpp>::type converter; + typename mpl::apply_wrap2<converter_policy,T,lua_to_cpp>::type converter; obj.pushvalue(); @@ -88,7 +92,7 @@ boost::optional<T> object_cast_nothrow_impl(const Obj& obj, const Policies&) { typedef typename detail::find_conversion_policy<0, Policies>::type converter_policy; - typename converter_policy::template generate_converter<T, lua_to_cpp>::type converter; + typename mpl::apply_wrap2<converter_policy,T,lua_to_cpp>::type converter; if (obj.lua_state() == 0) return boost::optional<T>(); LUABIND_CHECK_STACK(obj.lua_state()); Index: constructor.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/detail/constructor.hpp,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- constructor.hpp 28 Nov 2005 20:55:34 -0000 1.8 +++ constructor.hpp 4 Dec 2005 13:56:16 -0000 1.9 @@ -33,6 +33,8 @@ #include <boost/preprocessor/repeat.hpp> #include <boost/preprocessor/comma_if.hpp> +#include <boost/mpl/apply_wrap.hpp> + #include <luabind/config.hpp> #include <luabind/wrapper_base.hpp> #include <luabind/detail/policy.hpp> @@ -46,6 +48,8 @@ template<int N> struct constructor_helper; + namespace mpl = boost::mpl; + template<int N> struct wrapped_constructor_helper; @@ -93,10 +97,15 @@ #elif BOOST_PP_ITERATION_FLAGS() == 1 -#define LUABIND_DECL(z, n, text) typedef typename find_conversion_policy<n+1,Policies>::type BOOST_PP_CAT(converter_policy,n); \ - typedef typename BOOST_PP_CAT(converter_policy,n)::template generate_converter<A##n, lua_to_cpp>::type BOOST_PP_CAT(c_t,n); \ - typename BOOST_PP_CAT(converter_policy,n)::template generate_converter<A##n, lua_to_cpp>::type BOOST_PP_CAT(c,n); -#define LUABIND_PARAM(z,n,text) BOOST_PP_CAT(c,n).BOOST_PP_CAT(c_t,n)::apply(L, LUABIND_DECORATE_TYPE(A##n), n + 2) +#define LUABIND_DECL(z, n, text) \ + typedef typename find_conversion_policy<n+1,Policies>::type BOOST_PP_CAT(converter_policy,n); \ +\ + typename mpl::apply_wrap2< \ + BOOST_PP_CAT(converter_policy,n), BOOST_PP_CAT(A,n), lua_to_cpp \ + >::type BOOST_PP_CAT(c,n); + +#define LUABIND_PARAM(z,n,text) \ + BOOST_PP_CAT(c,n).apply(L, LUABIND_DECORATE_TYPE(BOOST_PP_CAT(A,n)), n + 2) template<> struct constructor_helper<BOOST_PP_ITERATION()> Index: call_function.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/detail/call_function.hpp,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- call_function.hpp 28 Nov 2005 20:55:34 -0000 1.14 +++ call_function.hpp 4 Dec 2005 13:56:15 -0000 1.15 @@ -111,7 +111,7 @@ operator Ret() { - typename default_policy::template generate_converter<Ret, lua_to_cpp>::type converter; + typename mpl::apply_wrap2<default_policy,Ret,lua_to_cpp>::type converter; m_called = true; lua_State* L = m_state; @@ -161,7 +161,7 @@ Ret operator[](const Policies& p) { typedef typename detail::find_conversion_policy<0, Policies>::type converter_policy; - typename converter_policy::template generate_converter<Ret, lua_to_cpp>::type converter; + typename mpl::apply_wrap2<converter_policy,Ret,lua_to_cpp>::type converter; m_called = true; lua_State* L = m_state; Index: policy.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/detail/policy.hpp,v retrieving revision 1.51 retrieving revision 1.52 diff -u -d -r1.51 -r1.52 --- policy.hpp 28 Nov 2005 20:55:34 -0000 1.51 +++ policy.hpp 4 Dec 2005 13:56:16 -0000 1.52 @@ -42,6 +42,7 @@ #include <boost/bind/arg.hpp> #include <boost/limits.hpp> #include <boost/tuple/tuple.hpp> +#include <boost/version.hpp> #include <luabind/detail/class_registry.hpp> #include <luabind/detail/primitives.hpp> @@ -1126,7 +1127,7 @@ static void precall(lua_State*, T, int) {} template<class T, class Direction> - struct generate_converter + struct apply : eval_if< is_user_defined<T> , user_defined_converter<Direction> @@ -1293,10 +1294,28 @@ }} // namespace luabind::detail -namespace luabind { namespace +namespace luabind { namespace { - LUABIND_ANONYMOUS_FIX boost::arg<0> return_value; - LUABIND_ANONYMOUS_FIX boost::arg<0> result; +#if defined(__BORLANDC__) || (BOOST_VERSION < 103400 && defined(__GNUC__)) + static inline boost::arg<0> return_value() + { + return boost::arg<0>(); + } + + static inline boost::arg<0> result() + { + return boost::arg<0>(); + } +# define LUABIND_PLACEHOLDER_ARG(N) boost::arg<N>(*)() +#elif defined(BOOST_MSVC) || defined(__MWERKS__) + static boost::arg<0> return_value; + static boost::arg<0> result; +# define LUABIND_PLACEHOLDER_ARG(N) boost::arg<N> +#else + boost::arg<0> return_value; + boost::arg<0> result; +# define LUABIND_PLACEHOLDER_ARG(N) boost::arg<N> +#endif }} #endif // LUABIND_POLICY_HPP_INCLUDED |
From: Arvid N. <ar...@us...> - 2005-11-28 20:55:57
|
Update of /cvsroot/luabind/luabind/luabind In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15879/luabind Modified Files: Jamfile Log Message: merged in changes from beta7-devel2 (tag: beta7-devel2-merge) Index: Jamfile =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/Jamfile,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- Jamfile 15 Apr 2005 13:46:14 -0000 1.5 +++ Jamfile 28 Nov 2005 20:55:33 -0000 1.6 @@ -31,7 +31,7 @@ lib lualib : - : <name>lualib <search>$(LUA_PATH)/lualib + : <name>lualib <search>$(LUA_PATH)/lib ; project luabind |
From: Arvid N. <ar...@us...> - 2005-11-28 20:55:57
|
Update of /cvsroot/luabind/luabind/luabind/examples/hello_world In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15879/luabind/examples/hello_world Modified Files: Jamfile hello_world.cpp Added Files: README Log Message: merged in changes from beta7-devel2 (tag: beta7-devel2-merge) --- NEW FILE: README --- this example will build an extension module as a shared library, use loadlib() from within the lua interpreter to load the library, it will then export a function named greet() which you can call. > loadlib('hello_world.dll', 'init')() > greet() Hello world! > Index: hello_world.cpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/examples/hello_world/hello_world.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- hello_world.cpp 25 Feb 2004 20:32:08 -0000 1.1 +++ hello_world.cpp 28 Nov 2005 20:55:34 -0000 1.2 @@ -1,4 +1,4 @@ -// Copyright (c) 2004 Daniel Wallin +// Copyright (c) 2005 Daniel Wallin and Arvid Norberg // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the "Software"), @@ -20,6 +20,13 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE // OR OTHER DEALINGS IN THE SOFTWARE. +extern "C" +{ + #include "lua.h" + #include "lualib.h" + #include "lauxlib.h" +} + #include <iostream> #include <luabind/luabind.hpp> Index: Jamfile =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/examples/hello_world/Jamfile,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- Jamfile 25 Feb 2004 20:32:08 -0000 1.1 +++ Jamfile 28 Nov 2005 20:55:34 -0000 1.2 @@ -5,5 +5,5 @@ lib hello_world : hello_world.cpp /luabind//luabind/<link>static /luabind//lua ; -stage bin : hello_world ; +stage . : hello_world ; |
From: Arvid N. <ar...@us...> - 2005-11-28 20:55:57
|
Update of /cvsroot/luabind/luabind/luabind/luabind In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15879/luabind/luabind Modified Files: adopt_policy.hpp back_reference.hpp back_reference_fwd.hpp class.hpp class_info.hpp config.hpp dependency_policy.hpp iterator_policy.hpp luabind.hpp object.hpp scope.hpp wrapper_base.hpp Added Files: from_stack.hpp get_pointer.hpp handle.hpp value_wrapper.hpp Removed Files: functor.hpp Log Message: merged in changes from beta7-devel2 (tag: beta7-devel2-merge) Index: object.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/object.hpp,v retrieving revision 1.34 retrieving revision 1.35 diff -u -d -r1.34 -r1.35 --- object.hpp 7 Aug 2004 13:37:10 -0000 1.34 +++ object.hpp 28 Nov 2005 20:55:34 -0000 1.35 @@ -1,4 +1,4 @@ -// Copyright (c) 2003 Daniel Wallin and Arvid Norberg +// Copyright (c) 2005 Daniel Wallin and Arvid Norberg // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the "Software"), @@ -20,1481 +20,1045 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE // OR OTHER DEALINGS IN THE SOFTWARE. -#if !BOOST_PP_IS_ITERATING - [...2311 lines suppressed...] - template<BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), class A)> -#endif - detail::proxy_caller<boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> > - operator()(BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_OPERATOR_PARAMS, _)) const - { - typedef boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> tuple_t; -#if BOOST_PP_ITERATION() == 0 - tuple_t args; -#else - tuple_t args(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), &a)); -#endif - return detail::proxy_caller<tuple_t>(const_cast<luabind::object*>(this), args); - } +} // namespace luabind -#undef LUABIND_OPERATOR_PARAMS -#undef LUABIND_TUPLE_PARAMS +#endif // LUABIND_OBJECT_050419_HPP -#endif Index: config.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/config.hpp,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- config.hpp 7 Aug 2004 13:37:10 -0000 1.10 +++ config.hpp 28 Nov 2005 20:55:34 -0000 1.11 @@ -129,6 +129,10 @@ // you can set LUABIND_EXPORT to __declspec(dllexport) // and LUABIND_IMPORT to __declspec(dllimport) +#if _GNUC_ >= 4 +#define LUABIND_API __attribute__ ((visibility("default"))) +#else + // this define is set if we're currently building a luabind file // select import or export depending on it #ifdef LUABIND_BUILDING @@ -145,5 +149,7 @@ #endif #endif +#endif + #endif // LUABIND_CONFIG_HPP_INCLUDED Index: dependency_policy.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/dependency_policy.hpp,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- dependency_policy.hpp 29 Aug 2003 10:55:40 -0000 1.5 +++ dependency_policy.hpp 28 Nov 2005 20:55:34 -0000 1.6 @@ -73,12 +73,22 @@ } template<class A, class B> - detail::policy_cons<detail::dependency_policy<detail::get_index_workaround<A>::value, detail::get_index_workaround<B>::value>, detail::null_type> dependency(A,B) { return detail::policy_cons<detail::dependency_policy<detail::get_index_workaround<A>::value, detail::get_index_workaround<B>::value>, detail::null_type>(); } + detail::policy_cons<detail::dependency_policy<detail::get_index_workaround<A>::value + , detail::get_index_workaround<B>::value>, detail::null_type> dependency(A,B) + { + return detail::policy_cons<detail::dependency_policy< + detail::get_index_workaround<A>::value, detail::get_index_workaround<B>::value> + , detail::null_type>(); + } template<class A> - detail::policy_cons<detail::dependency_policy<0, detail::get_index_workaround<A>::value>, detail::null_type> + detail::policy_cons<detail::dependency_policy<0 + , detail::get_index_workaround<A>::value>, detail::null_type> return_internal_reference(A) - { return detail::policy_cons<detail::dependency_policy<0, detail::get_index_workaround<A>::value>, detail::null_type>(); } + { + return detail::policy_cons<detail::dependency_policy<0 + , detail::get_index_workaround<A>::value>, detail::null_type>(); + } } #else --- functor.hpp DELETED --- Index: wrapper_base.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/wrapper_base.hpp,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- wrapper_base.hpp 7 Aug 2004 13:37:10 -0000 1.2 +++ wrapper_base.hpp 28 Nov 2005 20:55:34 -0000 1.3 @@ -96,7 +96,7 @@ typename boost::mpl::if_<boost::is_void<R> , luabind::detail::proxy_member_void_caller<boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> > , luabind::detail::proxy_member_caller<R, boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> > >::type - call(char const* name BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_OPERATOR_PARAMS, _), detail::type<R>* = 0) const + call(char const* name BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_OPERATOR_PARAMS, _), detail::type_<R>* = 0) const { typedef boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> tuple_t; #if BOOST_PP_ITERATION() == 0 @@ -164,13 +164,13 @@ wrap_base const* self , char const* fn BOOST_PP_ENUM_TRAILING_BINARY_PARAMS(N, A, &a) - , detail::type<R>* = 0 + , detail::type_<R>* = 0 ) { return self->call( fn BOOST_PP_ENUM_TRAILING_PARAMS(N, a) - , (detail::type<R>*)0 + , (detail::type_<R>*)0 ); } Index: back_reference.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/back_reference.hpp,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- back_reference.hpp 7 Aug 2004 13:37:10 -0000 1.2 +++ back_reference.hpp 28 Nov 2005 20:55:34 -0000 1.3 @@ -20,175 +20,93 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE // OR OTHER DEALINGS IN THE SOFTWARE. -#ifndef BACK_REFERENCE_040510_HPP -#define BACK_REFERENCE_040510_HPP +#ifndef LUABIND_BACK_REFERENCE_040510_HPP +#define LUABIND_BACK_REFERENCE_040510_HPP #include <luabind/lua_include.hpp> #include <luabind/wrapper_base.hpp> +#include <luabind/detail/has_get_pointer.hpp> +#include <luabind/get_pointer.hpp> #include <boost/type_traits/is_polymorphic.hpp> +#include <boost/type_traits/is_const.hpp> #include <boost/mpl/if.hpp> namespace luabind { -#if !(defined(BOOST_MSVC) && BOOST_MSVC <= 1300) - template<class T> - T* get_pointer(T& ref) - { - return &ref; - } - - namespace detail { -#else - namespace detail { - - struct no_overload_tag {}; - - } // namespace detail - - detail::no_overload_tag get_pointer(...); - - namespace detail { - - typedef char(&yes_overload)[1]; - typedef char(&no_overload)[2]; - - no_overload check_overload(no_overload_tag); - template<class T> - yes_overload check_overload(T const&); - -#endif - - template<class T> - struct extract_wrap_base - { -# if defined(BOOST_MSVC) && BOOST_MSVC <= 1300 - BOOST_STATIC_CONSTANT(bool, - value = sizeof(check_overload(get_pointer(*(T*)0))) - == sizeof(yes_overload) - ); - - static wrap_base const* extract(T const* ptr) - { - return extract_impl(ptr, boost::mpl::bool_<value>()); - } - - static wrap_base const* extract_impl(T const* ptr, boost::mpl::true_) - { - return dynamic_cast<wrap_base const*>( - get_pointer(*ptr)); - } - - static wrap_base const* extract_impl(T const* ptr, boost::mpl::false_) - { - return dynamic_cast<wrap_base const*>(ptr); - } - - static wrap_base* extract(T* ptr) - { - return extract_impl(ptr, boost::mpl::bool_<value>()); - } - - static wrap_base* extract_impl(T* ptr, boost::mpl::true_) - { - return dynamic_cast<wrap_base*>( - get_pointer(*ptr)); - } - - static wrap_base* extract_impl(T* ptr, boost::mpl::false_) - { - return dynamic_cast<wrap_base*>(ptr); - } -# else - static wrap_base const* extract(T const* ptr) - { - return dynamic_cast<wrap_base const*>(get_pointer(*ptr)); - } - - static wrap_base* extract(T* ptr) - { - return dynamic_cast<wrap_base*>(get_pointer(*ptr)); - } -# endif - }; - - struct default_back_reference {}; - - template<class T> - struct back_reference_impl : default_back_reference - { - static bool extract(lua_State* L, T const* ptr) - { - if (!has_wrapper) return false; - - if (wrap_base const* p = extract_wrap_base<T>::extract(ptr)) - { - wrap_access::ref(*p).get(L); - return true; - } - - return false; - } - - static bool move(lua_State* L, T* ptr) - { - if (!has_wrapper) return false; - - if (wrap_base* p = extract_wrap_base<T>::extract(ptr)) - { - assert(wrap_access::ref(*p).m_strong_ref.is_valid()); - wrap_access::ref(*p).get(L); - wrap_access::ref(*p).m_strong_ref.reset(); - return true; - } - - return false; - } +namespace detail +{ + namespace mpl = boost::mpl; + + template<class T> + wrap_base const* get_back_reference_aux0(T const* p, mpl::true_) + { + return dynamic_cast<wrap_base const*>(p); + } - static bool has_wrapper; - }; + template<class T> + wrap_base const* get_back_reference_aux0(T const* p, mpl::false_) + { + return 0; + } - template<class T> - bool back_reference_impl<T>::has_wrapper = false; + template<class T> + wrap_base const* get_back_reference_aux(T const* p) + { + return get_back_reference_aux0(p, boost::is_polymorphic<T>()); + } - template<class T> - struct back_reference_do_nothing - { - static bool extract(lua_State*, T const*) - { - return false; - } + template<class T> + wrap_base const* get_back_reference_aux(T const& x, mpl::true_) + { + return get_back_reference_aux(get_pointer(x)); + } - static bool move(lua_State*, T*) - { - return false; - } - }; + template<class T> + wrap_base const* get_back_reference_aux(T const& x, mpl::false_) + { + return get_back_reference_aux(&x); + } - } // namespace detail + template<class T> + wrap_base const* get_back_reference(T const& x) + { + return detail::get_back_reference_aux( + x + , has_get_pointer<T>() + ); + } + +} // namespace detail +template<class T> +bool get_back_reference(lua_State* L, T const& x) +{ #ifndef LUABIND_NO_RTTI - - template<class T> - struct back_reference - : boost::mpl::if_< - boost::is_polymorphic<T> - , detail::back_reference_impl<T> - , detail::back_reference_do_nothing<T> - >::type + if (wrap_base const* w = detail::get_back_reference(x)) { - }; - -#else + detail::wrap_access::ref(*w).get(L); + return true; + } +#endif + return false; +} - template<class T> - struct back_reference - : detail::back_reference_do_nothing<T> +template<class T> +bool move_back_reference(lua_State* L, T const& x) +{ +#ifndef LUABIND_NO_RTTI + if (wrap_base* w = const_cast<wrap_base*>(detail::get_back_reference(x))) { - }; - + assert(detail::wrap_access::ref(*w).m_strong_ref.is_valid()); + detail::wrap_access::ref(*w).get(L); + detail::wrap_access::ref(*w).m_strong_ref.reset(); + return true; + } #endif + return false; +} } // namespace luabind -#endif // BACK_REFERENCE_040510_HPP +#endif // LUABIND_BACK_REFERENCE_040510_HPP --- NEW FILE: value_wrapper.hpp --- // Copyright (c) 2005 Daniel Wallin and Arvid Norberg // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the "Software"), // to deal in the Software without restriction, including without limitation // the rights to use, copy, modify, merge, publish, distribute, sublicense, // and/or sell copies of the Software, and to permit persons to whom the // Software is furnished to do so, subject to the following conditions: // The above copyright notice and this permission notice shall be included // in all copies or substantial portions of the Software. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF // ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A // PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT // SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR // ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE // OR OTHER DEALINGS IN THE SOFTWARE. #ifndef LUABIND_VALUE_WRAPPER_050419_HPP #define LUABIND_VALUE_WRAPPER_050419_HPP #include <boost/mpl/integral_c.hpp> #include <boost/mpl/bool.hpp> #include <boost/mpl/aux_/msvc_eti_base.hpp> #ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION # define LUABIND_USE_VALUE_WRAPPER_TAG #else #endif #ifdef LUABIND_USE_VALUE_WRAPPER_TAG # include <boost/mpl/identity.hpp> # include <boost/mpl/eval_if.hpp> # include <boost/mpl/has_xxx.hpp> # include <boost/mpl/not.hpp> # include <boost/mpl/and.hpp> # include <boost/mpl/or.hpp> # include <boost/type_traits/is_reference.hpp> # include <boost/type_traits/is_pointer.hpp> # include <boost/type_traits/is_array.hpp> #endif namespace luabind { // // Concept ``ValueWrapper`` // #ifdef LUABIND_USE_VALUE_WRAPPER_TAG template<class T> struct value_wrapper_traits; namespace detail { BOOST_MPL_HAS_XXX_TRAIT_DEF(value_wrapper_tag); struct unspecialized_value_wrapper_traits { typedef boost::mpl::false_ is_specialized; }; template<class T> struct value_wrapper_traits_aux { typedef value_wrapper_traits<typename T::value_wrapper_tag> type; }; } // namespace detail #endif template<class T> struct value_wrapper_traits #ifdef LUABIND_USE_VALUE_WRAPPER_TAG : boost::mpl::eval_if< boost::mpl::and_< boost::mpl::not_< boost::mpl::or_< boost::is_reference<T> , boost::is_pointer<T> , boost::is_array<T> > > , detail::has_value_wrapper_tag<T> > , detail::value_wrapper_traits_aux<T> , boost::mpl::identity<detail::unspecialized_value_wrapper_traits> >::type {}; #else { typedef boost::mpl::false_ is_specialized; }; #endif template<class T> struct is_value_wrapper : boost::mpl::aux::msvc_eti_base< typename value_wrapper_traits<T>::is_specialized >::type {}; } // namespace luabind #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION # include <boost/type_traits/remove_const.hpp> # include <boost/type_traits/remove_reference.hpp> namespace luabind { template<class T> struct is_value_wrapper_arg : is_value_wrapper< typename boost::remove_const< typename boost::remove_reference<T>::type >::type > {}; } // namespace luabind #else # include <luabind/detail/yes_no.hpp> # include <boost/type_traits/add_reference.hpp> namespace luabind { namespace detail { template<class T> typename is_value_wrapper<T>::type is_value_wrapper_arg_check(T const*); yes_t to_yesno(boost::mpl::true_); no_t to_yesno(boost::mpl::false_); template<class T> struct is_value_wrapper_arg_aux { static typename boost::add_reference<T>::type x; BOOST_STATIC_CONSTANT(bool, value = sizeof(to_yesno(is_value_wrapper_arg_check(&x))) == sizeof(yes_t) ); typedef boost::mpl::bool_<value> type; }; } // namespace detail template<class T> struct is_value_wrapper_arg : detail::is_value_wrapper_arg_aux<T>::type { }; } // namespace luabind #endif #endif // LUABIND_VALUE_WRAPPER_050419_HPP Index: back_reference_fwd.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/back_reference_fwd.hpp,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- back_reference_fwd.hpp 7 Aug 2004 13:37:10 -0000 1.2 +++ back_reference_fwd.hpp 28 Nov 2005 20:55:34 -0000 1.3 @@ -20,14 +20,18 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE // OR OTHER DEALINGS IN THE SOFTWARE. -#ifndef BACK_REFERENCE_FWD_040510_HPP -#define BACK_REFERENCE_FWD_040510_HPP +#ifndef LUABIND_BACK_REFERENCE_FWD_040510_HPP +#define LUABIND_BACK_REFERENCE_FWD_040510_HPP namespace luabind { - template<class T> struct back_reference; +template<class T> +bool get_back_reference(lua_State* L, T const& x); + +template<class T> +bool move_back_reference(lua_State* L, T const& x); } // namespace luabind -#endif // BACK_REFERENCE_FWD_040510_HPP +#endif // LUABIND_BACK_REFERENCE_FWD_040510_HPP Index: class_info.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/class_info.hpp,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- class_info.hpp 18 Feb 2004 01:18:58 -0000 1.3 +++ class_info.hpp 28 Nov 2005 20:55:34 -0000 1.4 @@ -27,15 +27,12 @@ #include <luabind/prefix.hpp> #include <luabind/lua_include.hpp> #include <luabind/luabind.hpp> +#include <luabind/object.hpp> namespace luabind { struct class_info - { - class_info(lua_State* L) - : methods(L) - {} - + { std::string name; object methods; object attributes; Index: adopt_policy.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/adopt_policy.hpp,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- adopt_policy.hpp 7 Aug 2004 13:37:10 -0000 1.10 +++ adopt_policy.hpp 28 Nov 2005 20:55:34 -0000 1.11 @@ -27,12 +27,17 @@ #include <luabind/config.hpp> #include <luabind/detail/policy.hpp> #include <luabind/detail/implicit_cast.hpp> +#include <boost/mpl/bool.hpp> +#include <luabind/back_reference_fwd.hpp> namespace luabind { namespace detail { template<class Direction = lua_to_cpp> struct adopt_pointer { + typedef boost::mpl::bool_<false> is_value_converter; + typedef adopt_pointer type; + template<class T> T* apply(lua_State* L, by_pointer<T>, int index) { @@ -75,6 +80,9 @@ template<> struct adopt_pointer<cpp_to_lua> { + typedef boost::mpl::bool_<false> is_value_converter; + typedef adopt_pointer type; + template<class T> void apply(lua_State* L, T* ptr) { @@ -87,7 +95,7 @@ // if there is a back_reference, then the // ownership will be removed from the // back reference and put on the lua stack. - if (back_reference<T>::move(L, ptr)) + if (luabind::move_back_reference(L, ptr)) { object_rep* obj = static_cast<object_rep*>(lua_touserdata(L, -1)); obj->set_flags(obj->flags() | object_rep::owner); Index: class.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/class.hpp,v retrieving revision 1.63 retrieving revision 1.64 diff -u -d -r1.63 -r1.64 --- class.hpp 3 Jan 2005 11:15:21 -0000 1.63 +++ class.hpp 28 Nov 2005 20:55:34 -0000 1.64 @@ -93,6 +93,7 @@ #include <luabind/config.hpp> #include <luabind/scope.hpp> +#include <luabind/raw_policy.hpp> #include <luabind/back_reference.hpp> #include <luabind/detail/constructor.hpp> #include <luabind/detail/call.hpp> @@ -127,16 +128,17 @@ struct unspecified {}; template<class Derived> struct operator_; - } - using detail::type; + struct you_need_to_define_a_get_const_holder_function_for_your_smart_ptr {}; + } template<class T, class X1 = detail::unspecified, class X2 = detail::unspecified, class X3 = detail::unspecified> struct class_; // TODO: this function will only be invoked if the user hasn't defined a correct overload // maybe we should have a static assert in here? - inline detail::null_type* get_const_holder(...) + inline detail::you_need_to_define_a_get_const_holder_function_for_your_smart_ptr* + get_const_holder(...) { return 0; } @@ -301,7 +303,7 @@ typedef void*(*extractor_fun)(void*); template<class T> - static extractor_fun apply(detail::type<T>) + static extractor_fun apply(detail::type_<T>) { return &detail::extract_underlying_type<T, HeldType>::extract; } @@ -313,7 +315,7 @@ typedef void*(*extractor_fun)(void*); template<class T> - static extractor_fun apply(detail::type<T>) + static extractor_fun apply(detail::type_<T>) { return 0; } @@ -363,13 +365,13 @@ typedef const void*(*extractor_fun)(void*); template<class T> - static extractor_fun apply(detail::type<T>) + static extractor_fun apply(detail::type_<T>) { - return get_extractor(detail::type<T>(), luabind::get_const_holder(static_cast<HeldType*>(0))); + return get_extractor(detail::type_<T>(), get_const_holder(static_cast<HeldType*>(0))); } private: template<class T, class ConstHolderType> - static extractor_fun get_extractor(detail::type<T>, ConstHolderType*) + static extractor_fun get_extractor(detail::type_<T>, ConstHolderType*) { return &detail::extract_underlying_const_type<T, ConstHolderType>::extract; } @@ -381,7 +383,7 @@ typedef const void*(*extractor_fun)(void*); template<class T> - static extractor_fun apply(detail::type<T>) + static extractor_fun apply(detail::type_<T>) { return 0; } @@ -439,7 +441,7 @@ { typedef void(*constructor)(void*,void*); template<class T> - static constructor apply(detail::type<T>) + static constructor apply(detail::type_<T>) { return &internal_construct_holder<HeldType, T>::apply; } @@ -450,7 +452,7 @@ { typedef void(*constructor)(void*,void*); template<class T> - static constructor apply(detail::type<T>) + static constructor apply(detail::type_<T>) { return 0; } @@ -464,15 +466,15 @@ { typedef void(*constructor)(void*,void*); template<class T> - static constructor apply(detail::type<T>) + static constructor apply(detail::type_<T>) { - return get_const_holder_constructor(detail::type<T>(), luabind::get_const_holder(static_cast<HolderType*>(0))); + return get_const_holder_constructor(detail::type_<T>(), get_const_holder(static_cast<HolderType*>(0))); } private: template<class T, class ConstHolderType> - static constructor get_const_holder_constructor(detail::type<T>, ConstHolderType*) + static constructor get_const_holder_constructor(detail::type_<T>, ConstHolderType*) { return &internal_construct_holder<ConstHolderType, T>::apply; } @@ -483,7 +485,7 @@ { typedef void(*constructor)(void*,void*); template<class T> - static constructor apply(detail::type<T>) + static constructor apply(detail::type_<T>) { return 0; } @@ -498,7 +500,7 @@ { typedef void(*constructor)(void*); template<class T> - static constructor apply(detail::type<T>) + static constructor apply(detail::type_<T>) { return &internal_default_construct_holder<HeldType, T>::apply; } @@ -509,7 +511,7 @@ { typedef void(*constructor)(void*); template<class T> - static constructor apply(detail::type<T>) + static constructor apply(detail::type_<T>) { return 0; } @@ -525,15 +527,15 @@ { typedef void(*constructor)(void*); template<class T> - static constructor apply(detail::type<T>) + static constructor apply(detail::type_<T>) { - return get_const_holder_default_constructor(detail::type<T>(), luabind::get_const_holder(static_cast<HolderType*>(0))); + return get_const_holder_default_constructor(detail::type_<T>(), get_const_holder(static_cast<HolderType*>(0))); } private: template<class T, class ConstHolderType> - static constructor get_const_holder_default_constructor(detail::type<T>, ConstHolderType*) + static constructor get_const_holder_default_constructor(detail::type_<T>, ConstHolderType*) { return &internal_default_construct_holder<ConstHolderType, T>::apply; } @@ -544,7 +546,7 @@ { typedef void(*constructor)(void*); template<class T> - static constructor apply(detail::type<T>) + static constructor apply(detail::type_<T>) { return 0; } @@ -558,7 +560,7 @@ template <class HolderType> struct internal_holder_size { - static int apply() { return get_internal_holder_size(luabind::get_const_holder(static_cast<HolderType*>(0))); } + static int apply() { return get_internal_holder_size(get_const_holder(static_cast<HolderType*>(0))); } private: template<class ConstHolderType> static int get_internal_holder_size(ConstHolderType*) @@ -582,7 +584,7 @@ { typedef void(*destructor_t)(void*); template<class T> - static destructor_t apply(detail::type<T>) + static destructor_t apply(detail::type_<T>) { return &detail::destruct_only_s<HeldType>::apply; } @@ -594,7 +596,7 @@ { typedef void(*destructor_t)(void*); template<class T> - static destructor_t apply(detail::type<T>) + static destructor_t apply(detail::type_<T>) { return &detail::delete_s<T>::apply; } @@ -607,9 +609,9 @@ { typedef void(*destructor_t)(void*); template<class T> - static destructor_t apply(detail::type<T>) + static destructor_t apply(detail::type_<T>) { - return const_holder_type_destructor(luabind::get_const_holder(static_cast<HolderType*>(0))); + return const_holder_type_destructor(get_const_holder(static_cast<HolderType*>(0))); } private: @@ -628,7 +630,7 @@ { typedef void(*destructor_t)(void*); template<class T> - static destructor_t apply(detail::type<T>) + static destructor_t apply(detail::type_<T>) { return 0; } @@ -642,7 +644,7 @@ { static int apply() { - return internal_alignment(luabind::get_const_holder(static_cast<HolderType*>(0))); + return internal_alignment(get_const_holder(static_cast<HolderType*>(0))); } private: @@ -820,7 +822,7 @@ // in the given class_rep structure. It will be able // to implicitly cast to the given template type template<class To> - void gen_base_info(detail::type<To>) + void gen_base_info(detail::type_<To>) { // fist, make sure the given base class is registered. // if it's not registered we can't push it's lua table onto @@ -833,17 +835,17 @@ // store the information in this class' base class-vector base_desc base; base.type = LUABIND_TYPEID(To); - base.ptr_offset = detail::ptr_offset(detail::type<T>(), detail::type<To>()); + base.ptr_offset = detail::ptr_offset(detail::type_<T>(), detail::type_<To>()); add_base(base); } - void gen_base_info(detail::type<detail::null_type>) + void gen_base_info(detail::type_<detail::null_type>) {} -#define LUABIND_GEN_BASE_INFO(z, n, text) gen_base_info(detail::type<B##n>()); +#define LUABIND_GEN_BASE_INFO(z, n, text) gen_base_info(detail::type_<B##n>()); template<BOOST_PP_ENUM_PARAMS(LUABIND_MAX_BASES, class B)> - void generate_baseclass_list(detail::type<bases<BOOST_PP_ENUM_PARAMS(LUABIND_MAX_BASES, B)> >) + void generate_baseclass_list(detail::type_<bases<BOOST_PP_ENUM_PARAMS(LUABIND_MAX_BASES, B)> >) { BOOST_PP_REPEAT(LUABIND_MAX_BASES, LUABIND_GEN_BASE_INFO, _) } @@ -1139,8 +1141,6 @@ void init() { - set_back_reference((back_reference<T>*)0); - typedef typename detail::extract_parameter< boost::mpl::list3<X1,X2,X3> , boost::mpl::or_< @@ -1160,21 +1160,21 @@ , detail::internal_holder_type<HeldType>::apply() , detail::pointee_typeid( get_const_holder(static_cast<HeldType*>(0))) - , detail::internal_holder_extractor<HeldType>::apply(detail::type<T>()) - , detail::internal_const_holder_extractor<HeldType>::apply(detail::type<T>()) + , detail::internal_holder_extractor<HeldType>::apply(detail::type_<T>()) + , detail::internal_const_holder_extractor<HeldType>::apply(detail::type_<T>()) , detail::const_converter<HeldType>::apply( - luabind::get_const_holder((HeldType*)0)) - , detail::holder_constructor<HeldType>::apply(detail::type<T>()) - , detail::const_holder_constructor<HeldType>::apply(detail::type<T>()) - , detail::holder_default_constructor<HeldType>::apply(detail::type<T>()) - , detail::const_holder_default_constructor<HeldType>::apply(detail::type<T>()) + get_const_holder((HeldType*)0)) + , detail::holder_constructor<HeldType>::apply(detail::type_<T>()) + , detail::const_holder_constructor<HeldType>::apply(detail::type_<T>()) + , detail::holder_default_constructor<HeldType>::apply(detail::type_<T>()) + , detail::const_holder_default_constructor<HeldType>::apply(detail::type_<T>()) , get_adopt_fun((WrappedType*)0) // adopt fun - , detail::internal_holder_destructor<HeldType>::apply(detail::type<T>()) - , detail::internal_const_holder_destructor<HeldType>::apply(detail::type<T>()) + , detail::internal_holder_destructor<HeldType>::apply(detail::type_<T>()) + , detail::internal_const_holder_destructor<HeldType>::apply(detail::type_<T>()) , detail::internal_holder_size<HeldType>::apply() , detail::get_holder_alignment<HeldType>::apply()); - generate_baseclass_list(detail::type<Base>()); + generate_baseclass_list(detail::type_<Base>()); } template<class Getter, class GetPolicies> @@ -1209,7 +1209,7 @@ // these handle default implementation of virtual functions template<class F, class Policies> class_& virtual_def(char const* name, F const& fn - , Policies const& policies, detail::null_type, boost::mpl::true_) + , Policies const&, detail::null_type, boost::mpl::true_) { // normal def() call detail::overload_rep o(fn, static_cast<Policies*>(0)); @@ -1226,7 +1226,7 @@ template<class F, class Default, class Policies> class_& virtual_def(char const* name, F const& fn - , Default const& default_, Policies const& policies, boost::mpl::false_) + , Default const& default_, Policies const&, boost::mpl::false_) { // default_ is a default implementation // policies is either null_type or a policy list @@ -1253,7 +1253,7 @@ class_& def_constructor( boost::mpl::true_ /* HasWrapper */ , Signature* - , Policies const& policies) + , Policies const&) { detail::construct_rep::overload_t o; @@ -1283,7 +1283,7 @@ class_& def_constructor( boost::mpl::false_ /* !HasWrapper */ , Signature* - , Policies const& policies) + , Policies const&) { detail::construct_rep::overload_t o; @@ -1310,16 +1310,6 @@ return *this; } - void set_back_reference(detail::default_back_reference*) - { - back_reference<T>::has_wrapper - = !boost::is_same<WrappedType, detail::null_type>::value; - } - - void set_back_reference(void*) - { - } - typedef void(*adopt_fun_t)(void*); template<class W> --- NEW FILE: from_stack.hpp --- // Copyright (c) 2005 Daniel Wallin and Arvid Norberg // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the "Software"), // to deal in the Software without restriction, including without limitation // the rights to use, copy, modify, merge, publish, distribute, sublicense, // and/or sell copies of the Software, and to permit persons to whom the // Software is furnished to do so, subject to the following conditions: // The above copyright notice and this permission notice shall be included // in all copies or substantial portions of the Software. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF // ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A // PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT // SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR // ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE // OR OTHER DEALINGS IN THE SOFTWARE. #ifndef LUABIND_FROM_STACK_050715_HPP #define LUABIND_FROM_STACK_050715_HPP namespace luabind { struct from_stack { from_stack(lua_State* interpreter, int index) : interpreter(interpreter) , index(index) {} lua_State* interpreter; int index; }; } // namespace luabind #endif // LUABIND_FROM_STACK_050715_HPP Index: luabind.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/luabind.hpp,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- luabind.hpp 17 Feb 2004 21:56:21 -0000 1.3 +++ luabind.hpp 28 Nov 2005 20:55:34 -0000 1.4 @@ -27,7 +27,6 @@ #include <luabind/config.hpp> #include <luabind/class.hpp> #include <luabind/function.hpp> -#include <luabind/functor.hpp> #include <luabind/open.hpp> #endif // LUABIND_BIND_HPP_INCLUDED --- NEW FILE: get_pointer.hpp --- // Copyright (c) 2005 Daniel Wallin // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the "Software"), // to deal in the Software without restriction, including without limitation // the rights to use, copy, modify, merge, publish, distribute, sublicense, // and/or sell copies of the Software, and to permit persons to whom the // Software is furnished to do so, subject to the following conditions: // The above copyright notice and this permission notice shall be included // in all copies or substantial portions of the Software. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF // ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A // PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT // SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR // ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE // OR OTHER DEALINGS IN THE SOFTWARE. #ifndef LUABIND_GET_POINTER_051023_HPP # define LUABIND_GET_POINTER_051023_HPP // // We need these overloads in the luabind namespace. // # include <boost/get_pointer.hpp> namespace luabind { using boost::get_pointer; } // namespace luabind #endif // LUABIND_GET_POINTER_051023_HPP --- NEW FILE: handle.hpp --- // Copyright (c) 2005 Daniel Wallin and Arvid Norberg // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the "Software"), // to deal in the Software without restriction, including without limitation // the rights to use, copy, modify, merge, publish, distribute, sublicense, // and/or sell copies of the Software, and to permit persons to whom the // Software is furnished to do so, subject to the following conditions: // The above copyright notice and this permission notice shall be included // in all copies or substantial portions of the Software. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF // ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A // PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT // SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR // ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE // OR OTHER DEALINGS IN THE SOFTWARE. #ifndef LUABIND_HANDLE_050420_HPP #define LUABIND_HANDLE_050420_HPP #include <luabind/lua_include.hpp> #include <luabind/value_wrapper.hpp> #include <luabind/detail/ref.hpp> namespace luabind { // A reference to a Lua value. Represents an entry in the // registry table. class handle { public: handle(); handle(lua_State* interpreter, int stack_index); handle(handle const& other); ~handle(); handle& operator=(handle const& other); void swap(handle& other); void push(lua_State* interpreter) const; lua_State* interpreter() const; void replace(lua_State* interpreter, int stack_index); private: lua_State* m_interpreter; int m_index; }; inline handle::handle() : m_interpreter(0) , m_index(LUA_NOREF) {} inline handle::handle(handle const& other) : m_interpreter(other.m_interpreter) , m_index(LUA_NOREF) { detail::getref(m_interpreter, other.m_index); m_index = detail::ref(m_interpreter); } inline handle::handle(lua_State* interpreter, int stack_index) : m_interpreter(interpreter) , m_index(LUA_NOREF) { lua_pushvalue(interpreter, stack_index); m_index = detail::ref(interpreter); } inline handle::~handle() { if (m_interpreter && m_index != LUA_NOREF) detail::unref(m_interpreter, m_index); } inline handle& handle::operator=(handle const& other) { handle(other).swap(*this); return *this; } inline void handle::swap(handle& other) { std::swap(m_interpreter, other.m_interpreter); std::swap(m_index, other.m_index); } inline void handle::push(lua_State* interpreter) const { detail::getref(interpreter, m_index); } inline lua_State* handle::interpreter() const { return m_interpreter; } inline void handle::replace(lua_State* interpreter, int stack_index) { lua_pushvalue(interpreter, stack_index); lua_rawseti(interpreter, LUA_REGISTRYINDEX, m_index); } template<> struct value_wrapper_traits<handle> { typedef boost::mpl::true_ is_specialized; static lua_State* interpreter(handle const& value) { return value.interpreter(); } static void unwrap(lua_State* interpreter, handle const& value) { value.push(interpreter); } static bool check(...) { return true; } }; } // namespace luabind #endif // LUABIND_HANDLE_050420_HPP Index: iterator_policy.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/iterator_policy.hpp,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- iterator_policy.hpp 5 Jul 2003 22:13:59 -0000 1.3 +++ iterator_policy.hpp 28 Nov 2005 20:55:34 -0000 1.4 @@ -28,6 +28,7 @@ #include <luabind/detail/policy.hpp> #include <luabind/detail/implicit_cast.hpp> #include <luabind/detail/convert_to_lua.hpp> +#include <boost/mpl/bool.hpp> namespace luabind { namespace detail { @@ -64,6 +65,9 @@ struct iterator_converter { + typedef boost::mpl::bool_<false> is_value_converter; + typedef iterator_converter type; + template<class T> void apply(lua_State* L, const T& c) { Index: scope.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/scope.hpp,v retrieving revision 1.16 retrieving revision 1.17 diff -u -d -r1.16 -r1.17 --- scope.hpp 20 Feb 2004 15:04:54 -0000 1.16 +++ scope.hpp 28 Nov 2005 20:55:34 -0000 1.17 @@ -45,7 +45,7 @@ virtual void register_(lua_State*) const = 0; private: - friend struct scope; + friend struct ::luabind::scope; registration* m_next; }; |
From: Arvid N. <ar...@us...> - 2005-11-28 20:55:47
|
Update of /cvsroot/luabind/luabind/luabind/doc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15879/luabind/doc Modified Files: docs.html docs.rst Added Files: changes.txt Log Message: merged in changes from beta7-devel2 (tag: beta7-devel2-merge) Index: docs.html =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/doc/docs.html,v retrieving revision 1.52 retrieving revision 1.53 diff -u -d -r1.52 -r1.53 --- docs.html 10 Aug 2004 22:27:06 -0000 1.52 +++ docs.html 28 Nov 2005 20:55:33 -0000 1.53 @@ -1,13 +1,13 @@ -<?xml version="1.0" encoding="Latin1" ?> +<?xml version="1.0" encoding="utf-8" ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> -<meta http-equiv="Content-Type" content="text/html; charset=Latin1" /> -<meta name="generator" content="Docutils 0.3.1: http://docutils.sourceforge.net/" /> +<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> +<meta name="generator" content="Docutils 0.3.8: http://docutils.sourceforge.net/" /> <title>luabind</title> <meta name="author" content="Daniel Wallin, Arvid Norberg" /> [...2290 lines suppressed...] </div> <div class="section" id="acknowledgments"> -<h1><a name="acknowledgments">19 Acknowledgments</a></h1> -<p>Written by Daniel Wallin and Arvid Norberg. © Copyright 2003. +<h1><a name="acknowledgments">19 Acknowledgments</a></h1> +<p>Written by Daniel Wallin and Arvid Norberg. © Copyright 2003. All rights reserved.</p> <p>Evan Wies has contributed with thorough testing, countless bug reports and feature ideas.</p> <p>This library was highly inspired by Dave Abrahams' <a class="reference" href="http://www.boost.org/libraries/python">Boost.Python</a> library.</p> </div> </div> -<hr class="footer" /> -<div class="footer"> -<a class="reference" href="docs.rst">View document source</a>. -Generated on: 2004-08-10 22:26 UTC. -Generated by <a class="reference" href="http://docutils.sourceforge.net/">Docutils</a> from <a class="reference" href="http://docutils.sourceforge.net/rst.html">reStructuredText</a> source. -</div> </body> </html> Index: docs.rst =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/doc/docs.rst,v retrieving revision 1.25 retrieving revision 1.26 diff -u -d -r1.25 -r1.26 --- docs.rst 19 Jan 2005 08:24:49 -0000 1.25 +++ docs.rst 28 Nov 2005 20:55:33 -0000 1.26 @@ -36,6 +36,7 @@ .. contents:: :depth: 2 + :backlinks: none .. section-numbering:: Introduction @@ -62,6 +63,11 @@ We are very interested in hearing about projects that use luabind, please let us know about your project. +The main channel for help and feedback is the `luabind mailing list`_. +There's also an IRC channel ``#luabind`` on irc.freenode.net. + +.. _`luabind mailing list`: https://lists.sourceforge.net/lists/listinfo/luabind-user + Features ======== @@ -97,7 +103,9 @@ - GCC 3.0.4 (Debian/Linux) - GCC 3.1 (SunOS 5.8) - GCC 3.2 (cygwin) - - GCC 3.3.1 (cygwin) + - GCC 3.3.1 (cygwin) + - GCC 3.3 (Apple, MacOS X) + - GCC 4.0 (Apple, MacOS X) It has been confirmed not to work with: @@ -117,8 +125,8 @@ To keep down the compilation-time luabind is built as a library. This means you have to either build it and link against it, or include its source files in your project. You also have to make sure the luabind directory is somewhere in -your compiler's include path. It requires `Boost`_ 1.31.0 to be installed (only -boost headers). It also requires that Lua is installed. +your compiler's include path. It requires `Boost`_ 1.32.0 or 1.33.0 to be +installed (only boost headers). It also requires that Lua is installed. The official way of building luabind is with `Boost.Build V2`_. To properly build luabind with Boost.Build you need to set two environment variables: @@ -132,7 +140,7 @@ ``$(LUA_PATH)/lib/.`` For backward compatibility, there is also a makefile in the root-directory that -will build the library and the test program. If you are using a UNIX-system (or +will build the library and the test programs. If you are using a UNIX-system (or cygwin) they will make it easy to build luabind as a static library. If you are using Visual Studio it may be easier to include the files in the src directory in your project. @@ -392,8 +400,8 @@ Calling Lua functions --------------------- -To call a Lua function, you can either use ``call_function()``, -an ``object`` or ``functor``. +To call a Lua function, you can either use ``call_function()`` or +an ``object``. :: @@ -432,6 +440,9 @@ int ret = call_function(L, "fun", boost::ref(val)); +If you want to use a custom error handler for the function call, see +``set_pcall_callback`` under Configuration_. + Using Lua threads ----------------- @@ -536,6 +547,39 @@ const member function (it can be called on const objects). +Overloaded member functions +--------------------------- + +When binding more than one overloads of a member function, or just binding +one overload of an overloaded member function, you have to disambiguate +the member function pointer you pass to ``def``. To do this, you can use an +ordinary C-style cast, to cast it to the right overload. To do this, you have +to know how to express member function types in C++, here's a short tutorial +(for more info, refer to your favourite book on C++). + +The syntax for member function pointer follows: + +.. parsed-literal:: + + *return-value* (*class-name*::\*)(*arg1-type*, *arg2-type*, *...*) + +Here's an example illlustrating this:: + + struct A + { + void f(int); + void f(int, int); + }; + +:: + + class_<A>() + .def("f", (void(A::*)(int))&A::f) + +This selects the first overload of the function ``f`` to bind. The second +overload is not bound. + + Properties ---------- @@ -561,9 +605,28 @@ module(L) [ class_<A>("A") - .def_readonly("a", &A::a) + .def_readonly("a", &A::a) ]; +When binding members that are a non-primitive type, the auto generated getter +function will return a reference to it. This is to allow chained .-operators. +For example, when having a struct containing another struct. Like this:: + + struct A { int m; }; + struct B { A a; }; + +When binding ``B`` to lua, the following expression code should work:: + + b = B() + b.a.m = 1 + assert(b.a.m == 1) + +This requires the first lookup (on ``a``) to return a reference to ``A``, and +not a copy. In that case, luabind will automatically use the dependency policy +to make the return value dependent on the object in which it is stored. So, if +the returned reference lives longer than all references to the object (b in +this case) it will keep the object alive, to avoid being a dangling pointer. + You can also register getter and setter functions and make them look as if they were a public data member. Consider the following class:: @@ -584,7 +647,8 @@ This way the ``get_a()`` and ``set_a()`` functions will be called instead of just writing to the data member. If you want to make it read only you can just -omit the last parameter. +omit the last parameter. Please note that the get function **has to be +const**, otherwise it won't compile. This seems to be a common source of errors. Enums @@ -621,6 +685,8 @@ Operators --------- +To bind operators you have to include ``<luabind/operator.hpp>``. + The mechanism for registering operators on your class is pretty simple. You use a global name ``luabind::self`` to refer to the class itself and then you just write the operator expression inside the ``def()`` call. This class:: @@ -643,7 +709,7 @@ This will work regardless if your plus operator is defined inside your class or as a free function. -If you operator is const (or, when defined as a free function, takes a const +If your operator is const (or, when defined as a free function, takes a const reference to the class itself) you have to use ``const_self`` instead of ``self``. Like this: @@ -659,12 +725,17 @@ .. parsed-literal:: - + - \* / == != < <= > >= + + - \* / == < <= This means, no in-place operators. The equality operator (``==``) has a little hitch; it will not be called if the references are equal. This means that the ``==`` operator has to do pretty much what's it's expected to do. +Lua does not support operators such as ``!=``, ``>`` or ``>=``. That's why you +can only register the operators listed above. When you invoke one of the +mentioned operators, lua will define it in terms of one of the avaliable +operators. + In the above example the other operand type is instantiated by writing ``int()``. If the operand type is a complex type that cannot easily be instantiated you can wrap the type in a class called ``other<>``. For example: @@ -689,7 +760,7 @@ .def(self + **other<std::string>()**) ]; -To register an application operator: +To register an application (function call-) operator: .. parsed-literal:: @@ -702,7 +773,7 @@ There's one special operator. In Lua it's called ``__tostring``, it's not really an operator. It is used for converting objects to strings in a standard way in Lua. If you register this functionality, you will be able to use the lua -standard function ``tostring()`` for converting you object to a string. +standard function ``tostring()`` for converting your object to a string. To implement this operator in C++ you should supply an ``operator<<`` for std::ostream. Like this example: @@ -737,6 +808,9 @@ def("f", &f) ]**; +In this example, ``f`` will behave like a static member function of the class +``foo``, and the class ``nested`` will behave like a nested class of ``foo``. + It's also possible to add namespace's to classes using the same syntax. @@ -798,7 +872,7 @@ namespace luabind { template<class T> - T* get_pointer(boost::shared_ptr<T> const& p) + T* get_pointer(boost::shared_ptr<T>& p) { return p.get(); } @@ -811,6 +885,11 @@ } } +The second function will only be used to get a compile time mapping +of ``boost::shared_ptr<A>`` to its const version, +``boost::shared_ptr<const A>``. It will never be called, so the +return value doesn't matter (only the return type). + The conversion that works are (given that B is a base class of A): .. topic:: From Lua to C++ @@ -840,10 +919,10 @@ ``holder_type<A const> const&`` ``holder_type<A const>`` =============================== ======================== -When using a holder type, it can be useful to know if the pointer is valid. For -example when using std::auto_ptr, the holder will be invalidated when passed as -a parameter to a function. For this purpose there is a member of all object -instances in luabind: ``__ok``. :: +When using a holder type, it can be useful to know if the pointer is valid +(i.e. not null). For example when using std::auto_ptr, the holder will be +invalidated when passed as a parameter to a function. For this purpose there +is a member of all object instances in luabind: ``__ok``. :: struct X {}; void f(std::auto_ptr<X>); @@ -865,13 +944,66 @@ false +When registering a hierarchy of classes, where all instances are to be held +by a smart pointer, all the classes should have the baseclass' holder type. +Like this: + +.. parsed-literal:: + + module(L) + [ + class_<base, boost::shared_ptr<base> >("base") + .def(constructor<>()), + class_<derived, base, **boost::shared_ptr<base>** >("base") + .def(constructor<>()) + ]; + +Internally, luabind will do the necessary conversions on the raw pointers, which +are first extracted from the holder type. + + +Splitting class registrations +----------------------------- + +In some situations it may be desirable to split a registration of a class +across different compilation units. Partly to save rebuild time when changing +in one part of the binding, and in some cases compiler limits may force you +to split it. To do this is very simple. Consider the following sample code:: + + void register_part1(class_<X>& x) + { + x.def(/*...*/); + } + + void register_part2(class_<X>& x) + { + x.def(/*...*/); + } + + void register_(lua_State* L) + { + class_<X> x("x"); + + register_part1(x); + register_part2(x); + + module(L) [ x ]; + } + +Here, the class ``X`` is registered in two steps. The two functions +``register_part1`` and ``register_part2`` may be put in separate compilation +units. + +To separate the module registration and the classes to be registered, see +`Splitting up the registration`_. + Object ====== Since functions have to be able to take Lua values (of variable type) we need a wrapper around them. This wrapper is called ``luabind::object``. If the function you register takes an object, it will match any Lua value. To use it, -you need to include ``luabind/object.hpp``. +you need to include ``<luabind/object.hpp>``. .. topic:: Synopsis @@ -880,46 +1012,26 @@ class object { public: - class iterator; - class raw_iterator; - class array_iterator; - template<class T> object(lua_State\*, T const& value); + object(from_stack const&); object(object const&); - object(lua_State\*); object(); ~object(); - - iterator begin() const; - iterator end() const; - raw_iterator raw_begin() const; - raw_iterator raw_end() const; - array_iterator abegin() const; - array_iterator aend() const; - void set(); - lua_State\* lua_state() const; - void pushvalue() const; + lua_State\* interpreter() const; + void push() const; bool is_valid() const; - operator safe_bool_type() const; + operator *safe_bool_type* () const; template<class Key> *implementation-defined* operator[](Key const&); - template<class Key> - object at(Key const&) const; - - template<class Key> - object raw_at(Key const&) const; - template<class T> object& operator=(T const&); object& operator=(object const&); - template<class T> - bool operator==(T const&) const; bool operator==(object const&) const; bool operator<(object const&) const; bool operator<=(object const&) const; @@ -927,8 +1039,10 @@ bool operator>=(object const&) const; bool operator!=(object const&) const; + template <class T> + *implementation-defined* operator[](T const& key) const + void swap(object&); - int type() const; *implementation-defined* operator()(); @@ -944,33 +1058,35 @@ When you have a Lua object, you can assign it a new value with the assignment operator (=). When you do this, the ``default_policy`` will be used to make the conversion from C++ value to Lua. If your ``luabind::object`` is a table you -can access its members through the operator[] or the iterators. The value +can access its members through the operator[] or the Iterators_. The value returned from the operator[] is a proxy object that can be used both for reading and writing values into the table (using operator=). Note that it is impossible to know if a Lua value is indexable or not (lua_gettable doesn't fail, it succeeds or crashes). This means that if you're trying to index something that cannot be indexed, you're on your own. Lua will call its ``panic()`` function (you can define your own panic function using -``lua_setpanicf``). The ``at()`` and ``raw_at()`` functions returns the value at -the given table position (like operator[] but only for reading). +``lua_setpanicf``). There are also free functions that can be used for +indexing the table, see `Related functions`_. -The ordinary ``object::iterator`` uses lua_gettable to extract the values from -the table, the standard way that will invoke metamethods if any. The -``object::raw_iterator`` uses lua_rawget and ``object::array_iterator`` uses -lua_rawgeti. The latter will only iterate over numerical keys starting at 1 -and continue until the first nil value. +The constructor that takes a ``from_stack`` object is used when you want to +initialize the object with a value from the lua stack. The ``from_stack`` +type has the following constructor:: -The ``lua_state()`` function returns the Lua state where this object is stored. + from_stack(lua_State* L, int index); + +The index is an ordinary lua stack index, negative values are indexed from the +top of the stack. You use it like this:: + + object o(from_stack(L, -1)); + +This will create the object ``o`` and copy the value from the top of the lua stack. + +The ``interpreter()`` function returns the Lua state where this object is stored. If you want to manipulate the object with Lua functions directly you can push -it onto the Lua stack by calling ``pushvalue()``. And set the object's value by -calling ``set()``, which will pop the top value from the Lua stack and assign -it to the object. +it onto the Lua stack by calling ``push()``. The operator== will call lua_equal() on the operands and return its result. -The ``type()`` member function will return the Lua type of the object. It will -return the same values as lua_type(). - The ``is_valid()`` function tells you whether the object has been initialized or not. When created with its default constructor, objects are invalid. To make an object valid, you can assign it a value. If you want to invalidate an object @@ -1024,9 +1140,9 @@ Here's an example of how a function can use a table:: - void my_function(const object& table) + void my_function(object const& table) { - if (table.type() == LUA_TTABLE) + if (type(table) == LUA_TTABLE) { table["time"] = std::clock(); table["name"] = std::rand() < 500 ? "unusual" : "usual"; @@ -1043,165 +1159,121 @@ Iterators --------- -The iterators, that are returned by ``begin()`` and ``end()`` (and their -variants) are (almost) models of the ForwardIterator concept. The exception -is that post increment doesn't exist on them. +There are two kinds of iterators. The normal iterator that will use the metamethod +of the object (if there is any) when the value is retrieved. This iterator is simply +called ``luabind::iterator``. The other iterator is called ``luabind::raw_iterator`` +and will bypass the metamethod and give the true contents of the table. They have +identical interfaces, which implements the ForwardIterator_ concept. Apart from +the members of standard iterators, they have the following members and constructors: -They look like this +.. _ForwardIterator: http://www.sgi.com/tech/stl/ForwardIterator.html .. parsed-literal:: - class object::iterator + class iterator { iterator(); - iterator(const iterator&); - - iterator& operator++(); - bool operator!=(const iterator&) const; - iterator& operator=(const iterator&); + iterator(object const&); object key() const; - *implementation-defined* operator*(); + *standard iterator members* }; -The implementation defined return value from the dereference operator is a -proxy object that can be used as if it was an object, it can also be used to -assign the specific table entry with a new value. If you want to assign a value -to an entry pointed to by an iterator, just use the assignment operator on the -dereferenced iterator:: +The constructor that takes a ``luabind::object`` is actually a template that can be +used with object. Passing an object as the parameter to the iterator will +construct the iterator to refer to the first element in the object. - *iter = 5; +The default constructor will initialize the iterator to the one-past-end +iterator. This is used to test for the end of the sequence. +The value type of the iterator is an implementation defined proxy type which +supports the same operations as ``luabind::object``. Which means that in most +cases you can just treat it as an ordinary object. The difference is that any +assignments to this proxy will result in the value being inserted at the +iterators position, in the table. + The ``key()`` member returns the key used by the iterator when indexing the associated Lua table. +An example using iterators:: -Related functions ------------------ - -There are a couple of functions related to objects and tables. :: - - T object_cast<T>(object const&); - T object_cast<T>(object const&, Policies); - - boost::optional<T> object_cast_nothrow<T>(object const&); - boost::optional<T> object_cast_nothrow<T>(object const&, Policies); - - -Functor -------- - -The ``functor`` class is similar to object, with the exception that it can only -be used to store functions. If you take it as a parameter, it will only match -functions. - -To use it you need to include its header:: - - #include <luabind/functor.hpp> - -It takes one template parameter, the return value of the Lua function it -represents. Currently the functor can have at most one return value (unlike Lua -functions). - -.. topic:: Synopsis - - .. parsed-literal:: - - template<class Ret> - class functor - { - public: - - functor(lua_State\*, char const* name); - functor(functor const&); - ~functor(); + for (iterator i(globals(L)["a"]), end; i != end; ++i) + { + *i = 1; + } - bool is_valid() const; - operator safe_bool_type() const; - void reset(); +The iterator named ``end`` will be constructed using the default constructor +and hence refer to the end of the sequence. This example will simply iterate +over the entries in the global table ``a`` and set all its values to 1. - lua_State\* lua_state() const; - void pushvalue() const; - - bool operator==(functor<Ret> const&); - bool operator!=(functor<Ret> const&); - - *implementation-defined* operator()() const; - - template<class A0> - *implementation-defined* operator()(A0 const&) const; +Related functions +----------------- - template<class A0, class A1> - *implementation-defined* operator()(A0 const&, A1 const&) const; +There are a couple of functions related to objects and tables. - /\* ... \*/ - }; +:: -The application operator takes any parameters. The parameters are converted -into Lua and the function is called. The return value will act as if it was the -type Ret, with the exception that you can use the return value to give policies -to the call. You do this the same way as you do with objects, using the -operator[], and giving the policies inside the brackets. + int type(object const&); -The ``is_valid()`` function works just like the one on object, it tells you if -the functor has been assigned with a valid Lua function. The ``operator -safe_bool_type()`` is an alias for this member function and also works just as -the one found in object. +This function will return the lua type index of the given object. +i.e. ``LUA_TNIL``, ``LUA_TNUMBER`` etc. -For example, if you have the following Lua function:: +:: - function f(a, b) - return a + b - end + template<class T, class K> + void settable(object const& o, K const& key, T const& value); + template<class K> + object gettable(object const& o, K const& key); + template<class T, class K> + void rawset(object const& o, K const& key, T const& value); + template<class K> + object rawget(object const& o, K const& key); -You can expose it to C++ like this:: +These functions are used for indexing into tables. ``settable`` and ``gettable`` +translates into calls to ``lua_settable`` and ``lua_gettable`` respectively. Which +means that you could just as well use the index operator of the object. - functor<int> f(L, "f"); +``rawset`` and ``rawget`` will translate into calls to ``lua_rawset`` and +``lua_rawget`` respectively. So they will bypass any metamethod and give you the +true value of the table entry. - std::cout << f(3, 5) << "\n"; +:: -This will print out the sum of 3 and 5. Note that you can pass any parameters -to the application operator of ``luabind::functor``, this is because lua -doesn't have signatures for its functions. All Lua functions take any number of -parameters of any type. + template<class T> + T object_cast<T>(object const&); + template<class T, class Policies> + T object_cast<T>(object const&, Policies); -If we have a C++ function that takes a ``luabind::functor`` and registers it, -it will accept Lua functions passed to it. This enables us to expose APIs that -requires you to register callbacks. For example, if your C++ API looks like -this:: + template<class T> + boost::optional<T> object_cast_nothrow<T>(object const&); + template<class T, class Policies> + boost::optional<T> object_cast_nothrow<T>(object const&, Policies); - void set_callback(void(*)(int, int)); +The ``object_cast`` function casts the value of an object to a C++ value. +You can supply a policy to handle the conversion from lua to C++. If the cast +cannot be made a ``cast_failed`` exception will be thrown. If you have +defined LUABIND_NO_ERROR_CHECKING (see configuration) no checking will occur, +and if the cast is invalid the application may very well crash. The nothrow +versions will return an uninitialized ``boost::optional<T>`` object, to +indicate that the cast could not be performed. -And you want to expose it to Lua, you have to wrap the call to the Lua -function inside a real C++ function, like this:: +The function signatures of all of the above functions are really templates +for the object parameter, but the intention is that you should only pass +objects in there, that's why it's left out of the documentation. - functor<void> lua_callback; +:: - void callback_wrapper(int a, int b) - { - lua_callback(a, b); - } + object globals(lua_State*); + object registry(lua_State*); - void set_callback_wrapper(const functor<void>& f) - { - lua_callback = f; - set_callback(&callback_wrapper); - } +These functions return the global environment table and the registry table respectively. -And then register ``set_callback_wrapper`` instead of registering -``set_callback``. This will have the effect that when one tries to register the -callback from Lua, your ``set_callback_wrapper`` will be called instead and -first set the Lua functor to the given function. It will then call the real -``set_callback`` with the ``callback_wrapper``. The ``callback_wrapper`` will -be called whenever the callback should be called, and it will simply call the -Lua function that we registered. +:: -You can also use ``object_cast`` to cast an object to a functor. + object newtable(lua_State*); -``reset`` on ``functor`` will invalidate the functor (and remove any references -to its Lua value). If the functor object has longer lifetime than the lua state -(e.g. if it's a global). +This function creates a new table and returns it as an object. Defining classes in Lua @@ -1584,10 +1656,10 @@ } There's another exception that luabind may throw: ``luabind::cast_failed``, -this exception is thrown from ``call_function<>``, ``call_member<>`` or when -``functor<>`` is invoked. It means that the return value from the Lua function -couldn't be converted to a C++ value. It is also thrown from ``object_cast<>`` -if the cast cannot be made. +this exception is thrown from ``call_function<>`` or ``call_member<>``. It +means that the return value from the Lua function couldn't be converted to +a C++ value. It is also thrown from ``object_cast<>`` if the cast cannot +be made. The synopsis for ``luabind::cast_failed`` is:: @@ -2047,8 +2119,8 @@ As mentioned in the `Lua documentation`_, it is possible to pass an error handler function to ``lua_pcall()``. Luabind makes use of -``lua_pcall()`` internally when calling methods and functions. It is -possible to set the error handler function that Luabind will use +``lua_pcall()`` internally when calling member functions and free functions. +It is possible to set the error handler function that Luabind will use globally:: typedef void(*pcall_callback_fun)(lua_State*); @@ -2099,7 +2171,7 @@ was called. Functions will still be able to throw exceptions when error checking is disabled. - If a functions throws an exception it will be caught by luabind and + If a function throws an exception it will be caught by luabind and propagated with ``lua_error()``. LUABIND_NO_EXCEPTIONS @@ -2123,7 +2195,8 @@ LUABIND_EXPORT, LUABIND_IMPORT If you want to link against luabind as a dll (in devstudio), you can define ``LUABIND_EXPORT`` to ``__declspec(dllexport)`` and - ``LUABIND_IMPORT`` to ``__declspec(dllimport)``. + ``LUABIND_IMPORT`` to ``__declspec(dllimport)`` or + ``__attribute__ ((visibility("default")))`` on GCC 4. Note that you have to link against Lua as a dll aswell, to make it work. LUABIND_NO_RTTI @@ -2216,8 +2289,8 @@ the attribute '*class-name.attribute-name*' is read only There is no data member named *attribute-name* in the class *class-name*, - or there's no setter-method registered on that property name. See the - properties section. + or there's no setter-function registered on that property name. See the + Properties_ section. - .. parsed-literal:: @@ -2282,7 +2355,8 @@ Internal structure overflow in VC If you, in visual studio, get fatal error C1204: compiler limit : internal structure overflow. You should try to split that compilation - unit up in smaller ones. + unit up in smaller ones. See `Splitting up the registration`_ and + `Splitting class registrations`_. .. the three entries above were removed, why? @@ -2340,7 +2414,7 @@ you want to be sure that the correct destructor is called (this apply to C++ in general). -.. And again, the above is irrelevant to docs. This isn't a general C++ FAQ. +.. And again, the above is irrelevant to docs. This isn't a general C++ FAQ. But it saves us support questions. Fatal Error C1063 compiler limit \: compiler stack overflow in VC VC6.5 chokes on warnings, if you are getting alot of warnings from your @@ -2353,7 +2427,7 @@ I cannot register a function with a non-const parameter This is because there is no way to get a reference to a Lua value. Have - a look at out_value and pure_out_value policies. + a look at out_value_ and pure_out_value_ policies. Known issues --- NEW FILE: changes.txt --- LUABIND BETA 7 changes ====================== We have introduced a change that may break current code, nothing will break silently however. The change is that the previous way of writing virtual class wrappers was to have it contain an object that refered to the actual lua object. This would cause a dependency cycle and result in the object never being garbage collected until the whole lua state was closed. The new way is to use a newly introduced type called weak_ref, instead of the object. See docs for more info. Changes from beta6 ------------------ * renamed get_globals() and get_registry() to globals() and registry() * rewrote object and made a few changes: * moved iterators out of the class and removed begin/end/raw_begin/raw_end/array_begin/array_end. See updated docs for how to use the iterators. * removed array_iterator alltogether * renamed pushvalue() to push() * removed set() * replaced the constructor that creates an object from a stack value (with better syntax) * moved out the member functions type(), at() and raw_at() and made them free functions. (type(), gettable(), settable(), rawget() and rawset()) * renamed lua_state() to interpreter() * object now supports nested indexing (with []-operator) as well as function calls directly on indexed values (i.e. globals(L)["my_fun"](10)). The indexing has also been made more efficient through the use of expression templates. * removed functor (use object with call_function() instead) * using boost-build, and has better support for building as a dll. The makefiles still works. * removed the option LUABIND_DONT_COPY_STRING, this means that luabind will not provide storage for name strings. i.e. the strings sent to module, namespace_ and class_ are expected to have global storage (it's no problem as long as you use string constants) wrappers ........ Wrapper classes now have to derive from wrap_base and they don't have to contain any references to the lua-part (this is done by the base class now). The overload of call_member() that previuosly took a weak_ref as first parameter is now a member function of the wrap_base class and no longer takes the self reference argument. Example: struct A { virtual ~A() {} virtual std::string f() { return "A:f()"; } }; struct A_wrap : A, wrap_base { virtual std::string f() { return call_member<std::string>("f"); } static std::string default_f(A* p) { return p->A::f(); } }; The changes when registering the virtual functions is that you now have to register both the virtual function _and_ the default implementation of the function (for static dispatch). Like this: module(L) [ class_<A, A_wrap>("A") .def(constructor<>()) .def("f", &A::f, &A_wrap::default_f) ] If you update your luabind version without changing the way you register virtual functions, it will still compile, but may give you runtime errors. With these changes adopt will work as expected on wrapped types (the weak reference will be transformed into a strong reference internally). These changes will also make dynamic function dispatch work from within lua (and not just from c++ into lua). policy placeholders ................... luabind now handles member functions in a more general way. The self reference that is passed as first parameter to member functions is now refered to using the _1 placeholder (instead of self). This means that the first argument to a member function is refered to with _2. additions ......... * added __newindex metatable entry on c++ classes * moved more code into cpp-files (hopefully reduces user compile time slightly) * the iterators are now true models of ForwardIterator * error messages when writing non-matching type to a property or attribute. * support for inner scopes * support for nil to holder_type conversion * wrappers for lua_resume() with the same syntax as call_function() (resume_function() and resume()) bugfixes ........ * bugs in the overload resolution could give internal errors in some cases. * def_readonly and def_readwrite will now return references if the type is not a primitive type. This will allow chained . operators. * object_cast() of uninitialized objects works * supports strings with extra nulls in them (not for member names though) * fixed reference leakage by reducing the amount of explicit resource management. * fixed bug where matchers for getters and setters did not propagate to derived classes. * fixed leak when using class wrappers. They had a reference cycle that wouldn't get collected (until the lua_State was closed). * lots of other fixes we can't remember |
Update of /cvsroot/luabind/luabind/luabind/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15879/luabind/test Modified Files: Jamfile makefile test.hpp test_attributes.cpp test_free_functions.cpp test_held_type.cpp test_lua_classes.cpp test_object.cpp test_operators.cpp test_policies.cpp test_typetraits.cpp test_yield.cpp Added Files: test_back_reference.cpp test_def_from_base.cpp test_has_get_pointer.cpp test_value_wrapper.cpp Log Message: merged in changes from beta7-devel2 (tag: beta7-devel2-merge) --- NEW FILE: test_def_from_base.cpp --- // Copyright (c) 2005 Daniel Wallin, Arvid Norberg // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the "Software"), // to deal in the Software without restriction, including without limitation // the rights to use, copy, modify, merge, publish, distribute, sublicense, // and/or sell copies of the Software, and to permit persons to whom the // Software is furnished to do so, subject to the following conditions: // The above copyright notice and this permission notice shall be included // in all copies or substantial portions of the Software. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF // ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A // PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT // SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR // ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE // OR OTHER DEALINGS IN THE SOFTWARE. #include "test.hpp" #include <luabind/luabind.hpp> struct V { int f(int,int) { return 2; } }; struct W : V {}; void test_main(lua_State* L) { using namespace luabind; module(L) [ class_<W>("W") .def(constructor<>()) .def("f", &V::f) ]; DOSTRING(L, "x = W()\n" "assert(x:f(1,2) == 2)\n" ); } Index: test_held_type.cpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/test/test_held_type.cpp,v retrieving revision 1.29 retrieving revision 1.30 diff -u -d -r1.29 -r1.30 --- test_held_type.cpp 15 Apr 2005 13:46:17 -0000 1.29 +++ test_held_type.cpp 28 Nov 2005 20:55:34 -0000 1.30 @@ -160,7 +160,7 @@ .def("f", &derived::f) ]; - object g = get_globals(L); + object g = globals(L); g["ptr"] = base_ptr; DOSTRING(L, "tester(ptr)"); @@ -203,7 +203,7 @@ "candidates are:\n" "tester12(const custom&)\n"); */ - object nil = get_globals(L)["non_existing_variable_is_nil"]; + object nil = globals(L)["non_existing_variable_is_nil"]; TEST_CHECK(object_cast<boost::shared_ptr<base> >(nil).get() == 0); TEST_CHECK(object_cast<boost::shared_ptr<const base> >(nil).get() == 0); --- NEW FILE: test_has_get_pointer.cpp --- // Copyright (c) 2005 Daniel Wallin // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the "Software"), // to deal in the Software without restriction, including without limitation // the rights to use, copy, modify, merge, publish, distribute, sublicense, // and/or sell copies of the Software, and to permit persons to whom the // Software is furnished to do so, subject to the following conditions: // The above copyright notice and this permission notice shall be included // in all copies or substantial portions of the Software. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF // ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A // PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT // SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR // ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE // OR OTHER DEALINGS IN THE SOFTWARE. #include <luabind/detail/has_get_pointer.hpp> #include <boost/mpl/assert.hpp> #include <boost/shared_ptr.hpp> #include <boost/get_pointer.hpp> namespace lb = luabind::detail; namespace test { struct X { }; struct Y { }; Y* get_pointer(Y const&); } // namespace test #ifdef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP namespace luabind { using test::get_pointer; using boost::get_pointer; } // namespace luabind #endif BOOST_MPL_ASSERT(( lb::has_get_pointer<boost::shared_ptr<int> > )); BOOST_MPL_ASSERT(( lb::has_get_pointer<test::Y> )); BOOST_MPL_ASSERT(( lb::has_get_pointer<char*> )); BOOST_MPL_ASSERT_NOT(( lb::has_get_pointer<int> )); BOOST_MPL_ASSERT_NOT(( lb::has_get_pointer<test::X> )); Index: test.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/test/test.hpp,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- test.hpp 15 Apr 2005 13:46:17 -0000 1.8 +++ test.hpp 28 Nov 2005 20:55:34 -0000 1.9 @@ -103,9 +103,9 @@ catch (luabind::error const& e) \ { \ using namespace std; \ - if (strcmp( \ + if (std::strcmp( \ lua_tostring(e.state(), -1) \ - , expected)) \ + , (char const*)expected)) \ { \ TEST_ERROR(lua_tostring(e.state(), -1)); \ } \ Index: test_lua_classes.cpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/test/test_lua_classes.cpp,v retrieving revision 1.26 retrieving revision 1.27 diff -u -d -r1.26 -r1.27 --- test_lua_classes.cpp 15 Apr 2005 13:46:17 -0000 1.26 +++ test_lua_classes.cpp 28 Nov 2005 20:55:34 -0000 1.27 @@ -138,50 +138,40 @@ void test_main(lua_State* L) { - module(L) - [ + module(L) + [ class_<A, A_wrap, boost::shared_ptr<A> >("A") - .def(constructor<>()) - .def("f", &A::f, &A_wrap::default_f) + .def(constructor<>()) + .def("f", &A::f, &A_wrap::default_f) .def("g", &A::g, &A_wrap::default_g), class_<B, A, B_wrap, boost::shared_ptr<A> >("B") - .def(constructor<>()) - .def("f", &B::f, &B_wrap::default_f) + .def(constructor<>()) + .def("f", &B::f, &B_wrap::default_f) .def("g", &B::g, &B_wrap::default_g), def("filter", &filter), class_<base, base_wrap>("base") - .def(constructor<>()) - .def("f", &base::f, &base_wrap::default_f) + .def(constructor<>()) + .def("f", &base::f, &base_wrap::default_f) .def("g", &base::g), class_<T_>("T") .def("f", &T_::f), class_<U, T_>("U") - .def(constructor<>()) + .def(constructor<>()) .def("f", &U::f) .def("g", &U::g) ]; - - try - { - dostring(L, "u = U()\n" + + DOSTRING(L, + "u = U()\n" "assert(u:f(0) == 1)\n" "assert(u:f(0,0) == 2)\n" "assert(u:g() == 3)\n"); - } - catch (luabind::error const& e) - { - TEST_ERROR(lua_tostring(e.state(), -1)); - } - catch (std::string const& s) - { - TEST_ERROR(s.c_str()); - } - + DOSTRING(L, "u = U()\n" "assert(u:f(0) == 1)\n" @@ -299,7 +289,7 @@ LUABIND_CHECK_STACK(L); TEST_NOTHROW( - object a = get_globals(L)["ba"]; + object a = globals(L)["ba"]; TEST_CHECK(call_member<int>(a, "fun") == 4); ); } @@ -307,7 +297,7 @@ { LUABIND_CHECK_STACK(L); - object make_derived = get_globals(L)["make_derived"]; + object make_derived = globals(L)["make_derived"]; TEST_NOTHROW( call_function<void>(make_derived) ); Index: test_operators.cpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/test/test_operators.cpp,v retrieving revision 1.15 retrieving revision 1.16 diff -u -d -r1.15 -r1.16 --- test_operators.cpp 15 Apr 2005 13:46:17 -0000 1.15 +++ test_operators.cpp 28 Nov 2005 20:55:34 -0000 1.16 @@ -51,9 +51,18 @@ { return 2.5f + a; } - }; +float operator*(operator_tester const& lhs, operator_tester const& rhs) +{ + return 35.f; +} + +std::string operator*(operator_tester const&, int v) +{ + return "(operator_tester, int) overload"; +} + int operator+(int a, const operator_tester&) { return 2 + a; @@ -101,11 +110,14 @@ .def(self + int()) .def(other<int>() + self) .def(-self) - .def(self + other<operator_tester2&>()) + .def(self + other<operator_tester2&>()) .def(self()) .def(const_self(int())) .def(self(int())) - .def(tostring(const_self)), + .def(tostring(const_self)) +// .def(const_self * other<operator_tester const&>()) + .def(const_self * const_self) + .def(const_self * other<int>()), // .def("clone", &clone, adopt(return_value)), class_<operator_tester2>("operator_tester2") @@ -134,6 +146,8 @@ DOSTRING(L, "assert(test(5) == 2.5 + 5)"); DOSTRING(L, "assert(-test == 46)"); + DOSTRING(L, "assert(test * test == 35)"); + DOSTRING(L, "assert(test * 3 == '(operator_tester, int) overload')") DOSTRING(L, "assert(test + test2 == 73)"); DOSTRING(L, "assert(2 + test == 2 + 2)"); DOSTRING(L, "assert(test + 2 == 1 + 2)"); Index: test_attributes.cpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/test/test_attributes.cpp,v retrieving revision 1.31 retrieving revision 1.32 diff -u -d -r1.31 -r1.32 --- test_attributes.cpp 15 Apr 2005 13:46:17 -0000 1.31 +++ test_attributes.cpp 28 Nov 2005 20:55:34 -0000 1.32 @@ -23,18 +23,41 @@ #include "test.hpp" #include <luabind/luabind.hpp> +struct A +{ + int get() const + { + return 5; + } +}; + +struct B : A +{ +}; + +struct C +{ + int a; +}; + struct property_test : counted_type<property_test> { - property_test(): o(6) {} + property_test(): o(6), c_ref(&c) {} + ~property_test() { c.a = 0; } - std::string str_; + std::string str_; int a_; float o; - signed char b; + signed char b; + C c; + C* c_ref; void set(int a) { a_ = a; } int get() const { return a_; } + void setA(A* a) {} + A* getA() const { return 0; } + void set_str(const char* str) { str_ = str; } @@ -50,18 +73,6 @@ int free_getter(const property_test& p) { return p.get(); } -struct A -{ - int get() const - { - return 5; - } -}; - -struct B : A -{ -}; - void test_main(lua_State* L) { using namespace luabind; @@ -72,11 +83,13 @@ .def(luabind::constructor<>()) .def("get", &property_test::get) .property("a", &property_test::get, &property_test::set) - .property( - "str", &property_test::get_str, &property_test::set_str) + .property("str", &property_test::get_str, &property_test::set_str) + .property("A", &property_test::getA, &property_test::setA) .def_readonly("o", &property_test::o) - .property("free", &free_getter, &free_setter) - .def_readwrite("b", &property_test::b), + .property("free", &free_getter, &free_setter) + .def_readwrite("b", &property_test::b) + .def_readwrite("c", &property_test::c) + .def_readwrite("c_ref", &property_test::c_ref), class_<A>("A") .def(constructor<>()) @@ -84,18 +97,34 @@ class_<B, A>("B") .def(constructor<>()) - .property("x", &A::get) + .property("x", &A::get), + + class_<C>("C") + .def(constructor<>()) + .def_readwrite("a", &C::a) ]; DOSTRING(L, "test = property()\n"); - DOSTRING(L, - "test.a = 5\n" - "assert(test.a == 5)"); + DOSTRING(L, + "test.a = 5\n" + "assert(test.a == 5)"); DOSTRING(L, "assert(test.o == 6)"); - DOSTRING(L, + DOSTRING(L, + "test.new_member = 'foo'\n" + "assert(test.new_member == 'foo')"); + + DOSTRING(L, + "property.new_member2 = 'bar'\n" + "assert(property.new_member2 == 'bar')"); + + DOSTRING(L, + "b = property()\n" + "assert(b.new_member2 == 'bar')"); + + DOSTRING(L, "test.str = 'foobar'\n" "assert(test.str == 'foobar')\n"); @@ -107,6 +136,20 @@ "test.b = 3\n" "assert(test.b == 3)\n"); + DOSTRING(L, "test.c.a = 1\n" + "assert(test.c.a == 1)\n" + "assert(test.c_ref.a == 1)"); + + DOSTRING(L, "t1 = property()\n" + "c = t1.c\n" + "c2 = t1.c_ref\n" + "c.a = 1\n" + "t1 = nil\n" + "collectgarbage()\n" + "collectgarbage()\n" + "assert(c.a == 1)\n" + "assert(c2.a == 1)"); + DOSTRING(L, "a = B()\n"); Index: makefile =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/test/makefile,v retrieving revision 1.20 retrieving revision 1.21 diff -u -d -r1.20 -r1.21 --- makefile 12 Aug 2004 06:31:51 -0000 1.20 +++ makefile 28 Nov 2005 20:55:34 -0000 1.21 @@ -1,7 +1,6 @@ include ../config SOURCES = \ - main.cpp \ test_abstract_base.cpp \ test_attributes.cpp \ test_const.cpp \ @@ -17,39 +16,32 @@ test_operators.cpp \ test_policies.cpp \ test_scope.cpp \ - test_separate_registration.cpp \ test_separation.cpp \ test_simple_class.cpp \ test_typetraits.cpp \ - test_yield.cpp - -# not converted yet - -# test_null_pointer.cpp \ + test_yield.cpp \ + test_null_pointer.cpp \ test_policies.cpp \ test_free_functions.cpp \ test_iterator.cpp \ -TARGET = test_luabind - - - - -OBJECTS = $(SOURCES:.cpp=.o) +CPPFLAGS = -Wno-long-double -all: $(TARGET) +all: $(SOURCES:.cpp=.exe) -$(TARGET): $(OBJECTS) - $(CXX) -g $(OBJECTS) -L$(LUA_PATH)/lib -L../lib -lluabind -llua -llualib -o $@ +%.exe:%.o main.o + $(CXX) $? -o $@ -g -L$(LUA_PATH)/lib -L../lib -lluabind -llualib -llua %.o:%.cpp - $(CXX) -Wall -ftemplate-depth-100 -g $(CONFIG) -I$(LUA_PATH)/include -I. -I- -I../ -I$(BOOST_ROOT) -c $? -o $@ + $(CXX) -Wall -ftemplate-depth-100 -g $(CPPFLAGS) $(CONFIG) -I$(LUA_PATH)/include -I. -I- -I../ -I$(BOOST_ROOT) -c $? -o $@ -relink: - rm -f $(TARGET) - make +#just to force the tests to be run +test: $(SOURCES:.cpp=.dummy) + +%.dummy:%.exe + ./$? clean: - rm -f $(OBJECTS) $(TARGET) core + rm -f $(SOURCES:.cpp=.o) $(SOURCES:.cpp=.exe) main.o core Index: test_policies.cpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/test/test_policies.cpp,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- test_policies.cpp 15 Apr 2005 13:46:17 -0000 1.10 +++ test_policies.cpp 28 Nov 2005 20:55:34 -0000 1.11 @@ -30,6 +30,14 @@ #include <luabind/dependency_policy.hpp> #include <luabind/luabind.hpp> +struct test_copy {}; + + +struct secret_type {}; + +secret_type sec_; + + struct policies_test_class { policies_test_class(const char* name): name_(name) @@ -58,6 +66,9 @@ // private: policies_test_class(policies_test_class const& c): name_(c.name_) { ++count; } + + void member_out_val(int* v) { *v = 5; } + secret_type* member_secret() { return &sec_; } }; int policies_test_class::count = 0; @@ -67,10 +78,6 @@ void out_val(float* f) { *f = 3.f; } policies_test_class* copy_val() { return &global; } -struct secret_type {}; - -secret_type sec_; - secret_type* secret() { return &sec_; } void aux_test(); @@ -96,15 +103,17 @@ module(L) [ - class_<test_t>("test_t") - .def("make", &test_t::make, adopt(return_value)) - .def("take", &test_t::take, adopt(_2)) + class_<test_t>("test_t") + .def("make", &test_t::make, adopt(return_value)) + .def("take", &test_t::take, adopt(_2)) ]; module(L) [ class_<policies_test_class>("test") .def(constructor<>()) + .def("member_out_val", &policies_test_class::member_out_val, pure_out_value(_2)) + .def("member_secret", &policies_test_class::member_secret, discard_result) .def("f", &policies_test_class::f, adopt(_2)) .def("make", &policies_test_class::make, adopt(return_value)) .def("internal_ref", &policies_test_class::internal_ref, dependency(result, _1)) @@ -186,6 +195,8 @@ TEST_CHECK(policies_test_class::count == 2); DOSTRING(L, "b = a:make('tjosan')"); + DOSTRING(L, "assert(a:member_out_val() == 5)"); + DOSTRING(L, "a:member_secret()"); // make instantiated a new policies_test_class TEST_CHECK(policies_test_class::count == 3); Index: test_object.cpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/test/test_object.cpp,v retrieving revision 1.27 retrieving revision 1.28 diff -u -d -r1.27 -r1.28 --- test_object.cpp 15 Apr 2005 13:46:17 -0000 1.27 +++ test_object.cpp 28 Nov 2005 20:55:34 -0000 1.28 @@ -20,6 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE // OR OTHER DEALINGS IN THE SOFTWARE. + #include "test.hpp" #include <luabind/luabind.hpp> #include <luabind/adopt_policy.hpp> @@ -32,44 +33,41 @@ int test_object_param(const object& table) { - LUABIND_CHECK_STACK(table.lua_state()); + LUABIND_CHECK_STACK(table.interpreter()); object current_object; current_object = table; + lua_State* L = table.interpreter(); - if (table.type() == LUA_TTABLE) + if (type(table) == LUA_TTABLE) { - - int sum = object_cast<int>(table["oh"]); - for (object::array_iterator i = table.abegin(); i != table.aend(); ++i) + int sum1 = 0; + for (iterator i(table), e; i != e; ++i) { - assert(i->type() == LUA_TNUMBER); - sum += object_cast<int>(*i); + assert(type(*i) == LUA_TNUMBER); + sum1 += object_cast<int>(*i); } int sum2 = 0; - for (object::iterator i = table.begin(); i != table.end(); ++i) + for (raw_iterator i(table), e; i != e; ++i) { - assert(i->type() == LUA_TNUMBER); + assert(type(*i) == LUA_TNUMBER); sum2 += object_cast<int>(*i); } - int sum3 = 0; - for (object::raw_iterator i = table.raw_begin(); i != table.raw_end(); ++i) - { - assert(i->type() == LUA_TNUMBER); - sum3 += object_cast<int>(*i); - } - - table["sum"] = sum; + // test iteration of empty table + object empty_table = newtable(L); + for (iterator i(empty_table), e; i != e; ++i) + {} + + table["sum1"] = sum1; table["sum2"] = sum2; - table["sum3"] = sum3; table["blurp"] = 5; return 0; } else { - if (table.type() != LUA_TNIL) + if (type(table) != LUA_TNIL) { return 1; } @@ -131,6 +129,10 @@ .def_readonly("obj2", &test_param::obj2) ]; + object uninitialized; + TEST_CHECK(!uninitialized); + TEST_CHECK(!uninitialized.is_valid()); + DOSTRING(L, "t = 2\n" "assert(test_object_param(t) == 1)"); @@ -138,19 +140,17 @@ DOSTRING(L, "assert(test_object_param(nil) == 2)"); DOSTRING(L, "t = { ['oh'] = 4, 3, 5, 7, 13 }"); DOSTRING(L, "assert(test_object_param(t) == 0)"); - DOSTRING(L, "assert(t.sum == 4 + 3 + 5 + 7 + 13)"); + DOSTRING(L, "assert(t.sum1 == 4 + 3 + 5 + 7 + 13)"); DOSTRING(L, "assert(t.sum2 == 4 + 3 + 5 + 7 + 13)"); - DOSTRING(L, "assert(t.sum3 == 4 + 3 + 5 + 7 + 13)"); DOSTRING(L, "assert(t.blurp == 5)"); - object g = get_globals(L); - object fun = g["test_fun"]; - object ret = fun(); + object g = globals(L); + object ret = g["test_fun"](); TEST_CHECK(object_cast<int>(ret) == 42); DOSTRING(L, "function test_param_policies(x, y) end"); object test_param_policies = g["test_param_policies"]; - int a = test_param_policies.type(); + int a = type(test_param_policies); TEST_CHECK(a == LUA_TFUNCTION); // call the function and tell lua to adopt the pointer passed as first argument @@ -172,13 +172,20 @@ object test_object_policies = g["test_object_policies"]; object ret_val = test_object_policies("teststring")[detail::null_type()]; TEST_CHECK(object_cast<int>(ret_val) == 6); + TEST_CHECK(ret_val == 6); + TEST_CHECK(6 == ret_val); + g["temp_val"] = 6; + TEST_CHECK(ret_val == g["temp_val"]); + object temp_val = g["temp_val"]; + TEST_CHECK(ret_val == temp_val); + TEST_CHECK(object_cast<std::string>(g["glob"]) == "teststring"); - TEST_CHECK(object_cast<std::string>(g.at("glob")) == "teststring"); - TEST_CHECK(object_cast<std::string>(g.raw_at("glob")) == "teststring"); + TEST_CHECK(object_cast<std::string>(gettable(g, "glob")) == "teststring"); + TEST_CHECK(object_cast<std::string>(rawget(g, "glob")) == "teststring"); object t = newtable(L); - TEST_CHECK(t.begin() == t.end()); - TEST_CHECK(t.raw_begin() == t.raw_end()); + TEST_CHECK(iterator(t) == iterator()); + TEST_CHECK(raw_iterator(t) == raw_iterator()); DOSTRING(L, "p1 = {}\n" @@ -189,6 +196,7 @@ "assert(p2.ret == 2)\n" "assert(p3.ret == 3)\n"); + #ifndef LUABIND_NO_EXCEPTIONS try @@ -202,6 +210,34 @@ #endif - object not_initialized; - TEST_CHECK(!object_cast_nothrow<int>(not_initialized)); + object not_initialized; + TEST_CHECK(!object_cast_nothrow<int>(not_initialized)); + TEST_CHECK(!not_initialized.is_valid()); + TEST_CHECK(!not_initialized); + + DOSTRING(L, "t = { {1}, {2}, {3}, {4} }"); + + int inner_sum = 0; + + for (iterator i(globals(L)["t"]), e; i != e; ++i) + { + inner_sum += object_cast<int>((*i)[1]); + } + + TEST_CHECK(inner_sum == 1 + 2 + 3 + 4); + + DOSTRING(L, "t = { {1, 2}, {3, 4}, {5, 6}, {7, 8} }"); + + inner_sum = 0; + + for (iterator i(globals(L)["t"]), e; i != e; ++i) + { + for (iterator j(*i), e; j != e; ++j) + { + inner_sum += object_cast<int>(*j); + } + } + + TEST_CHECK(inner_sum == 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8); + TEST_CHECK(object_cast<int>(globals(L)["t"][2][2]) == 4); } --- NEW FILE: test_back_reference.cpp --- // Copyright (c) 2005 Daniel Wallin // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the "Software"), // to deal in the Software without restriction, including without limitation // the rights to use, copy, modify, merge, publish, distribute, sublicense, // and/or sell copies of the Software, and to permit persons to whom the // Software is furnished to do so, subject to the following conditions: // The above copyright notice and this permission notice shall be included // in all copies or substantial portions of the Software. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF // ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A // PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT // SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR // ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE // OR OTHER DEALINGS IN THE SOFTWARE. #include "test.hpp" #include <luabind/luabind.hpp> #include <boost/shared_ptr.hpp> using namespace luabind; #ifdef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP namespace luabind { using boost::get_pointer; } #endif namespace luabind { template<class T> boost::shared_ptr<T const>* get_const_holder(boost::shared_ptr<T>*) { return 0; } } struct base0 { virtual ~base0() {} }; struct base_wrap0 : base0, wrap_base {}; struct base1 { virtual ~base1() {} }; struct base_wrap1 : base1, wrap_base {}; base0* filter0(base0* p) { return p; } boost::shared_ptr<base1> filter1(boost::shared_ptr<base1> const& p) { return p; } void test_main(lua_State* L) { module(L) [ class_<base0, base_wrap0>("base0") .def(constructor<>()), def("filter0", &filter0), class_<base1, base_wrap1, boost::shared_ptr<base1> >("base1") .def(constructor<>()), def("filter1", &filter1) ]; DOSTRING(L, "class 'derived0' (base0)\n" " function derived0:__init()\n" " super()\n" " end\n" "class 'derived1' (base1)\n" " function derived1:__init()\n" " super()\n" " end\n" ); DOSTRING(L, "x = derived0()\n" "y = filter0(x)\n" "assert(x == y)\n" ); DOSTRING(L, "x = derived1()\n" "y = filter1(x)\n" "assert(x == y)\n" ); } --- NEW FILE: test_value_wrapper.cpp --- // Copyright (c) 2005 Daniel Wallin and Arvid Norberg // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the "Software"), // to deal in the Software without restriction, including without limitation // the rights to use, copy, modify, merge, publish, distribute, sublicense, // and/or sell copies of the Software, and to permit persons to whom the // Software is furnished to do so, subject to the following conditions: // The above copyright notice and this permission notice shall be included // in all copies or substantial portions of the Software. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF // ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A // PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT // SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR // ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE // OR OTHER DEALINGS IN THE SOFTWARE. #include <luabind/value_wrapper.hpp> #include <luabind/object.hpp> #include <boost/mpl/assert.hpp> struct X_tag; struct X { typedef X_tag value_wrapper_tag; }; namespace luabind { #ifdef LUABIND_USE_VALUE_WRAPPER_TAG template<> struct value_wrapper_traits<X_tag> { typedef boost::mpl::true_ is_specialized; }; #else // used on compilers supporting partial template specialization template<> struct value_wrapper_traits<X> { typedef boost::mpl::true_ is_specialized; }; #endif } // namespace luabind BOOST_MPL_ASSERT(( luabind::is_value_wrapper<X> )); BOOST_MPL_ASSERT_NOT(( luabind::is_value_wrapper<X&> )); BOOST_MPL_ASSERT_NOT(( luabind::is_value_wrapper<X const&> )); BOOST_MPL_ASSERT(( luabind::is_value_wrapper_arg<X> )); BOOST_MPL_ASSERT(( luabind::is_value_wrapper_arg<X const> )); BOOST_MPL_ASSERT(( luabind::is_value_wrapper_arg<X&> )); BOOST_MPL_ASSERT(( luabind::is_value_wrapper_arg<X const&> )); BOOST_MPL_ASSERT_NOT(( luabind::is_value_wrapper_arg<int> )); BOOST_MPL_ASSERT_NOT(( luabind::is_value_wrapper_arg<int[4]> )); BOOST_MPL_ASSERT(( luabind::is_value_wrapper_arg<X const&> )); BOOST_MPL_ASSERT(( luabind::is_value_wrapper_arg<luabind::object&> )); BOOST_MPL_ASSERT(( luabind::is_value_wrapper_arg<luabind::object const&> )); int main() { } Index: test_yield.cpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/test/test_yield.cpp,v retrieving revision 1.15 retrieving revision 1.16 diff -u -d -r1.15 -r1.16 --- test_yield.cpp 15 Apr 2005 13:46:17 -0000 1.15 +++ test_yield.cpp 28 Nov 2005 20:55:34 -0000 1.16 @@ -92,7 +92,7 @@ { lua_State* thread = lua_newthread(L); - object g = get_globals(thread)["g"]; + object g = globals(thread)["g"]; TEST_CHECK(resume_function<int>(g, "foobar") == 5); for (int i = 1; i < 10; ++i) Index: test_free_functions.cpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/test/test_free_functions.cpp,v retrieving revision 1.18 retrieving revision 1.19 diff -u -d -r1.18 -r1.19 --- test_free_functions.cpp 15 Apr 2005 13:46:17 -0000 1.18 +++ test_free_functions.cpp 28 Nov 2005 20:55:34 -0000 1.19 @@ -22,15 +22,16 @@ #include "test.hpp" #include <luabind/luabind.hpp> -#include <luabind/functor.hpp> +//#include <luabind/functor.hpp> #include <luabind/adopt_policy.hpp> - +/* luabind::functor<int> functor_test; void set_functor(luabind::functor<int> f) { functor_test = f; } +*/ struct base : counted_type<base> { @@ -125,8 +126,8 @@ def("f", (int(*)(int)) &f), def("f", (int(*)(int, int)) &f), - def("create", &create_base, adopt(return_value)), - def("set_functor", &set_functor) + def("create", &create_base, adopt(return_value)) +// def("set_functor", &set_functor) #if !(BOOST_MSVC < 1300) , @@ -144,11 +145,11 @@ DOSTRING(L, "assert(f(3, 9) == 12)"); - DOSTRING(L, "set_functor(function(x) return x * 10 end)"); +// DOSTRING(L, "set_functor(function(x) return x * 10 end)"); - TEST_CHECK(functor_test(20) == 200); +// TEST_CHECK(functor_test(20) == 200); - DOSTRING(L, "set_functor(nil)"); +// DOSTRING(L, "set_functor(nil)"); DOSTRING(L, "function lua_create() return create() end"); base* ptr = call_function<base*>(L, "lua_create") [ adopt(result) ]; @@ -165,20 +166,17 @@ "f(number)\n" "f(number, number)\n"); - DOSTRING(L, - "function functor_test(a) glob = a\n" - " return 'foobar'\n" - "end"); - functor<std::string> functor_test = object_cast<functor<std::string> >(get_globals(L)["functor_test"]); +// DOSTRING(L, +// "function functor_test(a) glob = a\n" +// " return 'foobar'\n" +// "end"); +// functor<std::string> functor_test = object_cast<functor<std::string> >(globals(L)["functor_test"]); - TEST_CHECK(functor_test(6)[detail::null_type()] == "foobar"); - TEST_CHECK(object_cast<int>(get_globals(L)["glob"]) == 6); - - functor<std::string> functor_test2 = object_cast<functor<std::string> >(get_globals(L)["functor_test"]); +// TEST_CHECK(functor_test(6)[detail::null_type()] == "foobar"); +// TEST_CHECK(object_cast<int>(globals(L)["glob"]) == 6); - TEST_CHECK(functor_test == functor_test2); +// functor<std::string> functor_test2 = object_cast<functor<std::string> >(globals(L)["functor_test"]); - // this must be reset before the lua state is destructed! - functor_test.reset(); +// TEST_CHECK(functor_test == functor_test2); } Index: test_typetraits.cpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/test/test_typetraits.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- test_typetraits.cpp 15 Apr 2005 13:46:17 -0000 1.5 +++ test_typetraits.cpp 28 Nov 2005 20:55:34 -0000 1.6 @@ -29,8 +29,9 @@ using namespace luabind::detail; struct tester {}; +struct lua_State; -int main() +int test_main(lua_State*) { BOOST_STATIC_ASSERT(is_nonconst_reference<int&>::value); BOOST_STATIC_ASSERT(!is_nonconst_reference<const int&>::value); Index: Jamfile =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/test/Jamfile,v retrieving revision 1.15 retrieving revision 1.16 diff -u -d -r1.15 -r1.16 --- Jamfile 15 Apr 2005 13:46:17 -0000 1.15 +++ Jamfile 28 Nov 2005 20:55:34 -0000 1.16 @@ -3,6 +3,9 @@ use-project /luabind : ../ ; SOURCES = + test_back_reference.cpp + test_def_from_base.cpp + test_object.cpp test_abstract_base.cpp test_attributes.cpp test_const.cpp @@ -14,7 +17,6 @@ test_iterator.cpp test_lua_classes.cpp test_null_pointer.cpp - test_object.cpp test_operators.cpp test_policies.cpp test_scope.cpp @@ -23,6 +25,8 @@ test_yield.cpp ; +project : default-build <link>static ; + lib main-lib : main.cpp /luabind//luabind/<link>static /luabind//lua /luabind//lualib : <link>static @@ -35,5 +39,9 @@ tests += [ run $(src) main-lib ] ; } -test-suite luabind-test : $(tests) [ compile test_typetraits.cpp ] ; +test-suite luabind-test : $(tests) + [ compile test_typetraits.cpp ] + [ compile test_value_wrapper.cpp ] + [ compile test_has_get_pointer.cpp ] + ; |
From: Arvid N. <ar...@us...> - 2005-11-28 20:55:45
|
Update of /cvsroot/luabind/luabind/luabind/examples/filesystem In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15879/luabind/examples/filesystem Modified Files: Jamfile filesystem.cpp Log Message: merged in changes from beta7-devel2 (tag: beta7-devel2-merge) Index: Jamfile =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/examples/filesystem/Jamfile,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- Jamfile 4 Apr 2004 16:28:26 -0000 1.1 +++ Jamfile 28 Nov 2005 20:55:34 -0000 1.2 @@ -5,8 +5,10 @@ use-project /boost : $(BOOST_ROOT) ; exe filesystem - : filesystem.cpp directory_iterator.hpp + : filesystem.cpp /boost/filesystem//boost_filesystem/<link>static /luabind//luabind ; +stage . : filesystem ; + Index: filesystem.cpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/examples/filesystem/filesystem.cpp,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- filesystem.cpp 10 Aug 2004 23:04:58 -0000 1.8 +++ filesystem.cpp 28 Nov 2005 20:55:34 -0000 1.9 @@ -7,18 +7,6 @@ #include "lualib.h" } -bool dostring(lua_State* L, const char* str) -{ - if (luaL_loadbuffer(L, str, std::strlen(str), str) || lua_pcall(L, 0, 0, 0)) - { - const char* a = lua_tostring(L, -1); - std::cout << a << "\n"; - lua_pop(L, 1); - return true; - } - return false; -} - #include <luabind/luabind.hpp> #include <luabind/operator.hpp> #include <boost/filesystem/operations.hpp> @@ -100,7 +88,9 @@ if (argc < 2) { - std::cout << "usage: filesystem filename [args]\n"; + std::cout << "This example will bind parts of the boost.Filesystem library\n" + "and then run the given lua file.\n\n" + "usage: filesystem filename [args]\n"; return 1; } @@ -118,9 +108,7 @@ } args["n"] = argc; - - object globals = get_globals(L); - globals["args"] = args; + globals(L)["args"] = args; lua_dofile(L, argv[1]); } |
From: Arvid N. <ar...@us...> - 2005-11-28 20:55:45
|
Update of /cvsroot/luabind/luabind/luabind/examples/regexp In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15879/luabind/examples/regexp Modified Files: regex_wrap.cpp Log Message: merged in changes from beta7-devel2 (tag: beta7-devel2-merge) Index: regex_wrap.cpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/examples/regexp/regex_wrap.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- regex_wrap.cpp 4 Apr 2004 16:14:09 -0000 1.3 +++ regex_wrap.cpp 28 Nov 2005 20:55:34 -0000 1.4 @@ -42,11 +42,12 @@ ]; } -void test_wrap_regex() +int main() { lua_State* L = lua_open(); lua_baselibopen(L); lua_strlibopen(L); + luabind::open(L); wrap_regex(L); |
Update of /cvsroot/luabind/luabind/luabind/luabind/detail In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15879/luabind/luabind/detail Modified Files: call.hpp call_function.hpp call_member.hpp call_operator_iterate.hpp class_rep.hpp construct_rep.hpp constructor.hpp find_best_match.hpp get_signature.hpp object_rep.hpp other.hpp overload_rep.hpp overload_rep_base.hpp policy.hpp primitives.hpp property.hpp signature_match.hpp stack_utils.hpp Added Files: has_get_pointer.hpp most_derived.hpp object_call.hpp Removed Files: overload_rep_impl.hpp Log Message: merged in changes from beta7-devel2 (tag: beta7-devel2-merge) Index: stack_utils.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/detail/stack_utils.hpp,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- stack_utils.hpp 7 Aug 2004 13:37:10 -0000 1.2 +++ stack_utils.hpp 28 Nov 2005 20:55:34 -0000 1.3 @@ -20,7 +20,6 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE // OR OTHER DEALINGS IN THE SOFTWARE. - #ifndef LUABIND_STACK_UTILS_HPP_INCLUDED #define LUABIND_STACK_UTILS_HPP_INCLUDED @@ -50,3 +49,4 @@ }} #endif // LUABIND_STACK_UTILS_HPP_INCLUDED + Index: get_signature.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/detail/get_signature.hpp,v retrieving revision 1.17 retrieving revision 1.18 diff -u -d -r1.17 -r1.18 --- get_signature.hpp 7 Aug 2004 13:37:10 -0000 1.17 +++ get_signature.hpp 28 Nov 2005 20:55:34 -0000 1.18 @@ -77,8 +77,8 @@ inline std::string name_of_type(by_value<const unsigned int>, lua_State*, int) { return "number"; } inline std::string name_of_type(by_value<const unsigned long>, lua_State*, int) { return "number"; } - template<class T> - inline std::string name_of_type(by_value<luabind::functor<T> >, lua_State* L, long) { return "function<" + name_of_type(LUABIND_DECORATE_TYPE(T), L, 0L) + ">"; } +// template<class T> +// inline std::string name_of_type(by_value<luabind::functor<T> >, lua_State* L, long) { return "function<" + name_of_type(LUABIND_DECORATE_TYPE(T), L, 0L) + ">"; } inline std::string name_of_type(by_value<std::string>, lua_State*, int) { return "string"; } inline std::string name_of_type(by_const_pointer<char>, lua_State*, int) { return "string"; } --- NEW FILE: object_call.hpp --- // Copyright (c) 2005 Daniel Wallin and Arvid Norberg // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the "Software"), // to deal in the Software without restriction, including without limitation // the rights to use, copy, modify, merge, publish, distribute, sublicense, // and/or sell copies of the Software, and to permit persons to whom the // Software is furnished to do so, subject to the following conditions: // The above copyright notice and this permission notice shall be included // in all copies or substantial portions of the Software. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF // ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A // PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT // SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR // ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE // OR OTHER DEALINGS IN THE SOFTWARE. #if !BOOST_PP_IS_ITERATING # error Do not include object_call.hpp directly! #endif #include <boost/preprocessor/repetition/enum_params.hpp> #include <boost/preprocessor/repetition/enum_binary_params.hpp> #include <boost/preprocessor/facilities/intercept.hpp> #define N BOOST_PP_ITERATION() template<BOOST_PP_ENUM_PARAMS(N, class A)> call_proxy< Derived , boost::tuples::tuple< BOOST_PP_ENUM_BINARY_PARAMS(N, A, const* BOOST_PP_INTERCEPT) > > operator()(BOOST_PP_ENUM_BINARY_PARAMS(N, A, const& a)) { typedef boost::tuples::tuple< BOOST_PP_ENUM_BINARY_PARAMS(N, A, const* BOOST_PP_INTERCEPT) > arguments; return call_proxy<Derived, arguments>( derived() , arguments(BOOST_PP_ENUM_PARAMS(N, &a)) ); } #undef N --- NEW FILE: has_get_pointer.hpp --- // Copyright (c) 2005 Daniel Wallin // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the "Software"), // to deal in the Software without restriction, including without limitation // the rights to use, copy, modify, merge, publish, distribute, sublicense, // and/or sell copies of the Software, and to permit persons to whom the // Software is furnished to do so, subject to the following conditions: // The above copyright notice and this permission notice shall be included // in all copies or substantial portions of the Software. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF // ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A // PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT // SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR // ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE // OR OTHER DEALINGS IN THE SOFTWARE. #ifndef LUABIND_HAS_GET_POINTER_051022_HPP # define LUABIND_HAS_GET_POINTER_051022_HPP # include <boost/type_traits/add_reference.hpp> # ifndef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP # include <memory> # endif namespace luabind { namespace detail { namespace has_get_pointer_ { struct any { template<class T> any(T const&); }; struct no_overload_tag {}; typedef char (&yes)[1]; typedef char (&no)[2]; no_overload_tag operator,(no_overload_tag, int); // // On compilers with ADL, we need these generic overloads in this // namespace as well as in luabind::. Otherwise get_pointer(any) // will be found before them. // # ifndef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP template<class T> T* get_pointer(T*); template<class T> T* get_pointer(std::auto_ptr<T> const&); # endif // // On compilers that doesn't support ADL, the overload below has to // live in luabind::. // # ifdef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP }} // namespace detail::has_get_pointer_ # endif detail::has_get_pointer_::no_overload_tag get_pointer(detail::has_get_pointer_::any); # ifdef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP namespace detail { namespace has_get_pointer_ { # endif template<class T> yes check(T const&); no check(no_overload_tag); template<class T> struct impl { static typename boost::add_reference<T>::type x; BOOST_STATIC_CONSTANT(bool, value = sizeof(has_get_pointer_::check( (get_pointer(x),0) )) == 1 ); typedef boost::mpl::bool_<value> type; }; } // namespace has_get_pointer_ template<class T> struct has_get_pointer : has_get_pointer_::impl<T>::type {}; }} // namespace luabind::detail #endif // LUABIND_HAS_GET_POINTER_051022_HPP Index: construct_rep.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/detail/construct_rep.hpp,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- construct_rep.hpp 7 Aug 2004 13:37:10 -0000 1.6 +++ construct_rep.hpp 28 Nov 2005 20:55:34 -0000 1.7 @@ -33,7 +33,7 @@ #include <boost/function/function1.hpp> #include <boost/function/function2.hpp> -#include <luabind/detail/signature_match.hpp> +//#include <luabind/detail/signature_match.hpp> #include <luabind/detail/overload_rep_base.hpp> #include <luabind/weak_ref.hpp> Index: signature_match.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/detail/signature_match.hpp,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- signature_match.hpp 7 Aug 2004 13:37:10 -0000 1.3 +++ signature_match.hpp 28 Nov 2005 20:55:34 -0000 1.4 @@ -44,10 +44,11 @@ #include <boost/mpl/int.hpp> #include <boost/type_traits.hpp> +#include <luabind/detail/policy.hpp> #include <luabind/detail/primitives.hpp> #include <luabind/detail/object_rep.hpp> #include <luabind/detail/class_rep.hpp> -#include <luabind/detail/policy.hpp> +#include <luabind/detail/most_derived.hpp> namespace luabind { @@ -189,7 +190,7 @@ , Policies const*) { typedef constructor< - T& + BOOST_DEDUCED_TYPENAME most_derived<T,WrappedClass>::type& BOOST_PP_ENUM_TRAILING_PARAMS(N, A) > params_t; @@ -213,7 +214,7 @@ , Policies const* policies) { typedef constructor< - T const& + BOOST_DEDUCED_TYPENAME most_derived<T,WrappedClass>::type const& BOOST_PP_ENUM_TRAILING_PARAMS(N, A) > params_t; return match_params( @@ -245,6 +246,10 @@ #if N int current_index = 0; #endif + // Removes unreferenced local variable warning on VC7. + (void)start_index; + (void)L; + BOOST_PP_REPEAT(N, LUABIND_MATCH_DECL, _) return m; } Index: class_rep.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/detail/class_rep.hpp,v retrieving revision 1.41 retrieving revision 1.42 diff -u -d -r1.41 -r1.42 --- class_rep.hpp 7 Aug 2004 13:37:10 -0000 1.41 +++ class_rep.hpp 28 Nov 2005 20:55:34 -0000 1.42 @@ -35,12 +35,21 @@ #include <luabind/detail/construct_rep.hpp> #include <luabind/detail/garbage_collector.hpp> #include <luabind/detail/operator_id.hpp> -#include <luabind/detail/signature_match.hpp> #include <luabind/detail/class_registry.hpp> #include <luabind/detail/find_best_match.hpp> #include <luabind/detail/get_overload_signature.hpp> #include <luabind/error.hpp> +#include <luabind/handle.hpp> +#include <luabind/detail/primitives.hpp> + +#ifdef BOOST_MSVC +// msvc doesn't have two-phase, but requires +// method_rep (and overload_rep) to be complete +// because of its std::list implementation. +// gcc on the other hand has two-phase but doesn't +// require method_rep to be complete. #include <luabind/detail/method_rep.hpp> +#endif namespace luabind { @@ -168,8 +177,8 @@ // the lua reference to the metatable for this class' instances int metatable_ref() const throw() { return m_instance_metatable; } - void get_table(lua_State* L) const { m_table_ref.get(L); } - void get_default_table(lua_State* L) const { m_default_table_ref.get(L); } + void get_table(lua_State* L) const { m_table.push(L); } + void get_default_table(lua_State* L) const { m_default_table.push(L); } void(*destructor() const)(void*) { return m_destructor; } void(*const_holder_destructor() const)(void*) { return m_const_holder_destructor; } @@ -342,11 +351,11 @@ // this table contains c closures for all // member functions in this class, they // may point to both static and virtual functions - detail::lua_reference m_table_ref; + handle m_table; // this table contains default implementations of the - // virtual functions in m_table_ref. - detail::lua_reference m_default_table_ref; + // virtual functions in m_table. + handle m_default_table; // the type of this class.. determines if it's written in c++ or lua class_type m_class_type; @@ -358,9 +367,8 @@ // ***** the maps below contains all members in this class ***** - // list of methods. pointers into this list is put - // in the m_table_ref and m_default_table_ref - // for access. The struct contains the function- + // list of methods. pointers into this list is put in the m_table and + // m_default_table for access. The struct contains the function- // signatures for every overload std::list<method_rep> m_methods; @@ -386,6 +394,6 @@ }} -#include <luabind/detail/overload_rep_impl.hpp> +//#include <luabind/detail/overload_rep_impl.hpp> #endif // LUABIND_CLASS_REP_HPP_INCLUDED Index: constructor.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/detail/constructor.hpp,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- constructor.hpp 7 Aug 2004 13:37:10 -0000 1.7 +++ constructor.hpp 28 Nov 2005 20:55:34 -0000 1.8 @@ -104,7 +104,7 @@ template<class T, class Policies, BOOST_PP_ENUM_PARAMS(LUABIND_MAX_ARITY, class A)> static T* execute( lua_State* L - , weak_ref const& ref + , weak_ref const& , T* , constructor<BOOST_PP_ENUM_PARAMS(LUABIND_MAX_ARITY,A)>* , Policies*) Index: other.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/detail/other.hpp,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- other.hpp 14 Jun 2003 21:05:02 -0000 1.2 +++ other.hpp 28 Nov 2005 20:55:34 -0000 1.3 @@ -74,7 +74,7 @@ no_other_t is_other_test(...); template<typename T> - yes_other_t is_other_test(type< other<T> >); + yes_other_t is_other_test(type_< other<T> >); template<bool wrapped> struct other_unwrapper @@ -102,7 +102,7 @@ public: BOOST_STATIC_CONSTANT( bool, value = ( - sizeof(detail::is_other_test(type<T>())) + sizeof(detail::is_other_test(type_<T>())) == sizeof(detail::yes_other_t))); }; Index: find_best_match.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/detail/find_best_match.hpp,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- find_best_match.hpp 14 Jun 2003 21:05:02 -0000 1.5 +++ find_best_match.hpp 28 Nov 2005 20:55:34 -0000 1.6 @@ -33,16 +33,25 @@ // expects that a match function can be accesed through the iterator // as int match_fun(lua_State*) - // returns true if it found a match better than the given. If it finds a better match match_index is - // updated to contain the new index to the best match (this index now refers to the list given to - // this call). - // orep_size is supposed to tell the size of the actual structures that start and end points to - // ambiguous is set to true if the match was ambiguous - // min_match should be initialized to the currently best match value (the number of implicit casts - // to get a perfect match). If there are no previous matches, set min_match to std::numeric_limits<int>::max() + // returns true if it found a match better than the given. If it finds a + // better match match_index is updated to contain the new index to the best + // match (this index now refers to the list given to this call). + // orep_size is supposed to tell the size of the actual structures that + // start and end points to ambiguous is set to true if the match was + // ambiguous min_match should be initialized to the currently best match + // value (the number of implicit casts to get a perfect match). If there + // are no previous matches, set min_match to + // std::numeric_limits<int>::max() - LUABIND_API bool find_best_match(lua_State* L, const detail::overload_rep_base* start, int num_overloads, size_t orep_size, bool& ambiguous, int& min_match, int& match_index, int num_params); - LUABIND_API void find_exact_match(lua_State* L, const detail::overload_rep_base* start, int num_overloads, size_t orep_size, int cmp_match, int num_params, std::vector<const overload_rep_base*>& dest); + LUABIND_API bool find_best_match(lua_State* L + , detail::overload_rep_base const* start, int num_overloads + , size_t orep_size, bool& ambiguous, int& min_match, int& match_index + , int num_params); + + LUABIND_API void find_exact_match(lua_State* L + , detail::overload_rep_base const* start, int num_overloads + , size_t orep_size, int cmp_match, int num_params + , std::vector<overload_rep_base const*>& dest); }} Index: call_operator_iterate.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/detail/call_operator_iterate.hpp,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- call_operator_iterate.hpp 12 Aug 2004 12:40:43 -0000 1.4 +++ call_operator_iterate.hpp 28 Nov 2005 20:55:34 -0000 1.5 @@ -45,7 +45,8 @@ BOOST_PP_ENUM_TRAILING(N, LUABIND_UNWRAP_PARAMETER, _) ) { - detail::operator_result( + using namespace detail; + operator_result( L #if BOOST_WORKAROUND(BOOST_MSVC, <= 1300) , self(BOOST_PP_ENUM_PARAMS(N, _)) Index: primitives.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/detail/primitives.hpp,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- primitives.hpp 16 Apr 2004 17:15:34 -0000 1.7 +++ primitives.hpp 28 Nov 2005 20:55:34 -0000 1.8 @@ -38,7 +38,7 @@ }; template<class T> - struct type {}; + struct type_ {}; struct null_type {}; @@ -78,7 +78,7 @@ // returns the offset added to a Derived* when cast to a Base* // TODO: return ptrdiff template<class Derived, class Base> - int ptr_offset(type<Derived>, type<Base>) + int ptr_offset(type_<Derived>, type_<Base>) { aligned<sizeof(Derived)> obj; Derived* ptr = reinterpret_cast<Derived*>(&obj); Index: object_rep.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/detail/object_rep.hpp,v retrieving revision 1.19 retrieving revision 1.20 diff -u -d -r1.19 -r1.20 --- object_rep.hpp 7 Aug 2004 13:37:10 -0000 1.19 +++ object_rep.hpp 28 Nov 2005 20:55:34 -0000 1.20 @@ -99,6 +99,8 @@ { static void apply(void* ptr) { + // Removes unreferenced formal parameter warning on VC7. + (void)ptr; #ifndef NDEBUG int completeness_check[sizeof(T)]; (void)completeness_check; Index: call_function.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/detail/call_function.hpp,v retrieving revision 1.13 retrieving revision 1.14 diff -u -d -r1.13 -r1.14 --- call_function.hpp 7 Aug 2004 13:37:10 -0000 1.13 +++ call_function.hpp 28 Nov 2005 20:55:34 -0000 1.14 @@ -368,8 +368,8 @@ , luabind::detail::proxy_function_void_caller<boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> > , luabind::detail::proxy_function_caller<Ret, boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> > >::type proxy_type; - obj.pushvalue(); - return proxy_type(obj.lua_state(), 1, &detail::pcall, args); + obj.push(obj.interpreter()); + return proxy_type(obj.interpreter(), 1, &detail::pcall, args); } template<class Ret BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), class A)> @@ -411,8 +411,8 @@ , luabind::detail::proxy_function_void_caller<boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> > , luabind::detail::proxy_function_caller<Ret, boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> > >::type proxy_type; - obj.pushvalue(); - return proxy_type(obj.lua_state(), 1, &detail::resume_impl, args); + obj.push(obj.interpreter()); + return proxy_type(obj.interpreter(), 1, &detail::resume_impl, args); } template<class Ret BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), class A)> Index: policy.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/detail/policy.hpp,v retrieving revision 1.50 retrieving revision 1.51 diff -u -d -r1.50 -r1.51 --- policy.hpp 15 Apr 2005 17:25:30 -0000 1.50 +++ policy.hpp 28 Nov 2005 20:55:34 -0000 1.51 @@ -41,6 +41,7 @@ #include <boost/type_traits/is_base_and_derived.hpp> #include <boost/bind/arg.hpp> #include <boost/limits.hpp> +#include <boost/tuple/tuple.hpp> #include <luabind/detail/class_registry.hpp> #include <luabind/detail/primitives.hpp> @@ -48,14 +49,17 @@ #include <luabind/detail/typetraits.hpp> #include <luabind/detail/class_cache.hpp> #include <luabind/detail/debug.hpp> +#include <luabind/detail/class_rep.hpp> #include <boost/type_traits/add_reference.hpp> #include <luabind/detail/decorate_type.hpp> -#include <luabind/object.hpp> #include <luabind/weak_ref.hpp> #include <luabind/back_reference_fwd.hpp> +#include <luabind/value_wrapper.hpp> +#include <luabind/from_stack.hpp> + namespace luabind { namespace detail @@ -73,7 +77,6 @@ class index_map { public: - index_map(const int* m): m_map(m) {} int operator[](int index) const @@ -82,7 +85,6 @@ } private: - const int* m_map; }; @@ -111,8 +113,7 @@ LUABIND_API int implicit_cast(const class_rep* crep, LUABIND_TYPE_INFO const&, int& pointer_offset); } - template<class T> class functor; - class object; +// template<class T> class functor; class weak_ref; } @@ -120,7 +121,7 @@ { template<class> struct is_primitive; - +/* template<class T> yes_t is_lua_functor_test(const functor<T>&); @@ -138,7 +139,7 @@ BOOST_STATIC_CONSTANT(bool, value = sizeof(is_lua_functor_test(t)) == sizeof(yes_t)); }; - +*/ template<class H, class T> struct policy_cons { @@ -228,10 +229,6 @@ #undef LUABIND_INTEGER_TYPE - template<> struct is_primitive<luabind::object>: boost::mpl::bool_<true> {}; - template<> struct is_primitive<const luabind::object>: boost::mpl::bool_<true> {}; - template<> struct is_primitive<const luabind::object&>: boost::mpl::bool_<true> {}; - template<> struct is_primitive<luabind::weak_ref>: boost::mpl::bool_<true> {}; template<> struct is_primitive<const luabind::weak_ref>: boost::mpl::bool_<true> {}; template<> struct is_primitive<const luabind::weak_ref&>: boost::mpl::bool_<true> {}; @@ -265,22 +262,9 @@ template<> struct primitive_converter<cpp_to_lua> { + typedef boost::mpl::bool_<false> is_value_converter; typedef primitive_converter type; - void apply(lua_State* L, const luabind::object& v) - { - // if the luabind::object is uninitialized - // treat it as nil. - if (v.lua_state() == 0) - { - lua_pushnil(L); - return; - } - // if you hit this assert you are trying to return a value from one state into another lua state - assert((v.lua_state() == L) && "you cannot return an uninitilized value " - "or a value from one lua state into another"); - v.pushvalue(); - } void apply(lua_State* L, int v) { lua_pushnumber(L, (lua_Number)v); } void apply(lua_State* L, short v) { lua_pushnumber(L, (lua_Number)v); } void apply(lua_State* L, char v) { lua_pushnumber(L, (lua_Number)v); } @@ -311,6 +295,7 @@ template<> struct primitive_converter<lua_to_cpp> { + typedef boost::mpl::bool_<false> is_value_converter; typedef primitive_converter type; #define PRIMITIVE_CONVERTER(prim) \ @@ -363,30 +348,13 @@ { return std::string(lua_tostring(L, index), lua_strlen(L, index)); } PRIMITIVE_MATCHER(std::string) { if (lua_type(L, index) == LUA_TSTRING) return 0; else return -1; } - PRIMITIVE_CONVERTER(luabind::object) - { - LUABIND_CHECK_STACK(L); - - lua_pushvalue(L, index); - detail::lua_reference ref; - ref.set(L); - return luabind::object(L, ref, true); - } - - PRIMITIVE_MATCHER(luabind::object) - { - (void)index; - (void)L; - return std::numeric_limits<int>::max() / LUABIND_MAX_ARITY; - } - PRIMITIVE_CONVERTER(luabind::weak_ref) { LUABIND_CHECK_STACK(L); return luabind::weak_ref(L, index); } - PRIMITIVE_MATCHER(luabind::weak_ref) { (void)index; (void)L; return std::numeric_limits<int>::max() - 1; } + PRIMITIVE_MATCHER(luabind::weak_ref) { (void)index; (void)L; return (std::numeric_limits<int>::max)() - 1; } const char* apply(lua_State* L, detail::by_const_pointer<char>, int index) { @@ -425,6 +393,7 @@ template<> struct user_defined_converter<lua_to_cpp> { + typedef boost::mpl::bool_<false> is_value_converter; typedef user_defined_converter type; template<class T> @@ -476,6 +445,7 @@ template<> struct user_defined_converter<cpp_to_lua> { + typedef boost::mpl::bool_<false> is_value_converter; typedef user_defined_converter type; template<class T> @@ -494,6 +464,7 @@ template<> struct pointer_converter<cpp_to_lua> { + typedef boost::mpl::bool_<false> is_value_converter; typedef pointer_converter type; template<class T> @@ -505,7 +476,7 @@ return; } - if (back_reference<T>::extract(L, ptr)) + if (luabind::get_back_reference(L, ptr)) return; class_rep* crep = get_class_rep<T>(L); @@ -529,6 +500,7 @@ template<> struct pointer_converter<lua_to_cpp> { + typedef boost::mpl::bool_<false> is_value_converter; typedef pointer_converter type; // TODO: does the pointer converter need this?! @@ -594,12 +566,13 @@ template<> struct value_converter<cpp_to_lua> { + typedef boost::mpl::bool_<true> is_value_converter; typedef value_converter type; template<class T> void apply(lua_State* L, const T& ref) { - if (back_reference<T>::extract(L, &ref)) + if (luabind::get_back_reference(L, ref)) return; class_rep* crep = get_class_rep<T>(L); @@ -659,6 +632,7 @@ template<> struct value_converter<lua_to_cpp> { + typedef boost::mpl::bool_<true> is_value_converter; typedef value_converter type; template<class T> @@ -734,6 +708,7 @@ template<> struct const_pointer_converter<cpp_to_lua> { + typedef boost::mpl::bool_<false> is_value_converter; typedef const_pointer_converter type; template<class T> @@ -745,7 +720,7 @@ return; } - if (back_reference<T>::extract(L, ptr)) + if (luabind::get_back_reference(L, ptr)) return; class_rep* crep = get_class_rep<T>(L); @@ -772,6 +747,7 @@ struct const_pointer_converter<lua_to_cpp> : private pointer_converter<lua_to_cpp> { + typedef boost::mpl::bool_<false> is_value_converter; typedef const_pointer_converter type; template<class T> @@ -794,7 +770,8 @@ bool const_ = obj->flags() & object_rep::constant; int d; - return implicit_cast(obj->crep(), LUABIND_TYPEID(T), d) + !const_; + int points = implicit_cast(obj->crep(), LUABIND_TYPEID(T), d); + return points == -1 ? -1 : points + !const_; } template<class T> @@ -811,12 +788,13 @@ template<> struct ref_converter<cpp_to_lua> { + typedef boost::mpl::bool_<false> is_value_converter; typedef ref_converter type; template<class T> void apply(lua_State* L, T& ref) { - if (back_reference<T>::extract(L, &ref)) + if (luabind::get_back_reference(L, ref)) return; class_rep* crep = get_class_rep<T>(L); @@ -842,6 +820,7 @@ template<> struct ref_converter<lua_to_cpp> { + typedef boost::mpl::bool_<false> is_value_converter; typedef ref_converter type; template<class T> @@ -869,12 +848,13 @@ template<> struct const_ref_converter<cpp_to_lua> { + typedef boost::mpl::bool_<false> is_value_converter; typedef const_ref_converter type; template<class T> void apply(lua_State* L, const T& ref) { - if (back_reference<T>::extract(L, &ref)) + if (luabind::get_back_reference(L, ref)) return; class_rep* crep = get_class_rep<T>(L); @@ -919,6 +899,7 @@ template<> struct const_ref_converter<lua_to_cpp> { + typedef boost::mpl::bool_<false> is_value_converter; typedef const_ref_converter type; // TODO: align! @@ -981,7 +962,8 @@ bool const_ = obj->flags() & object_rep::constant; int d; - return implicit_cast(obj->crep(), LUABIND_TYPEID(T), d) + !const_; + int points = implicit_cast(obj->crep(), LUABIND_TYPEID(T), d); + return points == -1 ? -1 : points + !const_; } ~const_ref_converter() @@ -1000,6 +982,7 @@ template<class Direction = cpp_to_lua> struct enum_converter { + typedef boost::mpl::bool_<false> is_value_converter; typedef enum_converter type; void apply(lua_State* L, int val) @@ -1011,6 +994,7 @@ template<> struct enum_converter<lua_to_cpp> { + typedef boost::mpl::bool_<false> is_value_converter; typedef enum_converter type; template<class T> @@ -1028,7 +1012,7 @@ template<class T> void converter_postcall(lua_State*, T, int) {} }; - +/* // ****** functor converter ******** template<class Direction> struct functor_converter; @@ -1077,10 +1061,58 @@ template<class T> void converter_postcall(lua_State*, T, int) {} }; +*/ + + template<class Direction> + struct value_wrapper_converter; + + template<> + struct value_wrapper_converter<lua_to_cpp> + { + typedef boost::mpl::bool_<false> is_value_converter; + typedef value_wrapper_converter type; + + template<class T> + T apply(lua_State* L, by_const_reference<T>, int index) + { + return T(from_stack(L, index)); + } + + template<class T> + T apply(lua_State* L, by_value<T>, int index) + { + return apply(L, by_const_reference<T>(), index); + } + + template<class T> + static int match(lua_State* L, by_const_reference<T>, int index) + { + return value_wrapper_traits<T>::check(L, index) + ? (std::numeric_limits<int>::max)() / LUABIND_MAX_ARITY + : -1; + } + template<class T> + static int match(lua_State* L, by_value<T>, int index) + { + return match(L, by_const_reference<T>(), index); + } + void converter_postcall(...) {} + }; + template<> + struct value_wrapper_converter<cpp_to_lua> + { + typedef boost::mpl::bool_<false> is_value_converter; + typedef value_wrapper_converter type; + template<class T> + void apply(lua_State* interpreter, T const& value_wrapper) + { + value_wrapper_traits<T>::unwrap(interpreter, value_wrapper); + } + }; // *********** default_policy ***************** @@ -1099,35 +1131,39 @@ is_user_defined<T> , user_defined_converter<Direction> , eval_if< - is_primitive<T> - , primitive_converter<Direction> + is_value_wrapper_arg<T> + , value_wrapper_converter<Direction> , eval_if< - is_lua_functor<T> - , functor_converter<Direction> + is_primitive<T> + , primitive_converter<Direction> , eval_if< - boost::is_enum<T> - , enum_converter<Direction> - , eval_if< - is_nonconst_pointer<T> - , pointer_converter<Direction> +// is_lua_functor<T> +// , functor_converter<Direction> +// , eval_if< + boost::is_enum<T> + , enum_converter<Direction> , eval_if< - is_const_pointer<T> - , const_pointer_converter<Direction> + is_nonconst_pointer<T> + , pointer_converter<Direction> , eval_if< - is_nonconst_reference<T> - , ref_converter<Direction> + is_const_pointer<T> + , const_pointer_converter<Direction> , eval_if< - is_const_reference<T> - , const_ref_converter<Direction> - , value_converter<Direction> + is_nonconst_reference<T> + , ref_converter<Direction> + , eval_if< + is_const_reference<T> + , const_ref_converter<Direction> + , value_converter<Direction> + > > > > > - > +// > > > - > + > { }; }; @@ -1263,7 +1299,5 @@ LUABIND_ANONYMOUS_FIX boost::arg<0> result; }} -#include <luabind/detail/object_funs.hpp> - #endif // LUABIND_POLICY_HPP_INCLUDED Index: call_member.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/detail/call_member.hpp,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- call_member.hpp 7 Aug 2004 13:37:10 -0000 1.11 +++ call_member.hpp 28 Nov 2005 20:55:34 -0000 1.12 @@ -30,6 +30,10 @@ #include <luabind/detail/convert_to_lua.hpp> #include <luabind/detail/pcall.hpp> #include <luabind/error.hpp> +#include <luabind/detail/stack_utils.hpp> +#include <luabind/object.hpp> // TODO: REMOVE DEPENDENCY + +#include <boost/tuple/tuple.hpp> #include <boost/preprocessor/control/if.hpp> #include <boost/preprocessor/facilities/expand.hpp> @@ -336,18 +340,18 @@ // once the call has been made // get the function - obj.pushvalue(); - lua_pushstring(obj.lua_state(), name); - lua_gettable(obj.lua_state(), -2); + obj.push(obj.interpreter()); + lua_pushstring(obj.interpreter(), name); + lua_gettable(obj.interpreter(), -2); // duplicate the self-object - lua_pushvalue(obj.lua_state(), -2); + lua_pushvalue(obj.interpreter(), -2); // remove the bottom self-object - lua_remove(obj.lua_state(), -3); + lua_remove(obj.interpreter(), -3); // now the function and self objects // are on the stack. These will both // be popped by pcall - return proxy_type(obj.lua_state(), args); + return proxy_type(obj.interpreter(), args); } #undef LUABIND_OPERATOR_PARAMS Index: overload_rep.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/detail/overload_rep.hpp,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- overload_rep.hpp 1 Aug 2005 17:29:19 -0000 1.7 +++ overload_rep.hpp 28 Nov 2005 20:55:34 -0000 1.8 @@ -30,13 +30,18 @@ #include <boost/preprocessor/enum_params.hpp> #include <boost/preprocessor/iteration/iterate.hpp> +#include <boost/preprocessor/repetition/enum_trailing_params.hpp> #include <boost/preprocessor/repeat.hpp> +#include <vector> #include <luabind/detail/overload_rep_base.hpp> -#include <luabind/detail/class_rep.hpp> #include <luabind/detail/is_indirect_const.hpp> +#ifndef BOOST_MSVC +#include <luabind/detail/policy.hpp> +#endif + namespace luabind { namespace detail { struct dummy_ {}; @@ -94,7 +99,7 @@ #elif BOOST_PP_ITERATION_FLAGS() == 1 #define LUABIND_PARAM(z, n, _) m_params_.push_back(LUABIND_TYPEID(A##n)); -#define LUABIND_POLICY_DECL(z,n,offset) typedef typename find_conversion_policy<n + offset, Policies>::type BOOST_PP_CAT(p,n); +#define LUABIND_POLICY_DECL(z,n,offset) typedef typename detail::find_conversion_policy<n + offset, Policies>::type BOOST_PP_CAT(p,n); #define LUABIND_ARITY(z,n,text) + BOOST_PP_CAT(p,n)::has_arg // overloaded template funtion that initializes the parameter list Index: call.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/detail/call.hpp,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- call.hpp 7 Aug 2004 13:37:10 -0000 1.6 +++ call.hpp 28 Nov 2005 20:55:34 -0000 1.7 @@ -41,6 +41,8 @@ #include <luabind/detail/policy.hpp> #include <luabind/yield_policy.hpp> +#include <luabind/detail/most_derived.hpp> + #define LUABIND_DECL(z, n, off) \ typedef typename find_conversion_policy< \ n + off \ @@ -92,16 +94,6 @@ } }; - template<class Class, class WrappedClass> - struct most_derived - { - typedef typename boost::mpl::if_< - boost::is_base_and_derived<Class, WrappedClass> - , WrappedClass - , Class - >::type type; - }; - template<class T> struct returns { Index: overload_rep_base.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/detail/overload_rep_base.hpp,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- overload_rep_base.hpp 7 Aug 2004 13:37:10 -0000 1.3 +++ overload_rep_base.hpp 28 Nov 2005 20:55:34 -0000 1.4 @@ -26,6 +26,8 @@ #include <luabind/config.hpp> #include <boost/function/function1.hpp> +struct lua_State; + namespace luabind { namespace detail { // this class represents a specific overload of a member-function. @@ -34,10 +36,10 @@ #if !defined(NDEBUG) && !defined(LUABIND_NO_ERROR_CHECKING) overload_rep_base(): m_get_signature_fun(0), m_match_fun(0), m_arity(-1) {} #else - overload_rep_base(): m_match_fun(0), m_arity(-1) {} + overload_rep_base(): m_match_fun(0), m_arity(-1) {} #endif - typedef boost::function1<int, lua_State*> match_fun_t; + typedef boost::function1<int, lua_State*> match_fun_t; typedef void(*get_sig_ptr)(lua_State*, std::string&); inline int match(lua_State* L, int num_params) const --- overload_rep_impl.hpp DELETED --- Index: property.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/detail/property.hpp,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- property.hpp 7 Aug 2004 13:37:10 -0000 1.11 +++ property.hpp 28 Nov 2005 20:55:34 -0000 1.12 @@ -25,6 +25,9 @@ #define LUABIND_PROPERTY_HPP_INCLUDED #include <luabind/config.hpp> +#include <boost/type_traits/add_reference.hpp> +#include <boost/mpl/eval_if.hpp> +#include <luabind/dependency_policy.hpp> namespace luabind { namespace detail { @@ -126,7 +129,6 @@ return set_matcher<Param, Policy>::apply; } - // TODO: add support for policies template<class T, class D, class Policies> struct auto_set : Policies { @@ -167,7 +169,15 @@ } }; - // TODO: add support for policies + // if the input type is a value_converter, it will produce + // a reference converter + template<class ConverterPolicy, class D> + struct make_reference_converter + { + typedef typename ConverterPolicy::template generate_converter< + typename boost::add_reference<D>::type, cpp_to_lua>::type type; + }; + template<class T, class D, class Policies> struct auto_get : Policies { @@ -194,14 +204,29 @@ T* ptr = reinterpret_cast<T*>(static_cast<char*>(raw_ptr) + pointer_offset); typedef typename find_conversion_policy<0,Policies>::type converter_policy; - typename converter_policy::template generate_converter<D,cpp_to_lua>::type converter; + typedef typename converter_policy::template generate_converter<D,cpp_to_lua>::type converter1_t; + + // if the converter is a valua converer, return a reference instead + typedef typename boost::mpl::eval_if< + typename converter1_t::is_value_converter + , make_reference_converter<converter_policy, D> + , converter1_t>::type converter2_t; + + // If this yields a reference converter, the dependency policy + // is automatically added + typedef typename boost::mpl::if_< + typename converter1_t::is_value_converter + , policy_cons<dependency_policy<1, 0>, Policies> + , Policies>::type policy_list; + + converter2_t converter; converter.apply(L, ptr->*member); int nret = lua_gettop(L) - nargs; const int indices[] = { 1, nargs + nret }; - policy_list_postcall<Policies>::apply(L, indices); + policy_list_postcall<policy_list>::apply(L, indices); return nret; } --- NEW FILE: most_derived.hpp --- // Copyright (c) 2005 Daniel Wallin and Arvid Norberg // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the "Software"), // to deal in the Software without restriction, including without limitation // the rights to use, copy, modify, merge, publish, distribute, sublicense, // and/or sell copies of the Software, and to permit persons to whom the // Software is furnished to do so, subject to the following conditions: // The above copyright notice and this permission notice shall be included // in all copies or substantial portions of the Software. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF // ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A // PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT // SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR // ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE // OR OTHER DEALINGS IN THE SOFTWARE. #ifndef MOST_DERIVED_051018_HPP # define MOST_DERIVED_051018_HPP # include <boost/mpl/if.hpp> # include <boost/type_traits/is_base_and_derived.hpp> namespace luabind { namespace detail { template<class Class, class WrappedClass> struct most_derived { typedef typename boost::mpl::if_< boost::is_base_and_derived<Class, WrappedClass> , WrappedClass , Class >::type type; }; }} // namespace luabind::detail #endif // MOST_DERIVED_051018_HPP |
From: Arvid N. <ar...@us...> - 2005-11-28 20:55:43
|
Update of /cvsroot/luabind/luabind/luabind/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15879/luabind/src Modified Files: Jamfile class_info.cpp class_rep.cpp find_best_match.cpp makefile Added Files: overload_rep.cpp Removed Files: object.cpp Log Message: merged in changes from beta7-devel2 (tag: beta7-devel2-merge) Index: Jamfile =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/src/Jamfile,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- Jamfile 7 Aug 2004 13:37:11 -0000 1.6 +++ Jamfile 28 Nov 2005 20:55:34 -0000 1.7 @@ -14,11 +14,11 @@ open.cpp create_class.cpp stack_content_by_name.cpp - object.cpp object_rep.cpp class_info.cpp ref.cpp class_registry.cpp + overload_rep.cpp link_compatibility.cpp : <define>LUABIND_BUILDING ; Index: makefile =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/src/makefile,v retrieving revision 1.17 retrieving revision 1.18 diff -u -d -r1.17 -r1.18 --- makefile 7 Aug 2004 13:37:11 -0000 1.17 +++ makefile 28 Nov 2005 20:55:34 -0000 1.18 @@ -14,12 +14,12 @@ open.cpp \ create_class.cpp \ stack_content_by_name.cpp \ - object.cpp \ object_rep.cpp \ class_info.cpp \ class_registry.cpp \ link_compatibility.cpp \ weak_ref.cpp \ + overload_rep.cpp \ link_compatibility.cpp OBJECTS = $(SOURCES:.cpp=.o) Index: class_info.cpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/src/class_info.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- class_info.cpp 7 Aug 2004 13:37:11 -0000 1.4 +++ class_info.cpp 28 Nov 2005 20:55:34 -0000 1.5 @@ -29,18 +29,22 @@ { class_info get_class_info(const object& o) { - lua_State* L = o.lua_state(); + lua_State* L = o.interpreter(); - class_info result(L); + class_info result; - o.pushvalue(); + o.push(L); detail::object_rep* obj = static_cast<detail::object_rep*>(lua_touserdata(L, -1)); lua_pop(L, 1); result.name = obj->crep()->name(); obj->crep()->get_table(L); - result.methods.set(); + object methods(from_stack(L, -1)); + + methods.swap(result.methods); + lua_pop(L, 1); + result.attributes = newtable(L); typedef detail::class_rep::property_map map_type; --- NEW FILE: overload_rep.cpp --- // Copyright (c) 2005 Daniel Wallin and Arvid Norberg // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the "Software"), // to deal in the Software without restriction, including without limitation // the rights to use, copy, modify, merge, publish, distribute, sublicense, // and/or sell copies of the Software, and to permit persons to whom the // Software is furnished to do so, subject to the following conditions: // The above copyright notice and this permission notice shall be included // in all copies or substantial portions of the Software. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF // ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A // PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT // SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR // ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE // OR OTHER DEALINGS IN THE SOFTWARE. #include <luabind/detail/overload_rep.hpp> namespace luabind { namespace detail { int overload_rep::call(lua_State* L, bool force_static_call) const { if (force_static_call) return call_fun_static(L); else return call_fun(L); } }} // namespace luabind::detail Index: class_rep.cpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/src/class_rep.cpp,v retrieving revision 1.49 retrieving revision 1.50 diff -u -d -r1.49 -r1.50 --- class_rep.cpp 10 Aug 2004 06:54:13 -0000 1.49 +++ class_rep.cpp 28 Nov 2005 20:55:34 -0000 1.50 @@ -101,10 +101,10 @@ assert(m_holder_alignment >= 1 && "internal error"); lua_newtable(L); - m_table_ref.set(L); - + handle(L, -1).swap(m_table); lua_newtable(L); - m_default_table_ref.set(L); + handle(L, -1).swap(m_default_table); + lua_pop(L, 2); class_registry* r = class_registry::get_registry(L); assert((r->cpp_class() != LUA_NOREF) && "you must call luabind::open()"); @@ -139,10 +139,10 @@ , m_operator_cache(0) { lua_newtable(L); - m_table_ref.set(L); - + handle(L, -1).swap(m_table); lua_newtable(L); - m_default_table_ref.set(L); + handle(L, -1).swap(m_default_table); + lua_pop(L, 2); class_registry* r = class_registry::get_registry(L); assert((r->cpp_class() != LUA_NOREF) && "you must call luabind::open()"); @@ -274,7 +274,7 @@ lua_gettable(L, -2); if (!lua_isnil(L, -1)) { - lua_remove(L, -2); // more table + lua_remove(L, -2); // remove table return 1; } lua_pop(L, 2); @@ -287,7 +287,7 @@ if (!lua_isnil(L, -1)) { - lua_remove(L, -2); // more table + lua_remove(L, -2); // remove table return 1; } lua_pop(L, 2); @@ -615,7 +615,8 @@ #endif int num_params = lua_gettop(L) /*- 1*/; - found = find_best_match(L, &rep->overloads().front(), rep->overloads().size(), sizeof(overload_rep), ambiguous, min_match, match_index, num_params); + found = find_best_match(L, &rep->overloads().front(), rep->overloads().size() + , sizeof(overload_rep), ambiguous, min_match, match_index, num_params); #ifdef LUABIND_NO_ERROR_CHECKING @@ -639,7 +640,8 @@ function_name += ":"; function_name += rep->name; - msg += get_overload_signatures(L, rep->overloads().begin(), rep->overloads().end(), function_name); + msg += get_overload_signatures(L, rep->overloads().begin() + , rep->overloads().end(), function_name); lua_pushstring(L, msg.c_str()); } @@ -657,14 +659,16 @@ msg += ")' is ambiguous\nnone of the overloads have a best conversion:\n"; std::vector<const overload_rep_base*> candidates; - find_exact_match(L, &rep->overloads().front(), rep->overloads().size(), sizeof(overload_rep), min_match, num_params, candidates); + find_exact_match(L, &rep->overloads().front(), rep->overloads().size() + , sizeof(overload_rep), min_match, num_params, candidates); std::string function_name; function_name += rep->crep->name(); function_name += ":"; function_name += rep->name; - msg += get_overload_signatures_candidates(L, candidates.begin(), candidates.end(), function_name); + msg += get_overload_signatures_candidates(L, candidates.begin() + , candidates.end(), function_name); lua_pushstring(L, msg.c_str()); } @@ -734,8 +738,8 @@ std::string to_string(luabind::object const& o) { using namespace luabind; - if (o.type() == LUA_TSTRING) return object_cast<std::string>(o); - lua_State* L = o.lua_state(); + if (type(o) == LUA_TSTRING) return object_cast<std::string>(o); + lua_State* L = o.interpreter(); LUABIND_CHECK_STACK(L); #ifdef BOOST_NO_STRINGSTREAM @@ -744,13 +748,13 @@ std::stringstream s; #endif - if (o.type() == LUA_TNUMBER) + if (type(o) == LUA_TNUMBER) { s << object_cast<float>(o); return s.str(); } - s << "<" << lua_typename(L, o.type()) << ">"; + s << "<" << lua_typename(L, type(o)) << ">"; #ifdef BOOST_NO_STRINGSTREAM s << std::ends; #endif @@ -762,12 +766,12 @@ { #if !defined(LUABIND_NO_ERROR_CHECKING) using namespace luabind; - lua_State* L = e.lua_state(); + lua_State* L = e.interpreter(); LUABIND_CHECK_STACK(L); - if (e.type() == LUA_TFUNCTION) + if (type(e) == LUA_TFUNCTION) { - e.pushvalue(); + e.push(L); detail::stack_pop p(L, 1); { @@ -828,21 +832,17 @@ ret << "dynamic dispatch functions:\n------------------\n"; - get_table(L); - object t(L); - t.set(); - for (object::iterator i = t.begin(); i != t.end(); ++i) + for (luabind::iterator i(m_table), end; i != end; ++i) { - object e = *i; + luabind::object e = *i; ret << " " << to_string(i.key()) << ": " << member_to_string(e) << "\n"; } ret << "default implementations:\n------------------\n"; - get_default_table(L); - t.set(); - for (object::iterator i = t.begin(); i != t.end(); ++i) + + for (luabind::iterator i(m_default_table), end; i != end; ++i) { - object e = *i; + luabind::object e = *i; ret << " " << to_string(i.key()) << ": " << member_to_string(e) << "\n"; } #ifdef BOOST_NO_STRINGSTREAM @@ -1641,8 +1641,8 @@ LUABIND_CHECK_STACK(L); // insert the function in the normal member table // and in the default member table - m_default_table_ref.get(L); - m_table_ref.get(L); + m_default_table.push(L); + m_table.push(L); // pops the tables detail::stack_pop pop_tables(L, 2); @@ -1650,7 +1650,7 @@ for (std::list<method_rep>::const_iterator m = m_methods.begin(); m != m_methods.end(); ++m) { - // create the function closure in m_table_ref + // create the function closure in m_table lua_pushstring(L, m->name); lua_pushlightuserdata(L, const_cast<void*>((const void*)&(*m))); lua_pushboolean(L, 0); @@ -1658,7 +1658,7 @@ lua_pushcclosure(L, function_dispatcher, 3); lua_settable(L, -3); - // create the function closure in m_default_table_ref + // create the function closure in m_default_table lua_pushstring(L, m->name); lua_pushlightuserdata(L, const_cast<void*>((const void*)&(*m))); lua_pushboolean(L, 1); --- object.cpp DELETED --- Index: find_best_match.cpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/src/find_best_match.cpp,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- find_best_match.cpp 7 Aug 2004 13:37:11 -0000 1.9 +++ find_best_match.cpp 28 Nov 2005 20:55:34 -0000 1.10 @@ -28,7 +28,7 @@ bool luabind::detail::find_best_match( lua_State* L - , const overload_rep_base* start + , overload_rep_base const* start , int num_overloads , size_t orep_size , bool& ambiguous @@ -42,6 +42,7 @@ for (int index = 0; index < num_overloads; ++index) { int match_value = start->match(L, num_params); + reinterpret_cast<const char*&>(start) += orep_size; if (match_value < 0) continue; @@ -58,13 +59,14 @@ } } - ambiguous = min_match == min_but_one_match && min_match < std::numeric_limits<int>::max(); + ambiguous = min_match == min_but_one_match + && min_match < std::numeric_limits<int>::max(); return found; } void luabind::detail::find_exact_match( lua_State* L - , const overload_rep_base* start + , overload_rep_base const* start , int num_overloads , size_t orep_size , int cmp_match |
From: Arvid N. <ar...@us...> - 2005-11-28 20:55:43
|
Update of /cvsroot/luabind/luabind/luabind/examples/intrusive_ptr In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15879/luabind/examples/intrusive_ptr Modified Files: Jamfile Log Message: merged in changes from beta7-devel2 (tag: beta7-devel2-merge) Index: Jamfile =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/examples/intrusive_ptr/Jamfile,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- Jamfile 4 Apr 2004 16:34:32 -0000 1.1 +++ Jamfile 28 Nov 2005 20:55:34 -0000 1.2 @@ -5,3 +5,5 @@ /luabind//luabind ; +stage . : intrusive_ptr ; + |
From: Arvid N. <ar...@us...> - 2005-11-28 20:55:43
|
Update of /cvsroot/luabind/luabind/luabind/examples/any_converter In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15879/luabind/examples/any_converter Modified Files: Jamfile any_converter.cpp Log Message: merged in changes from beta7-devel2 (tag: beta7-devel2-merge) Index: any_converter.cpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/examples/any_converter/any_converter.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- any_converter.cpp 4 Apr 2004 16:14:05 -0000 1.3 +++ any_converter.cpp 28 Nov 2005 20:55:34 -0000 1.4 @@ -19,8 +19,6 @@ return false; } -#define LUABIND_NO_HEADERS_ONLY - #include <luabind/luabind.hpp> #include <boost/any.hpp> Index: Jamfile =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/examples/any_converter/Jamfile,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- Jamfile 4 Apr 2004 16:36:24 -0000 1.1 +++ Jamfile 28 Nov 2005 20:55:34 -0000 1.2 @@ -5,3 +5,5 @@ /luabind//luabind ; +stage . : any_converter ; + |
From: Arvid N. <ar...@us...> - 2005-11-28 20:55:43
|
Update of /cvsroot/luabind/luabind/luabind/examples/glut In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15879/luabind/examples/glut Modified Files: glut_bind.cpp makefile Added Files: Jamfile Log Message: merged in changes from beta7-devel2 (tag: beta7-devel2-merge) Index: glut_bind.cpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/examples/glut/glut_bind.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- glut_bind.cpp 7 Aug 2004 13:37:10 -0000 1.4 +++ glut_bind.cpp 28 Nov 2005 20:55:34 -0000 1.5 @@ -8,7 +8,7 @@ #include <luabind/luabind.hpp> #include <luabind/class.hpp> #include <luabind/function.hpp> -#include <luabind/functor.hpp> +#include <luabind/object.hpp> #include <GL/glut.h> @@ -18,68 +18,70 @@ struct glut_constants {}; struct gl_constants {}; +using luabind::object; + namespace glut_bindings { - luabind::functor<void> displayfunc; + object displayfunc; void displayfunc_callback() { displayfunc(); } - void set_displayfunc(const luabind::functor<void>& fun) + void set_displayfunc(object const& fun) { glutDisplayFunc(&displayfunc_callback); displayfunc = fun; } - luabind::functor<void> idlefunc; + object idlefunc; void idlefunc_callback() { idlefunc(); } - void set_idlefunc(const luabind::functor<void>& fun) + void set_idlefunc(object const& fun) { glutIdleFunc(&idlefunc_callback); idlefunc = fun; } - luabind::functor<void> reshapefunc; + object reshapefunc; void reshapefunc_callback(int w, int h) { - reshapefunc(w,h); + reshapefunc(w, h); } - void set_reshapefunc(const luabind::functor<void>& fun) + void set_reshapefunc(object const& fun) { reshapefunc = fun; } - luabind::functor<void> keyboardfunc; + object keyboardfunc; void keyboardfunc_callback(unsigned char key, int x, int y) { - keyboardfunc(key,x,y); + keyboardfunc(key, x, y); } - void set_keyboardfunc(const luabind::functor<void>& fun) + void set_keyboardfunc(object const& fun) { glutKeyboardFunc(&keyboardfunc_callback); keyboardfunc = fun; } - luabind::functor<void> mousefunc; + object mousefunc; void mousefunc_callback(int button, int state, int x, int y) { mousefunc(button, state, x, y); } - void set_mousefunc(const luabind::functor<void>& fun) + void set_mousefunc(object const& fun) { mousefunc = fun; } @@ -137,7 +139,7 @@ .enum_("constants") [ value("COLOR_BUFFER_BIT", GL_COLOR_BUFFER_BIT), - value("DEPTH_BUFFER_BIT", GL_DEPTH_BUFFER_BIT), + value("DEPTH_BUFFER_BIT", GL_DEPTH_BUFFER_BIT), value("TRIANGLES", GL_TRIANGLES), value("MODELVIEW", GL_MODELVIEW), value("PROJECTION", GL_PROJECTION) @@ -163,17 +165,13 @@ ]; } -int main() +int main(int argc, char* argv[]) { lua_State* L = lua_open(); lua_baselibopen(L); lua_mathlibopen(L); bind_glut(L); - int argc = 1; - char* argv[1]; - argv[0] = "blabla"; - glutInit (&argc, argv); lua_dofile(L, "glut_bindings.lua"); Index: makefile =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/examples/glut/makefile,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- makefile 4 Apr 2004 16:14:09 -0000 1.5 +++ makefile 28 Nov 2005 20:55:34 -0000 1.6 @@ -2,8 +2,14 @@ all: glut_test +# if using fink on darwin +# you need these additional flags +CPPFLAGS = -I/sw/include -L/sw/lib + glut_test: glut_bind.cpp - $(CXX) glut_bind.cpp -o glut_bind -I$(LUA_PATH)/include -I- -I$(BOOST_ROOT) -I../../ -I/usr/X11R6/include -L/usr/X11R6/lib -L$(LUA_PATH)/lib -L../../lib -lluabind -lX11 -lXi -lXmu -lglut -lGL -lGLU -lm -llua -llualib + $(CXX) glut_bind.cpp -o glut_bind -I$(LUA_PATH)/include -I- -I$(BOOST_ROOT) $(CPPFLAGS) \ + -I../../ -I/usr/X11R6/include -L/usr/X11R6/lib -L$(LUA_PATH)/lib -L../../lib \ + -lluabind -lX11 -lXi -lXmu -lglut -lGL -lGLU -lm -llua -llualib clean: rm -f glut_bind.o --- NEW FILE: Jamfile --- import modules ; lib glut : : <name>glut ; lib glu : : <name>glu ; lib gl : : <name>gl ; exe glut_bind : glut_bind.cpp gl glu glut /luabind//lualib /luabind//luabind ; stage . : glut_bind ; |
From: Arvid N. <ar...@us...> - 2005-11-09 16:59:40
|
Update of /cvsroot/luabind/luabind/luabind/doc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30753 Modified Files: Tag: beta7-devel2 docs.rst Log Message: fixed typo Index: docs.rst =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/doc/docs.rst,v retrieving revision 1.25.2.14 retrieving revision 1.25.2.15 diff -u -d -r1.25.2.14 -r1.25.2.15 --- docs.rst 26 Oct 2005 17:18:49 -0000 1.25.2.14 +++ docs.rst 9 Nov 2005 16:59:22 -0000 1.25.2.15 @@ -773,7 +773,7 @@ There's one special operator. In Lua it's called ``__tostring``, it's not really an operator. It is used for converting objects to strings in a standard way in Lua. If you register this functionality, you will be able to use the lua -standard function ``tostring()`` for converting you object to a string. +standard function ``tostring()`` for converting your object to a string. To implement this operator in C++ you should supply an ``operator<<`` for std::ostream. Like this example: |
From: Arvid N. <ar...@us...> - 2005-10-26 17:18:58
|
Update of /cvsroot/luabind/luabind/luabind/doc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11526 Modified Files: Tag: beta7-devel2 docs.html docs.rst Log Message: foxed typo in example Index: docs.html =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/doc/docs.html,v retrieving revision 1.52.2.11 retrieving revision 1.52.2.12 diff -u -d -r1.52.2.11 -r1.52.2.12 --- docs.html 26 Oct 2005 16:10:26 -0000 1.52.2.11 +++ docs.html 26 Oct 2005 17:18:49 -0000 1.52.2.12 @@ -24,7 +24,7 @@ <tr><th class="docinfo-name">Date:</th> <td>2005-10-26</td></tr> <tr><th class="docinfo-name">Revision:</th> -<td>1.25.2.12</td></tr> +<td>1.25.2.13</td></tr> <tr class="field"><th class="docinfo-name">License:</th><td class="field-body"><p class="first">Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation @@ -1152,7 +1152,7 @@ <pre class="literal-block"> void my_function(object const& table) { - if (table.type() == LUA_TTABLE) + if (type(table) == LUA_TTABLE) { table["time"] = std::clock(); table["name"] = std::rand() < 500 ? "unusual" : "usual"; Index: docs.rst =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/doc/docs.rst,v retrieving revision 1.25.2.13 retrieving revision 1.25.2.14 diff -u -d -r1.25.2.13 -r1.25.2.14 --- docs.rst 26 Oct 2005 16:10:26 -0000 1.25.2.13 +++ docs.rst 26 Oct 2005 17:18:49 -0000 1.25.2.14 @@ -1142,7 +1142,7 @@ void my_function(object const& table) { - if (table.type() == LUA_TTABLE) + if (type(table) == LUA_TTABLE) { table["time"] = std::clock(); table["name"] = std::rand() < 500 ? "unusual" : "usual"; |
From: Arvid N. <ar...@us...> - 2005-10-26 16:10:47
|
Update of /cvsroot/luabind/luabind/luabind/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24965/test Modified Files: Tag: beta7-devel2 test_attributes.cpp Log Message: properties now make the returned reference keep the object alive using the dependency policy Index: test_attributes.cpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/test/test_attributes.cpp,v retrieving revision 1.31.2.4 retrieving revision 1.31.2.5 diff -u -d -r1.31.2.4 -r1.31.2.5 --- test_attributes.cpp 24 Oct 2005 22:24:54 -0000 1.31.2.4 +++ test_attributes.cpp 26 Oct 2005 16:10:27 -0000 1.31.2.5 @@ -43,6 +43,7 @@ struct property_test : counted_type<property_test> { property_test(): o(6), c_ref(&c) {} + ~property_test() { c.a = 0; } std::string str_; int a_; @@ -138,6 +139,16 @@ DOSTRING(L, "test.c.a = 1\n" "assert(test.c.a == 1)\n" "assert(test.c_ref.a == 1)"); + + DOSTRING(L, "t1 = property()\n" + "c = t1.c\n" + "c2 = t1.c_ref\n" + "c.a = 1\n" + "t1 = nil\n" + "collectgarbage()\n" + "collectgarbage()\n" + "assert(c.a == 1)\n" + "assert(c2.a == 1)"); DOSTRING(L, "a = B()\n"); |