luabind-cvs Mailing List for luabind (Page 4)
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-10-26 16:10:35
|
Update of /cvsroot/luabind/luabind/luabind/doc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24965/doc Modified Files: Tag: beta7-devel2 docs.html docs.rst Log Message: properties now make the returned reference keep the object alive using the dependency policy Index: docs.html =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/doc/docs.html,v retrieving revision 1.52.2.10 retrieving revision 1.52.2.11 diff -u -d -r1.52.2.10 -r1.52.2.11 --- docs.html 26 Oct 2005 09:44:23 -0000 1.52.2.10 +++ docs.html 26 Oct 2005 16:10:26 -0000 1.52.2.11 @@ -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-24" /> +<meta name="date" content="2005-10-26" /> <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-24</td></tr> +<td>2005-10-26</td></tr> <tr><th class="docinfo-name">Revision:</th> -<td>1.25.2.11</td></tr> +<td>1.25.2.12</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 @@ -639,7 +639,10 @@ assert(b.a.m == 1) </pre> <p>This requires the first lookup (on <tt class="docutils literal"><span class="pre">a</span></tt>) to return a reference to <tt class="docutils literal"><span class="pre">A</span></tt>, and -not a copy.</p> +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.</p> <p>You can also register getter and setter functions and make them look as if they were a public data member. Consider the following class:</p> <pre class="literal-block"> Index: docs.rst =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/doc/docs.rst,v retrieving revision 1.25.2.12 retrieving revision 1.25.2.13 diff -u -d -r1.25.2.12 -r1.25.2.13 --- docs.rst 26 Oct 2005 09:44:23 -0000 1.25.2.12 +++ docs.rst 26 Oct 2005 16:10:26 -0000 1.25.2.13 @@ -622,7 +622,10 @@ assert(b.a.m == 1) This requires the first lookup (on ``a``) to return a reference to ``A``, and -not a copy. +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:: |
From: Arvid N. <ar...@us...> - 2005-10-26 16:10:35
|
Update of /cvsroot/luabind/luabind/luabind/luabind In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24965/luabind Modified Files: Tag: beta7-devel2 dependency_policy.hpp Log Message: properties now make the returned reference keep the object alive using the dependency policy Index: dependency_policy.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/dependency_policy.hpp,v retrieving revision 1.5 retrieving revision 1.5.4.1 diff -u -d -r1.5 -r1.5.4.1 --- dependency_policy.hpp 29 Aug 2003 10:55:40 -0000 1.5 +++ dependency_policy.hpp 26 Oct 2005 16:10:26 -0000 1.5.4.1 @@ -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 |
From: Arvid N. <ar...@us...> - 2005-10-26 16:10:35
|
Update of /cvsroot/luabind/luabind/luabind/luabind/detail In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24965/luabind/detail Modified Files: Tag: beta7-devel2 policy.hpp property.hpp Log Message: properties now make the returned reference keep the object alive using the dependency policy Index: property.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/detail/property.hpp,v retrieving revision 1.11.2.1 retrieving revision 1.11.2.2 diff -u -d -r1.11.2.1 -r1.11.2.2 --- property.hpp 24 Oct 2005 09:44:00 -0000 1.11.2.1 +++ property.hpp 26 Oct 2005 16:10:26 -0000 1.11.2.2 @@ -27,6 +27,7 @@ #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 { @@ -204,13 +205,19 @@ typedef typename find_conversion_policy<0,Policies>::type converter_policy; 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; - // TODO: If this yields a reference converter, return_internal_reference policy - // should be automatically added + // 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); @@ -219,7 +226,7 @@ const int indices[] = { 1, nargs + nret }; - policy_list_postcall<Policies>::apply(L, indices); + policy_list_postcall<policy_list>::apply(L, indices); return nret; } Index: policy.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/detail/policy.hpp,v retrieving revision 1.50.2.9 retrieving revision 1.50.2.10 diff -u -d -r1.50.2.9 -r1.50.2.10 --- policy.hpp 25 Oct 2005 22:57:47 -0000 1.50.2.9 +++ policy.hpp 26 Oct 2005 16:10:26 -0000 1.50.2.10 @@ -445,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> |
From: Arvid N. <ar...@us...> - 2005-10-26 09:44:32
|
Update of /cvsroot/luabind/luabind/luabind/doc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2517 Modified Files: Tag: beta7-devel2 docs.html docs.rst Log Message: updated documentation Index: docs.html =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/doc/docs.html,v retrieving revision 1.52.2.9 retrieving revision 1.52.2.10 diff -u -d -r1.52.2.9 -r1.52.2.10 --- docs.html 24 Oct 2005 23:11:46 -0000 1.52.2.9 +++ docs.html 26 Oct 2005 09:44:23 -0000 1.52.2.10 @@ -24,7 +24,7 @@ <tr><th class="docinfo-name">Date:</th> <td>2005-10-24</td></tr> <tr><th class="docinfo-name">Revision:</th> -<td>1.25.2.10</td></tr> +<td>1.25.2.11</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 @@ -1010,6 +1010,8 @@ <p>Here, the class <tt class="docutils literal"><span class="pre">X</span></tt> is registered in two steps. The two functions <tt class="docutils literal"><span class="pre">register_part1</span></tt> and <tt class="docutils literal"><span class="pre">register_part2</span></tt> may be put in separate compilation units.</p> +<p>To separate the module registration and the classes to be registered, see +<a class="reference" href="#splitting-up-the-registration">Splitting up the registration</a>.</p> </div> </div> <div class="section" id="object"> @@ -1666,7 +1668,7 @@ </ul> </div> <div class="section" id="adopt"> -<h2><a name="adopt">12.1 adopt</a></h2> +<h2><a class="toc-backref" href="#id93" 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> @@ -1720,7 +1722,7 @@ </div> </div> <div class="section" id="dependency"> -<h2><a name="dependency">12.2 dependency</a></h2> +<h2><a class="toc-backref" href="#id94" 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. @@ -1778,7 +1780,7 @@ </div> </div> <div class="section" id="out-value"> -<h2><a name="out-value">12.3 out_value</a></h2> +<h2><a class="toc-backref" href="#id95" 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 @@ -1841,7 +1843,7 @@ </div> </div> <div class="section" id="pure-out-value"> -<h2><a name="pure-out-value">12.4 pure_out_value</a></h2> +<h2><a class="toc-backref" href="#id96" 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 @@ -1903,7 +1905,7 @@ </div> </div> <div class="section" id="return-reference-to"> -<h2><a name="return-reference-to">12.5 return_reference_to</a></h2> +<h2><a class="toc-backref" href="#id97" 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 @@ -1987,7 +1989,7 @@ </div> </div> <div class="section" id="copy"> -<h2><a name="copy">12.6 copy</a></h2> +<h2><a class="toc-backref" href="#id98" 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 @@ -2046,7 +2048,7 @@ </div> </div> <div class="section" id="discard-result"> -<h2><a name="discard-result">12.7 discard_result</a></h2> +<h2><a class="toc-backref" href="#id99" 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 @@ -2088,7 +2090,7 @@ </div> </div> <div class="section" id="return-stl-iterator"> -<h2><a name="return-stl-iterator">12.8 return_stl_iterator</a></h2> +<h2><a class="toc-backref" href="#id100" 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 @@ -2133,7 +2135,7 @@ </div> </div> <div class="section" id="raw"> -<h2><a name="raw">12.9 raw</a></h2> +<h2><a class="toc-backref" href="#id101" 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. @@ -2193,7 +2195,7 @@ </div> </div> <div class="section" id="yield"> -<h2><a name="yield">12.10 yield</a></h2> +<h2><a class="toc-backref" href="#id102" 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> @@ -2619,8 +2621,8 @@ <h1><a name="configuration">14 Configuration</a></h1> <p>As mentioned in the <a class="reference" href="http://www.lua.org/manual/5.0/manual.html">Lua documentation</a>, it is possible to pass an error handler function to <tt class="docutils literal"><span class="pre">lua_pcall()</span></tt>. Luabind makes use of -<tt class="docutils literal"><span class="pre">lua_pcall()</span></tt> internally when calling methods and functions. It is -possible to set the error handler function that Luabind will use +<tt class="docutils literal"><span class="pre">lua_pcall()</span></tt> internally when calling member functions and free functions. +It is possible to set the error handler function that Luabind will use globally:</p> <pre class="literal-block"> typedef void(*pcall_callback_fun)(lua_State*); @@ -2769,8 +2771,8 @@ the attribute '<em>class-name.attribute-name</em>' is read only </pre> <p>There is no data member named <em>attribute-name</em> in the class <em>class-name</em>, -or there's no setter-method registered on that property name. See the -properties section.</p> +or there's no setter-function registered on that property name. See the +<a class="reference" href="#properties">Properties</a> section.</p> </li> <li><pre class="first literal-block"> the attribute '<em>class-name.attribute-name</em>' is of type: (<em>class-name</em>) and does not match (<em>class_name</em>) @@ -2829,7 +2831,8 @@ <dt>Internal structure overflow in VC</dt> <dd>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.</dd> +unit up in smaller ones. See <a class="reference" href="#splitting-up-the-registration">Splitting up the registration</a> and +<a class="reference" href="#splitting-class-registrations">Splitting class registrations</a>.</dd> </dl> <!-- the three entries above were removed, why? --> <dl class="docutils"> @@ -2886,7 +2889,7 @@ in general).</p> </dd> </dl> -<!-- 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. --> <dl class="docutils"> <dt>Fatal Error C1063 compiler limit : compiler stack overflow in VC</dt> <dd>VC6.5 chokes on warnings, if you are getting alot of warnings from your Index: docs.rst =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/doc/docs.rst,v retrieving revision 1.25.2.11 retrieving revision 1.25.2.12 diff -u -d -r1.25.2.11 -r1.25.2.12 --- docs.rst 24 Oct 2005 23:11:46 -0000 1.25.2.11 +++ docs.rst 26 Oct 2005 09:44:23 -0000 1.25.2.12 @@ -36,6 +36,7 @@ .. contents:: :depth: 2 + :backlinks: none .. section-numbering:: Introduction @@ -990,6 +991,8 @@ ``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 ====== @@ -2113,8 +2116,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*); @@ -2283,8 +2286,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:: @@ -2349,7 +2352,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? @@ -2407,7 +2411,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 |
From: Arvid N. <ar...@us...> - 2005-10-25 22:57:55
|
Update of /cvsroot/luabind/luabind/luabind/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14830/src Modified Files: Tag: beta7-devel2 class_rep.cpp find_best_match.cpp Log Message: fixed bug in the const-pointer and const-reference matchers returning perfect matches for some non-matches Index: find_best_match.cpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/src/find_best_match.cpp,v retrieving revision 1.9 retrieving revision 1.9.2.1 diff -u -d -r1.9 -r1.9.2.1 --- find_best_match.cpp 7 Aug 2004 13:37:11 -0000 1.9 +++ find_best_match.cpp 25 Oct 2005 22:57:47 -0000 1.9.2.1 @@ -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 Index: class_rep.cpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/src/class_rep.cpp,v retrieving revision 1.49.2.2 retrieving revision 1.49.2.3 diff -u -d -r1.49.2.2 -r1.49.2.3 --- class_rep.cpp 29 Jul 2005 14:45:54 -0000 1.49.2.2 +++ class_rep.cpp 25 Oct 2005 22:57:47 -0000 1.49.2.3 @@ -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()); } |
From: Arvid N. <ar...@us...> - 2005-10-25 22:57:55
|
Update of /cvsroot/luabind/luabind/luabind/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14830/test Modified Files: Tag: beta7-devel2 test_operators.cpp Log Message: fixed bug in the const-pointer and const-reference matchers returning perfect matches for some non-matches Index: test_operators.cpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/test/test_operators.cpp,v retrieving revision 1.15 retrieving revision 1.15.2.1 diff -u -d -r1.15 -r1.15.2.1 --- test_operators.cpp 15 Apr 2005 13:46:17 -0000 1.15 +++ test_operators.cpp 25 Oct 2005 22:57:47 -0000 1.15.2.1 @@ -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)"); |
From: Arvid N. <ar...@us...> - 2005-10-25 22:57:54
|
Update of /cvsroot/luabind/luabind/luabind/luabind/detail In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14830/luabind/detail Modified Files: Tag: beta7-devel2 find_best_match.hpp policy.hpp Log Message: fixed bug in the const-pointer and const-reference matchers returning perfect matches for some non-matches 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.5.4.1 diff -u -d -r1.5 -r1.5.4.1 --- find_best_match.hpp 14 Jun 2003 21:05:02 -0000 1.5 +++ find_best_match.hpp 25 Oct 2005 22:57:47 -0000 1.5.4.1 @@ -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: policy.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/detail/policy.hpp,v retrieving revision 1.50.2.8 retrieving revision 1.50.2.9 diff -u -d -r1.50.2.8 -r1.50.2.9 --- policy.hpp 24 Oct 2005 09:44:00 -0000 1.50.2.8 +++ policy.hpp 25 Oct 2005 22:57:47 -0000 1.50.2.9 @@ -769,7 +769,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> @@ -960,7 +961,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() |
From: Arvid N. <ar...@us...> - 2005-10-25 22:57:54
|
Update of /cvsroot/luabind/luabind/luabind/doc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14830/doc Modified Files: Tag: beta7-devel2 changes.txt Log Message: fixed bug in the const-pointer and const-reference matchers returning perfect matches for some non-matches Index: changes.txt =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/doc/Attic/changes.txt,v retrieving revision 1.1.2.3 retrieving revision 1.1.2.4 diff -u -d -r1.1.2.3 -r1.1.2.4 --- changes.txt 24 Oct 2005 09:44:00 -0000 1.1.2.3 +++ changes.txt 25 Oct 2005 22:57:47 -0000 1.1.2.4 @@ -126,6 +126,8 @@ 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. |
From: Arvid N. <ar...@us...> - 2005-10-24 23:11:56
|
Update of /cvsroot/luabind/luabind/luabind/doc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11169/doc Modified Files: Tag: beta7-devel2 docs.html docs.rst Log Message: added more documentation regarding overloaded member functions Index: docs.html =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/doc/docs.html,v retrieving revision 1.52.2.8 retrieving revision 1.52.2.9 diff -u -d -r1.52.2.8 -r1.52.2.9 --- docs.html 24 Oct 2005 22:24:54 -0000 1.52.2.8 +++ docs.html 24 Oct 2005 23:11:46 -0000 1.52.2.9 @@ -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-22" /> +<meta name="date" content="2005-10-24" /> <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-22</td></tr> +<td>2005-10-24</td></tr> <tr><th class="docinfo-name">Revision:</th> -<td>1.25.2.9</td></tr> +<td>1.25.2.10</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 @@ -69,51 +69,52 @@ </ul> </li> <li><a class="reference" href="#binding-classes-to-lua" id="id56" name="id56">8 Binding classes to Lua</a><ul class="auto-toc"> -<li><a class="reference" href="#properties" id="id57" name="id57">8.1 Properties</a></li> -<li><a class="reference" href="#enums" id="id58" name="id58">8.2 Enums</a></li> -<li><a class="reference" href="#operators" id="id59" name="id59">8.3 Operators</a></li> -<li><a class="reference" href="#nested-scopes-and-static-functions" id="id60" name="id60">8.4 Nested scopes and static functions</a></li> -<li><a class="reference" href="#derived-classes" id="id61" name="id61">8.5 Derived classes</a></li> -<li><a class="reference" href="#smart-pointers" id="id62" name="id62">8.6 Smart pointers</a></li> -<li><a class="reference" href="#splitting-class-registrations" id="id63" name="id63">8.7 Splitting class registrations</a></li> +<li><a class="reference" href="#overloaded-member-functions" id="id57" name="id57">8.1 Overloaded member functions</a></li> +<li><a class="reference" href="#properties" id="id58" name="id58">8.2 Properties</a></li> +<li><a class="reference" href="#enums" id="id59" name="id59">8.3 Enums</a></li> +<li><a class="reference" href="#operators" id="id60" name="id60">8.4 Operators</a></li> +<li><a class="reference" href="#nested-scopes-and-static-functions" id="id61" name="id61">8.5 Nested scopes and static functions</a></li> +<li><a class="reference" href="#derived-classes" id="id62" name="id62">8.6 Derived classes</a></li> +<li><a class="reference" href="#smart-pointers" id="id63" name="id63">8.7 Smart pointers</a></li> +<li><a class="reference" href="#splitting-class-registrations" id="id64" name="id64">8.8 Splitting class registrations</a></li> </ul> </li> -<li><a class="reference" href="#object" id="id64" name="id64">9 Object</a><ul class="auto-toc"> -<li><a class="reference" href="#iterators" id="id65" name="id65">9.1 Iterators</a></li> -<li><a class="reference" href="#related-functions" id="id66" name="id66">9.2 Related functions</a></li> +<li><a class="reference" href="#object" id="id65" name="id65">9 Object</a><ul class="auto-toc"> +<li><a class="reference" href="#iterators" id="id66" name="id66">9.1 Iterators</a></li> +<li><a class="reference" href="#related-functions" id="id67" name="id67">9.2 Related functions</a></li> </ul> </li> -<li><a class="reference" href="#defining-classes-in-lua" id="id67" name="id67">10 Defining classes in Lua</a><ul class="auto-toc"> -<li><a class="reference" href="#deriving-in-lua" id="id68" name="id68">10.1 Deriving in lua</a></li> -<li><a class="reference" href="#overloading-operators" id="id69" name="id69">10.2 Overloading operators</a></li> -<li><a class="reference" href="#finalizers" id="id70" name="id70">10.3 Finalizers</a></li> -<li><a class="reference" href="#slicing" id="id71" name="id71">10.4 Slicing</a></li> +<li><a class="reference" href="#defining-classes-in-lua" id="id68" name="id68">10 Defining classes in Lua</a><ul class="auto-toc"> +<li><a class="reference" href="#deriving-in-lua" id="id69" name="id69">10.1 Deriving in lua</a></li> +<li><a class="reference" href="#overloading-operators" id="id70" name="id70">10.2 Overloading operators</a></li> +<li><a class="reference" href="#finalizers" id="id71" name="id71">10.3 Finalizers</a></li> +<li><a class="reference" href="#slicing" id="id72" name="id72">10.4 Slicing</a></li> </ul> </li> -<li><a class="reference" href="#exceptions" id="id72" name="id72">11 Exceptions</a></li> -<li><a class="reference" href="#policies" id="id73" name="id73">12 Policies</a><ul class="auto-toc"> -<li><a class="reference" href="#adopt" id="id74" name="id74">12.1 adopt</a></li> -<li><a class="reference" href="#dependency" id="id75" name="id75">12.2 dependency</a></li> -<li><a class="reference" href="#out-value" id="id76" name="id76">12.3 out_value</a></li> -<li><a class="reference" href="#pure-out-value" id="id77" name="id77">12.4 pure_out_value</a></li> -<li><a class="reference" href="#return-reference-to" id="id78" name="id78">12.5 return_reference_to</a></li> -<li><a class="reference" href="#copy" id="id79" name="id79">12.6 copy</a></li> -<li><a class="reference" href="#discard-result" id="id80" name="id80">12.7 discard_result</a></li> -<li><a class="reference" href="#return-stl-iterator" id="id81" name="id81">12.8 return_stl_iterator</a></li> -<li><a class="reference" href="#raw" id="id82" name="id82">12.9 raw</a></li> -<li><a class="reference" href="#yield" id="id83" name="id83">12.10 yield</a></li> +<li><a class="reference" href="#exceptions" id="id73" name="id73">11 Exceptions</a></li> +<li><a class="reference" href="#policies" id="id74" name="id74">12 Policies</a><ul class="auto-toc"> +<li><a class="reference" href="#adopt" id="id75" name="id75">12.1 adopt</a></li> +<li><a class="reference" href="#dependency" id="id76" name="id76">12.2 dependency</a></li> +<li><a class="reference" href="#out-value" id="id77" name="id77">12.3 out_value</a></li> +<li><a class="reference" href="#pure-out-value" id="id78" name="id78">12.4 pure_out_value</a></li> +<li><a class="reference" href="#return-reference-to" id="id79" name="id79">12.5 return_reference_to</a></li> +<li><a class="reference" href="#copy" id="id80" name="id80">12.6 copy</a></li> +<li><a class="reference" href="#discard-result" id="id81" name="id81">12.7 discard_result</a></li> +<li><a class="reference" href="#return-stl-iterator" id="id82" name="id82">12.8 return_stl_iterator</a></li> +<li><a class="reference" href="#raw" id="id83" name="id83">12.9 raw</a></li> +<li><a class="reference" href="#yield" id="id84" name="id84">12.10 yield</a></li> </ul> </li> -<li><a class="reference" href="#splitting-up-the-registration" id="id84" name="id84">13 Splitting up the registration</a></li> -<li><a class="reference" href="#configuration" id="id85" name="id85">14 Configuration</a><ul class="auto-toc"> -<li><a class="reference" href="#build-options" id="id86" name="id86">14.1 Build options</a></li> +<li><a class="reference" href="#splitting-up-the-registration" id="id85" name="id85">13 Splitting up the registration</a></li> +<li><a class="reference" href="#configuration" id="id86" name="id86">14 Configuration</a><ul class="auto-toc"> +<li><a class="reference" href="#build-options" id="id87" name="id87">14.1 Build options</a></li> </ul> </li> -<li><a class="reference" href="#implementation-notes" id="id87" name="id87">15 Implementation notes</a></li> -<li><a class="reference" href="#error-messages" id="id88" name="id88">16 Error messages</a></li> -<li><a class="reference" href="#faq" id="id89" name="id89">17 FAQ</a></li> -<li><a class="reference" href="#known-issues" id="id90" name="id90">18 Known issues</a></li> -<li><a class="reference" href="#acknowledgments" id="id91" name="id91">19 Acknowledgments</a></li> +<li><a class="reference" href="#implementation-notes" id="id88" name="id88">15 Implementation notes</a></li> +<li><a class="reference" href="#error-messages" id="id89" name="id89">16 Error messages</a></li> +<li><a class="reference" href="#faq" id="id90" name="id90">17 FAQ</a></li> +<li><a class="reference" href="#known-issues" id="id91" name="id91">18 Known issues</a></li> +<li><a class="reference" href="#acknowledgments" id="id92" name="id92">19 Acknowledgments</a></li> </ul> </div> <div class="section" id="introduction"> @@ -174,6 +175,8 @@ <li>GCC 3.1 (SunOS 5.8)</li> <li>GCC 3.2 (cygwin)</li> <li>GCC 3.3.1 (cygwin)</li> +<li>GCC 3.3 (Apple, MacOS X)</li> +<li>GCC 4.0 (Apple, MacOS X)</li> </ul> </blockquote> <p>It has been confirmed not to work with:</p> @@ -193,8 +196,8 @@ <p>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 <a class="reference" href="http://www.boost.org">Boost</a> 1.32.0 to be installed (only -boost headers). It also requires that Lua is installed.</p> +your compiler's include path. It requires <a class="reference" href="http://www.boost.org">Boost</a> 1.32.0 or 1.33.0 to be +installed (only boost headers). It also requires that Lua is installed.</p> <p>The official way of building luabind is with <a class="reference" href="http://www.boost.org/tools/build/v2/index_v2.html">Boost.Build V2</a>. To properly build luabind with Boost.Build you need to set two environment variables:</p> <dl class="docutils"> @@ -206,7 +209,7 @@ <tt class="docutils literal"><span class="pre">$(LUA_PATH)/lib/.</span></tt></dd> </dl> <p>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.</p> @@ -568,8 +571,35 @@ <p><tt class="docutils literal"><span class="pre">plus()</span></tt> can now be called as a member function on A with one parameter, int. If the object pointer parameter is const, the function will act as if it was a const member function (it can be called on const objects).</p> +<div class="section" id="overloaded-member-functions"> +<h2><a name="overloaded-member-functions">8.1 Overloaded member functions</a></h2> +<p>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 <tt class="docutils literal"><span class="pre">def</span></tt>. 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++).</p> +<p>The syntax for member function pointer follows:</p> +<pre class="literal-block"> +<em>return-value</em> (<em>class-name</em>::*)(<em>arg1-type</em>, <em>arg2-type</em>, <em>...</em>) +</pre> +<p>Here's an example illlustrating this:</p> +<pre class="literal-block"> +struct A +{ + void f(int); + void f(int, int); +}; +</pre> +<pre class="literal-block"> +class_<A>() + .def("f", (void(A::*)(int))&A::f) +</pre> +<p>This selects the first overload of the function <tt class="docutils literal"><span class="pre">f</span></tt> to bind. The second +overload is not bound.</p> +</div> <div class="section" id="properties"> -<h2><a name="properties">8.1 Properties</a></h2> +<h2><a name="properties">8.2 Properties</a></h2> <p>To register a global data member with a class is easily done. Consider the following class:</p> <pre class="literal-block"> @@ -634,7 +664,7 @@ const</strong>, otherwise it won't compile. This seems to be a common source of errors.</p> </div> <div class="section" id="enums"> -<h2><a name="enums">8.2 Enums</a></h2> +<h2><a name="enums">8.3 Enums</a></h2> <p>If your class contains enumerated constants (enums), you can register them as well to make them available in Lua. Note that they will not be type safe, all enums are integers in Lua, and all functions that takes an enum, will accept @@ -662,7 +692,7 @@ </pre> </div> <div class="section" id="operators"> -<h2><a name="operators">8.3 Operators</a></h2> +<h2><a name="operators">8.4 Operators</a></h2> <p>To bind operators you have to include <tt class="docutils literal"><span class="pre"><luabind/operator.hpp></span></tt>.</p> <p>The mechanism for registering operators on your class is pretty simple. You use a global name <tt class="docutils literal"><span class="pre">luabind::self</span></tt> to refer to the class itself and then you just @@ -751,7 +781,7 @@ </pre> </div> <div class="section" id="nested-scopes-and-static-functions"> -<h2><a name="nested-scopes-and-static-functions">8.4 Nested scopes and static functions</a></h2> +<h2><a name="nested-scopes-and-static-functions">8.5 Nested scopes and static functions</a></h2> <p>It is possible to add nested scopes to a class. This is useful when you need to wrap a nested class, or a static function.</p> <pre class="literal-block"> @@ -763,10 +793,12 @@ def("f", &f) ]</strong>; </pre> +<p>In this example, <tt class="docutils literal"><span class="pre">f</span></tt> will behave like a static member function of the class +<tt class="docutils literal"><span class="pre">foo</span></tt>, and the class <tt class="docutils literal"><span class="pre">nested</span></tt> will behave like a nested class of <tt class="docutils literal"><span class="pre">foo</span></tt>.</p> <p>It's also possible to add namespace's to classes using the same syntax.</p> </div> <div class="section" id="derived-classes"> -<h2><a name="derived-classes">8.5 Derived classes</a></h2> +<h2><a name="derived-classes">8.6 Derived classes</a></h2> <p>If you want to register classes that derives from other classes, you can specify a template parameter <tt class="docutils literal"><span class="pre">bases<></span></tt> to the <tt class="docutils literal"><span class="pre">class_</span></tt> instantiation. The following hierarchy:</p> @@ -798,7 +830,7 @@ </div> </div> <div class="section" id="smart-pointers"> -<h2><a name="smart-pointers">8.6 Smart pointers</a></h2> +<h2><a name="smart-pointers">8.7 Smart pointers</a></h2> <p>When you register a class you can tell luabind that all instances of that class should be held by some kind of smart pointer (boost::shared_ptr for instance). You do this by giving the holder type as an extra template parameter to @@ -949,7 +981,7 @@ are first extracted from the holder type.</p> </div> <div class="section" id="splitting-class-registrations"> -<h2><a name="splitting-class-registrations">8.7 Splitting class registrations</a></h2> +<h2><a name="splitting-class-registrations">8.8 Splitting class registrations</a></h2> <p>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 @@ -1621,16 +1653,16 @@ <div class="contents topic" id="policies-currently-implemented"> <p class="topic-title first"><a name="policies-currently-implemented">Policies currently implemented</a></p> <ul class="auto-toc simple"> -<li><a class="reference" href="#adopt" id="id92" name="id92">12.1 adopt</a></li> -<li><a class="reference" href="#dependency" id="id93" name="id93">12.2 dependency</a></li> -<li><a class="reference" href="#out-value" id="id94" name="id94">12.3 out_value</a></li> -<li><a class="reference" href="#pure-out-value" id="id95" name="id95">12.4 pure_out_value</a></li> -<li><a class="reference" href="#return-reference-to" id="id96" name="id96">12.5 return_reference_to</a></li> -<li><a class="reference" href="#copy" id="id97" name="id97">12.6 copy</a></li> -<li><a class="reference" href="#discard-result" id="id98" name="id98">12.7 discard_result</a></li> -<li><a class="reference" href="#return-stl-iterator" id="id99" name="id99">12.8 return_stl_iterator</a></li> -<li><a class="reference" href="#raw" id="id100" name="id100">12.9 raw</a></li> -<li><a class="reference" href="#yield" id="id101" name="id101">12.10 yield</a></li> +<li><a class="reference" href="#adopt" id="id93" name="id93">12.1 adopt</a></li> +<li><a class="reference" href="#dependency" id="id94" name="id94">12.2 dependency</a></li> +<li><a class="reference" href="#out-value" id="id95" name="id95">12.3 out_value</a></li> +<li><a class="reference" href="#pure-out-value" id="id96" name="id96">12.4 pure_out_value</a></li> +<li><a class="reference" href="#return-reference-to" id="id97" name="id97">12.5 return_reference_to</a></li> +<li><a class="reference" href="#copy" id="id98" name="id98">12.6 copy</a></li> +<li><a class="reference" href="#discard-result" id="id99" name="id99">12.7 discard_result</a></li> +<li><a class="reference" href="#return-stl-iterator" id="id100" name="id100">12.8 return_stl_iterator</a></li> +<li><a class="reference" href="#raw" id="id101" name="id101">12.9 raw</a></li> +<li><a class="reference" href="#yield" id="id102" name="id102">12.10 yield</a></li> </ul> </div> <div class="section" id="adopt"> Index: docs.rst =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/doc/docs.rst,v retrieving revision 1.25.2.10 retrieving revision 1.25.2.11 diff -u -d -r1.25.2.10 -r1.25.2.11 --- docs.rst 24 Oct 2005 22:24:54 -0000 1.25.2.10 +++ docs.rst 24 Oct 2005 23:11:46 -0000 1.25.2.11 @@ -102,7 +102,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: @@ -122,8 +124,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.32.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: @@ -137,7 +139,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. @@ -544,6 +546,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 ---------- @@ -769,6 +804,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. |
From: Arvid N. <ar...@us...> - 2005-10-24 22:25:03
|
Update of /cvsroot/luabind/luabind/luabind/doc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1243/doc Modified Files: Tag: beta7-devel2 docs.html docs.rst Log Message: updated the documentation and added another test for the new property code Index: docs.html =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/doc/docs.html,v retrieving revision 1.52.2.7 retrieving revision 1.52.2.8 diff -u -d -r1.52.2.7 -r1.52.2.8 --- docs.html 3 Aug 2005 14:41:14 -0000 1.52.2.7 +++ docs.html 24 Oct 2005 22:24:54 -0000 1.52.2.8 @@ -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-07-29" /> +<meta name="date" content="2005-10-22" /> <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-07-29</td></tr> +<td>2005-10-22</td></tr> <tr><th class="docinfo-name">Revision:</th> -<td>1.25.2.7</td></tr> +<td>1.25.2.9</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 @@ -75,44 +75,45 @@ <li><a class="reference" href="#nested-scopes-and-static-functions" id="id60" name="id60">8.4 Nested scopes and static functions</a></li> <li><a class="reference" href="#derived-classes" id="id61" name="id61">8.5 Derived classes</a></li> <li><a class="reference" href="#smart-pointers" id="id62" name="id62">8.6 Smart pointers</a></li> +<li><a class="reference" href="#splitting-class-registrations" id="id63" name="id63">8.7 Splitting class registrations</a></li> </ul> </li> -<li><a class="reference" href="#object" id="id63" name="id63">9 Object</a><ul class="auto-toc"> -<li><a class="reference" href="#iterators" id="id64" name="id64">9.1 Iterators</a></li> -<li><a class="reference" href="#related-functions" id="id65" name="id65">9.2 Related functions</a></li> +<li><a class="reference" href="#object" id="id64" name="id64">9 Object</a><ul class="auto-toc"> +<li><a class="reference" href="#iterators" id="id65" name="id65">9.1 Iterators</a></li> +<li><a class="reference" href="#related-functions" id="id66" name="id66">9.2 Related functions</a></li> </ul> </li> -<li><a class="reference" href="#defining-classes-in-lua" id="id66" name="id66">10 Defining classes in Lua</a><ul class="auto-toc"> -<li><a class="reference" href="#deriving-in-lua" id="id67" name="id67">10.1 Deriving in lua</a></li> -<li><a class="reference" href="#overloading-operators" id="id68" name="id68">10.2 Overloading operators</a></li> -<li><a class="reference" href="#finalizers" id="id69" name="id69">10.3 Finalizers</a></li> -<li><a class="reference" href="#slicing" id="id70" name="id70">10.4 Slicing</a></li> +<li><a class="reference" href="#defining-classes-in-lua" id="id67" name="id67">10 Defining classes in Lua</a><ul class="auto-toc"> +<li><a class="reference" href="#deriving-in-lua" id="id68" name="id68">10.1 Deriving in lua</a></li> +<li><a class="reference" href="#overloading-operators" id="id69" name="id69">10.2 Overloading operators</a></li> +<li><a class="reference" href="#finalizers" id="id70" name="id70">10.3 Finalizers</a></li> +<li><a class="reference" href="#slicing" id="id71" name="id71">10.4 Slicing</a></li> </ul> </li> -<li><a class="reference" href="#exceptions" id="id71" name="id71">11 Exceptions</a></li> -<li><a class="reference" href="#policies" id="id72" name="id72">12 Policies</a><ul class="auto-toc"> -<li><a class="reference" href="#adopt" id="id73" name="id73">12.1 adopt</a></li> -<li><a class="reference" href="#dependency" id="id74" name="id74">12.2 dependency</a></li> -<li><a class="reference" href="#out-value" id="id75" name="id75">12.3 out_value</a></li> -<li><a class="reference" href="#pure-out-value" id="id76" name="id76">12.4 pure_out_value</a></li> -<li><a class="reference" href="#return-reference-to" id="id77" name="id77">12.5 return_reference_to</a></li> -<li><a class="reference" href="#copy" id="id78" name="id78">12.6 copy</a></li> -<li><a class="reference" href="#discard-result" id="id79" name="id79">12.7 discard_result</a></li> -<li><a class="reference" href="#return-stl-iterator" id="id80" name="id80">12.8 return_stl_iterator</a></li> -<li><a class="reference" href="#raw" id="id81" name="id81">12.9 raw</a></li> -<li><a class="reference" href="#yield" id="id82" name="id82">12.10 yield</a></li> +<li><a class="reference" href="#exceptions" id="id72" name="id72">11 Exceptions</a></li> +<li><a class="reference" href="#policies" id="id73" name="id73">12 Policies</a><ul class="auto-toc"> +<li><a class="reference" href="#adopt" id="id74" name="id74">12.1 adopt</a></li> +<li><a class="reference" href="#dependency" id="id75" name="id75">12.2 dependency</a></li> +<li><a class="reference" href="#out-value" id="id76" name="id76">12.3 out_value</a></li> +<li><a class="reference" href="#pure-out-value" id="id77" name="id77">12.4 pure_out_value</a></li> +<li><a class="reference" href="#return-reference-to" id="id78" name="id78">12.5 return_reference_to</a></li> +<li><a class="reference" href="#copy" id="id79" name="id79">12.6 copy</a></li> +<li><a class="reference" href="#discard-result" id="id80" name="id80">12.7 discard_result</a></li> +<li><a class="reference" href="#return-stl-iterator" id="id81" name="id81">12.8 return_stl_iterator</a></li> +<li><a class="reference" href="#raw" id="id82" name="id82">12.9 raw</a></li> +<li><a class="reference" href="#yield" id="id83" name="id83">12.10 yield</a></li> </ul> </li> -<li><a class="reference" href="#splitting-up-the-registration" id="id83" name="id83">13 Splitting up the registration</a></li> -<li><a class="reference" href="#configuration" id="id84" name="id84">14 Configuration</a><ul class="auto-toc"> -<li><a class="reference" href="#build-options" id="id85" name="id85">14.1 Build options</a></li> +<li><a class="reference" href="#splitting-up-the-registration" id="id84" name="id84">13 Splitting up the registration</a></li> +<li><a class="reference" href="#configuration" id="id85" name="id85">14 Configuration</a><ul class="auto-toc"> +<li><a class="reference" href="#build-options" id="id86" name="id86">14.1 Build options</a></li> </ul> </li> -<li><a class="reference" href="#implementation-notes" id="id86" name="id86">15 Implementation notes</a></li> -<li><a class="reference" href="#error-messages" id="id87" name="id87">16 Error messages</a></li> -<li><a class="reference" href="#faq" id="id88" name="id88">17 FAQ</a></li> -<li><a class="reference" href="#known-issues" id="id89" name="id89">18 Known issues</a></li> -<li><a class="reference" href="#acknowledgments" id="id90" name="id90">19 Acknowledgments</a></li> +<li><a class="reference" href="#implementation-notes" id="id87" name="id87">15 Implementation notes</a></li> +<li><a class="reference" href="#error-messages" id="id88" name="id88">16 Error messages</a></li> +<li><a class="reference" href="#faq" id="id89" name="id89">17 FAQ</a></li> +<li><a class="reference" href="#known-issues" id="id90" name="id90">18 Known issues</a></li> +<li><a class="reference" href="#acknowledgments" id="id91" name="id91">19 Acknowledgments</a></li> </ul> </div> <div class="section" id="introduction"> @@ -591,9 +592,24 @@ module(L) [ class_<A>("A") - .def_readonly("a", &A::a) + .def_readonly("a", &A::a) ]; </pre> +<p>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:</p> +<pre class="literal-block"> +struct A { int m; }; +struct B { A a; }; +</pre> +<p>When binding <tt class="docutils literal"><span class="pre">B</span></tt> to lua, the following expression code should work:</p> +<pre class="literal-block"> +b = B() +b.a.m = 1 +assert(b.a.m == 1) +</pre> +<p>This requires the first lookup (on <tt class="docutils literal"><span class="pre">a</span></tt>) to return a reference to <tt class="docutils literal"><span class="pre">A</span></tt>, and +not a copy.</p> <p>You can also register getter and setter functions and make them look as if they were a public data member. Consider the following class:</p> <pre class="literal-block"> @@ -647,6 +663,7 @@ </div> <div class="section" id="operators"> <h2><a name="operators">8.3 Operators</a></h2> +<p>To bind operators you have to include <tt class="docutils literal"><span class="pre"><luabind/operator.hpp></span></tt>.</p> <p>The mechanism for registering operators on your class is pretty simple. You use a global name <tt class="docutils literal"><span class="pre">luabind::self</span></tt> to refer to the class itself and then you just write the operator expression inside the <tt class="docutils literal"><span class="pre">def()</span></tt> call. This class:</p> @@ -666,7 +683,7 @@ </pre> <p>This will work regardless if your plus operator is defined inside your class or as a free function.</p> -<p>If you operator is const (or, when defined as a free function, takes a const +<p>If your operator is const (or, when defined as a free function, takes a const reference to the class itself) you have to use <tt class="docutils literal"><span class="pre">const_self</span></tt> instead of <tt class="docutils literal"><span class="pre">self</span></tt>. Like this:</p> <pre class="literal-block"> @@ -678,11 +695,15 @@ </pre> <p>The operators supported are those available in Lua:</p> <pre class="literal-block"> -+ - * / == != < <= > >= ++ - * / == < <= </pre> <p>This means, no in-place operators. The equality operator (<tt class="docutils literal"><span class="pre">==</span></tt>) has a little hitch; it will not be called if the references are equal. This means that the <tt class="docutils literal"><span class="pre">==</span></tt> operator has to do pretty much what's it's expected to do.</p> +<p>Lua does not support operators such as <tt class="docutils literal"><span class="pre">!=</span></tt>, <tt class="docutils literal"><span class="pre">></span></tt> or <tt class="docutils literal"><span class="pre">>=</span></tt>. 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.</p> <p>In the above example the other operand type is instantiated by writing <tt class="docutils literal"><span class="pre">int()</span></tt>. If the operand type is a complex type that cannot easily be instantiated you can wrap the type in a class called <tt class="docutils literal"><span class="pre">other<></span></tt>. For example:</p> @@ -702,7 +723,7 @@ .def(self + <strong>other<std::string>()</strong>) ]; </pre> -<p>To register an application operator:</p> +<p>To register an application (function call-) operator:</p> <pre class="literal-block"> module(L) [ @@ -800,7 +821,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(); } @@ -927,13 +948,44 @@ <p>Internally, luabind will do the necessary conversions on the raw pointers, which are first extracted from the holder type.</p> </div> +<div class="section" id="splitting-class-registrations"> +<h2><a name="splitting-class-registrations">8.7 Splitting class registrations</a></h2> +<p>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:</p> +<pre class="literal-block"> +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 ]; +} +</pre> +<p>Here, the class <tt class="docutils literal"><span class="pre">X</span></tt> is registered in two steps. The two functions +<tt class="docutils literal"><span class="pre">register_part1</span></tt> and <tt class="docutils literal"><span class="pre">register_part2</span></tt> may be put in separate compilation +units.</p> +</div> </div> <div class="section" id="object"> <h1><a name="object">9 Object</a></h1> <p>Since functions have to be able to take Lua values (of variable type) we need a wrapper around them. This wrapper is called <tt class="docutils literal"><span class="pre">luabind::object</span></tt>. If the function you register takes an object, it will match any Lua value. To use it, -you need to include <tt class="docutils literal"><span class="pre">luabind/object.hpp</span></tt>.</p> +you need to include <tt class="docutils literal"><span class="pre"><luabind/object.hpp></span></tt>.</p> <div class="topic"> <p class="topic-title first">Synopsis</p> <pre class="literal-block"> @@ -960,9 +1012,6 @@ object& operator=(T const&); object& operator=(object const&); - <strong>COMPARISONS ARE NOT IMPLEMENTED YET</strong> - template<class T> - bool operator==(T const&) const; bool operator==(object const&) const; bool operator<(object const&) const; bool operator<=(object const&) const; @@ -970,6 +1019,9 @@ bool operator>=(object const&) const; bool operator!=(object const&) const; + template <class T> + <em>implementation-defined</em> operator[](T const& key) const + void swap(object&); <em>implementation-defined</em> operator()(); @@ -1061,7 +1113,7 @@ release its Lua object in its destructor.</p> <p>Here's an example of how a function can use a table:</p> <pre class="literal-block"> -void my_function(const object& table) +void my_function(object const& table) { if (table.type() == LUA_TTABLE) { @@ -1569,16 +1621,16 @@ <div class="contents topic" id="policies-currently-implemented"> <p class="topic-title first"><a name="policies-currently-implemented">Policies currently implemented</a></p> <ul class="auto-toc simple"> -<li><a class="reference" href="#adopt" id="id91" name="id91">12.1 adopt</a></li> -<li><a class="reference" href="#dependency" id="id92" name="id92">12.2 dependency</a></li> -<li><a class="reference" href="#out-value" id="id93" name="id93">12.3 out_value</a></li> -<li><a class="reference" href="#pure-out-value" id="id94" name="id94">12.4 pure_out_value</a></li> -<li><a class="reference" href="#return-reference-to" id="id95" name="id95">12.5 return_reference_to</a></li> -<li><a class="reference" href="#copy" id="id96" name="id96">12.6 copy</a></li> -<li><a class="reference" href="#discard-result" id="id97" name="id97">12.7 discard_result</a></li> -<li><a class="reference" href="#return-stl-iterator" id="id98" name="id98">12.8 return_stl_iterator</a></li> -<li><a class="reference" href="#raw" id="id99" name="id99">12.9 raw</a></li> -<li><a class="reference" href="#yield" id="id100" name="id100">12.10 yield</a></li> +<li><a class="reference" href="#adopt" id="id92" name="id92">12.1 adopt</a></li> +<li><a class="reference" href="#dependency" id="id93" name="id93">12.2 dependency</a></li> +<li><a class="reference" href="#out-value" id="id94" name="id94">12.3 out_value</a></li> +<li><a class="reference" href="#pure-out-value" id="id95" name="id95">12.4 pure_out_value</a></li> +<li><a class="reference" href="#return-reference-to" id="id96" name="id96">12.5 return_reference_to</a></li> +<li><a class="reference" href="#copy" id="id97" name="id97">12.6 copy</a></li> +<li><a class="reference" href="#discard-result" id="id98" name="id98">12.7 discard_result</a></li> +<li><a class="reference" href="#return-stl-iterator" id="id99" name="id99">12.8 return_stl_iterator</a></li> +<li><a class="reference" href="#raw" id="id100" name="id100">12.9 raw</a></li> +<li><a class="reference" href="#yield" id="id101" name="id101">12.10 yield</a></li> </ul> </div> <div class="section" id="adopt"> Index: docs.rst =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/doc/docs.rst,v retrieving revision 1.25.2.9 retrieving revision 1.25.2.10 diff -u -d -r1.25.2.9 -r1.25.2.10 --- docs.rst 22 Oct 2005 10:42:33 -0000 1.25.2.9 +++ docs.rst 24 Oct 2005 22:24:54 -0000 1.25.2.10 @@ -569,9 +569,25 @@ 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. + You can also register getter and setter functions and make them look as if they were a public data member. Consider the following class:: @@ -630,6 +646,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:: @@ -652,7 +670,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: @@ -668,12 +686,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: @@ -698,7 +721,7 @@ .def(self + **other<std::string>()**) ]; -To register an application operator: +To register an application (function call-) operator: .. parsed-literal:: @@ -897,13 +920,46 @@ 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. + + 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 @@ -932,9 +988,6 @@ object& operator=(T const&); object& operator=(object const&); - **COMPARISONS ARE NOT IMPLEMENTED YET** - template<class T> - bool operator==(T const&) const; bool operator==(object const&) const; bool operator<(object const&) const; bool operator<=(object const&) const; @@ -942,6 +995,9 @@ bool operator>=(object const&) const; bool operator!=(object const&) const; + template <class T> + *implementation-defined* operator[](T const& key) const + void swap(object&); *implementation-defined* operator()(); @@ -1040,7 +1096,7 @@ 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) { |
From: Arvid N. <ar...@us...> - 2005-10-24 22:25:02
|
Update of /cvsroot/luabind/luabind/luabind/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1243/test Modified Files: Tag: beta7-devel2 test_attributes.cpp Log Message: updated the documentation and added another test for the new property code Index: test_attributes.cpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/test/test_attributes.cpp,v retrieving revision 1.31.2.3 retrieving revision 1.31.2.4 diff -u -d -r1.31.2.3 -r1.31.2.4 --- test_attributes.cpp 24 Oct 2005 09:44:00 -0000 1.31.2.3 +++ test_attributes.cpp 24 Oct 2005 22:24:54 -0000 1.31.2.4 @@ -42,13 +42,14 @@ struct property_test : counted_type<property_test> { - property_test(): o(6) {} + property_test(): o(6), c_ref(&c) {} std::string str_; int a_; float o; signed char b; C c; + C* c_ref; void set(int a) { a_ = a; } int get() const { return a_; } @@ -84,9 +85,10 @@ .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) + .property("free", &free_getter, &free_setter) .def_readwrite("b", &property_test::b) - .def_readwrite("c", &property_test::c), + .def_readwrite("c", &property_test::c) + .def_readwrite("c_ref", &property_test::c_ref), class_<A>("A") .def(constructor<>()) @@ -134,7 +136,8 @@ "assert(test.b == 3)\n"); DOSTRING(L, "test.c.a = 1\n" - "assert(test.c.a == 1)\n"); + "assert(test.c.a == 1)\n" + "assert(test.c_ref.a == 1)"); DOSTRING(L, "a = B()\n"); |
From: Arvid N. <ar...@us...> - 2005-10-24 09:44:25
|
Update of /cvsroot/luabind/luabind/luabind/doc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29680/doc Modified Files: Tag: beta7-devel2 changes.txt Log Message: def_readwrite and def_readonly will now return references if the bound memeber type is not a primitive type Index: changes.txt =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/doc/Attic/changes.txt,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -u -d -r1.1.2.2 -r1.1.2.3 --- changes.txt 29 Jul 2005 14:45:36 -0000 1.1.2.2 +++ changes.txt 24 Oct 2005 09:44:00 -0000 1.1.2.3 @@ -126,6 +126,9 @@ bugfixes ........ +* 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) |
From: Arvid N. <ar...@us...> - 2005-10-24 09:44:25
|
Update of /cvsroot/luabind/luabind/luabind/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29680/test Modified Files: Tag: beta7-devel2 test_attributes.cpp Log Message: def_readwrite and def_readonly will now return references if the bound memeber type is not a primitive type Index: test_attributes.cpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/test/test_attributes.cpp,v retrieving revision 1.31.2.2 retrieving revision 1.31.2.3 diff -u -d -r1.31.2.2 -r1.31.2.3 --- test_attributes.cpp 4 Sep 2005 20:57:04 -0000 1.31.2.2 +++ test_attributes.cpp 24 Oct 2005 09:44:00 -0000 1.31.2.3 @@ -35,6 +35,11 @@ { }; +struct C +{ + int a; +}; + struct property_test : counted_type<property_test> { property_test(): o(6) {} @@ -43,6 +48,7 @@ int a_; float o; signed char b; + C c; void set(int a) { a_ = a; } int get() const { return a_; } @@ -79,7 +85,8 @@ .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), + .def_readwrite("b", &property_test::b) + .def_readwrite("c", &property_test::c), class_<A>("A") .def(constructor<>()) @@ -87,7 +94,11 @@ 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"); @@ -122,6 +133,9 @@ "test.b = 3\n" "assert(test.b == 3)\n"); + DOSTRING(L, "test.c.a = 1\n" + "assert(test.c.a == 1)\n"); + DOSTRING(L, "a = B()\n"); |
From: Arvid N. <ar...@us...> - 2005-10-24 09:44:25
|
Update of /cvsroot/luabind/luabind/luabind/luabind/detail In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29680/luabind/detail Modified Files: Tag: beta7-devel2 policy.hpp property.hpp Log Message: def_readwrite and def_readonly will now return references if the bound memeber type is not a primitive type Index: property.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/detail/property.hpp,v retrieving revision 1.11 retrieving revision 1.11.2.1 diff -u -d -r1.11 -r1.11.2.1 --- property.hpp 7 Aug 2004 13:37:10 -0000 1.11 +++ property.hpp 24 Oct 2005 09:44:00 -0000 1.11.2.1 @@ -25,6 +25,8 @@ #define LUABIND_PROPERTY_HPP_INCLUDED #include <luabind/config.hpp> +#include <boost/type_traits/add_reference.hpp> +#include <boost/mpl/eval_if.hpp> namespace luabind { namespace detail { @@ -126,7 +128,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 +168,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,7 +203,16 @@ 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; + typedef typename boost::mpl::eval_if< + typename converter1_t::is_value_converter + , make_reference_converter<converter_policy, D> + , converter1_t>::type converter2_t; + + // TODO: If this yields a reference converter, return_internal_reference policy + // should be automatically added + + converter2_t converter; converter.apply(L, ptr->*member); int nret = lua_gettop(L) - nargs; Index: policy.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/detail/policy.hpp,v retrieving revision 1.50.2.7 retrieving revision 1.50.2.8 diff -u -d -r1.50.2.7 -r1.50.2.8 --- policy.hpp 23 Oct 2005 21:37:16 -0000 1.50.2.7 +++ policy.hpp 24 Oct 2005 09:44:00 -0000 1.50.2.8 @@ -262,6 +262,7 @@ template<> struct primitive_converter<cpp_to_lua> { + typedef boost::mpl::bool_<false> is_value_converter; typedef primitive_converter type; void apply(lua_State* L, int v) { lua_pushnumber(L, (lua_Number)v); } @@ -294,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) \ @@ -391,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> @@ -460,6 +463,7 @@ template<> struct pointer_converter<cpp_to_lua> { + typedef boost::mpl::bool_<false> is_value_converter; typedef pointer_converter type; template<class T> @@ -495,6 +499,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?! @@ -560,6 +565,7 @@ template<> struct value_converter<cpp_to_lua> { + typedef boost::mpl::bool_<true> is_value_converter; typedef value_converter type; template<class T> @@ -625,6 +631,7 @@ template<> struct value_converter<lua_to_cpp> { + typedef boost::mpl::bool_<true> is_value_converter; typedef value_converter type; template<class T> @@ -700,6 +707,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> @@ -738,6 +746,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> @@ -777,6 +786,7 @@ template<> struct ref_converter<cpp_to_lua> { + typedef boost::mpl::bool_<false> is_value_converter; typedef ref_converter type; template<class T> @@ -808,6 +818,7 @@ template<> struct ref_converter<lua_to_cpp> { + typedef boost::mpl::bool_<false> is_value_converter; typedef ref_converter type; template<class T> @@ -835,6 +846,7 @@ template<> struct const_ref_converter<cpp_to_lua> { + typedef boost::mpl::bool_<false> is_value_converter; typedef const_ref_converter type; template<class T> @@ -885,6 +897,7 @@ template<> struct const_ref_converter<lua_to_cpp> { + typedef boost::mpl::bool_<false> is_value_converter; typedef const_ref_converter type; // TODO: align! @@ -966,6 +979,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) @@ -977,6 +991,7 @@ template<> struct enum_converter<lua_to_cpp> { + typedef boost::mpl::bool_<false> is_value_converter; typedef enum_converter type; template<class T> @@ -1051,6 +1066,7 @@ template<> struct value_wrapper_converter<lua_to_cpp> { + typedef boost::mpl::bool_<false> is_value_converter; typedef value_wrapper_converter type; template<class T> @@ -1085,6 +1101,7 @@ template<> struct value_wrapper_converter<cpp_to_lua> { + typedef boost::mpl::bool_<false> is_value_converter; typedef value_wrapper_converter type; template<class T> |
From: Arvid N. <ar...@us...> - 2005-10-24 09:44:17
|
Update of /cvsroot/luabind/luabind/luabind/luabind In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29680/luabind Modified Files: Tag: beta7-devel2 adopt_policy.hpp iterator_policy.hpp Log Message: def_readwrite and def_readonly will now return references if the bound memeber type is not a primitive type Index: adopt_policy.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/adopt_policy.hpp,v retrieving revision 1.10.2.1 retrieving revision 1.10.2.2 diff -u -d -r1.10.2.1 -r1.10.2.2 --- adopt_policy.hpp 23 Oct 2005 21:37:16 -0000 1.10.2.1 +++ adopt_policy.hpp 24 Oct 2005 09:44:00 -0000 1.10.2.2 @@ -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 (move_back_reference::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: iterator_policy.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/iterator_policy.hpp,v retrieving revision 1.3 retrieving revision 1.3.4.1 diff -u -d -r1.3 -r1.3.4.1 --- iterator_policy.hpp 5 Jul 2003 22:13:59 -0000 1.3 +++ iterator_policy.hpp 24 Oct 2005 09:44:00 -0000 1.3.4.1 @@ -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) { |
From: Daniel W. <dan...@us...> - 2005-10-24 00:31:50
|
Update of /cvsroot/luabind/luabind/luabind/luabind In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29574/luabind Modified Files: Tag: daniel-refactoring adopt_policy.hpp back_reference.hpp back_reference_fwd.hpp class.hpp object.hpp value_wrapper.hpp Added Files: Tag: daniel-refactoring get_pointer.hpp Log Message: merged_beta7-devel2_into_daniel-refactoring_051024 Index: object.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/object.hpp,v retrieving revision 1.34.2.17 retrieving revision 1.34.2.17.2.1 diff -u -d -r1.34.2.17 -r1.34.2.17.2.1 --- object.hpp 30 Sep 2005 11:28:42 -0000 1.34.2.17 +++ object.hpp 24 Oct 2005 00:31:34 -0000 1.34.2.17.2.1 @@ -52,7 +52,7 @@ { typedef typename boost::mpl::if_< boost::is_reference_wrapper<T> - , typename boost::unwrap_reference<T>::type& + , BOOST_DEDUCED_TYPENAME boost::unwrap_reference<T>::type& , T >::type unwrapped_type; @@ -63,7 +63,9 @@ cv.apply( interpreter - , boost::implicit_cast<typename boost::unwrap_reference<T>::type&>(value) + , boost::implicit_cast< + BOOST_DEDUCED_TYPENAME boost::unwrap_reference<T>::type& + >(value) ); } @@ -410,10 +412,9 @@ handle m_key; }; -#if defined(__GNUC__) || BOOST_WORKAROUND(BOOST_MSVC, == 1300) - // Needed because of GCC's and VC7's strange ADL +// Needed because of some strange ADL issues. -# define LUABIND_OPERATOR_ADL_WKND(op) \ +#define LUABIND_OPERATOR_ADL_WKND(op) \ inline bool operator op( \ basic_iterator<basic_access> const& x \ , basic_iterator<basic_access> const& y) \ @@ -431,10 +432,8 @@ LUABIND_OPERATOR_ADL_WKND(==) LUABIND_OPERATOR_ADL_WKND(!=) -# undef LUABIND_OPERATOR_ADL_WKND - -#endif - +#undef LUABIND_OPERATOR_ADL_WKND + } // namespace detail namespace adl @@ -485,7 +484,6 @@ this_type& operator=(T const& value) { value_wrapper_traits<Next>::unwrap(m_interpreter, m_next); - detail::stack_pop pop(m_interpreter, 1); lua_pushvalue(m_interpreter, m_key_index); @@ -570,22 +568,19 @@ namespace adl { - // An object holds a reference to a Lua value residing - // in the registry. - class object : public object_interface<object> + class object_init { - struct safe_bool_type {}; - public: - object() + protected: + object_init() {} - - explicit object(from_stack const& stack_reference) + + explicit object_init(from_stack const& stack_reference, boost::mpl::true_) : m_handle(stack_reference.interpreter, stack_reference.index) { } template<class ValueWrapper> - explicit object(ValueWrapper const& value_wrapper) + explicit object_init(ValueWrapper const& value_wrapper, boost::mpl::false_) { lua_State* interpreter = value_wrapper_traits<ValueWrapper>::interpreter( value_wrapper @@ -597,6 +592,27 @@ handle(interpreter, -1).swap(m_handle); } + handle m_handle; + }; + + // An object holds a reference to a Lua value residing + // in the registry. + class object : public object_interface<object> + { + struct safe_bool_type {}; + public: + object() + {} + + explicit object(handle const& other) + : m_handle(other) + {} + + explicit object(from_stack const& stack_reference) + : m_handle(stack_reference.interpreter, stack_reference.index) + { + } + template<class T> object(lua_State* interpreter, T const& value) { @@ -723,12 +739,14 @@ , class ValueWrapper , class Policies , class ErrorPolicy + , class ReturnType > - typename ErrorPolicy::type object_cast_aux( + ReturnType object_cast_aux( ValueWrapper const& value_wrapper , T* , Policies* , ErrorPolicy* + , ReturnType* ) { lua_State* interpreter = value_wrapper_traits<ValueWrapper>::interpreter( @@ -767,8 +785,6 @@ template<class T> struct throw_error_policy { - typedef T type; - static T handle_error(lua_State* interpreter, LUABIND_TYPE_INFO type_info) { #ifndef LUABIND_NO_EXCEPTIONS @@ -787,11 +803,9 @@ template<class T> struct nothrow_error_policy { - typedef boost::optional<T> type; - - static type handle_error(lua_State*, LUABIND_TYPE_INFO) + static boost::optional<T> handle_error(lua_State*, LUABIND_TYPE_INFO) { - return type(); + return boost::optional<T>(); } }; @@ -805,6 +819,7 @@ , (T*)0 , (detail::null_type*)0 , (detail::throw_error_policy<T>*)0 + , (T*)0 ); } @@ -816,6 +831,7 @@ , (T*)0 , (Policies*)0 , (detail::throw_error_policy<T>*)0 + , (T*)0 ); } @@ -827,6 +843,7 @@ , (T*)0 , (detail::null_type*)0 , (detail::nothrow_error_policy<T>*)0 + , (boost::optional<T>*)0 ); } @@ -838,18 +855,13 @@ , (T*)0 , (Policies*)0 , (detail::nothrow_error_policy<T>*)0 + , (boost::optional<T>*)0 ); } namespace detail { - template<class T> - void convert_to_lua(lua_State*, const T&); - - template<int Index, class T, class Policies> - void convert_to_lua_p(lua_State*, const T&, const Policies&); - template<int Index> struct push_args_from_tuple { Index: class.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/class.hpp,v retrieving revision 1.63.2.2.2.1 retrieving revision 1.63.2.2.2.2 diff -u -d -r1.63.2.2.2.1 -r1.63.2.2.2.2 --- class.hpp 2 Oct 2005 00:19:11 -0000 1.63.2.2.2.1 +++ class.hpp 24 Oct 2005 00:31:34 -0000 1.63.2.2.2.2 @@ -1055,8 +1055,6 @@ void init() { - set_back_reference((back_reference<T>*)0); - class_base::init(LUABIND_TYPEID(T) , detail::internal_holder_type<typename meta::held_type>::apply() , detail::pointee_typeid( @@ -1110,7 +1108,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)); @@ -1127,7 +1125,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 @@ -1154,7 +1152,7 @@ class_& def_constructor( boost::mpl::true_ /* HasWrapper */ , Signature* - , Policies const& policies) + , Policies const&) { detail::construct_rep::overload_t o; @@ -1184,7 +1182,7 @@ class_& def_constructor( boost::mpl::false_ /* !HasWrapper */ , Signature* - , Policies const& policies) + , Policies const&) { detail::construct_rep::overload_t o; @@ -1211,16 +1209,6 @@ return *this; } - void set_back_reference(detail::default_back_reference*) - { - back_reference<T>::has_wrapper - = !boost::is_same<typename meta::wrapped_type, detail::null_type>::value; - } - - void set_back_reference(void*) - { - } - typedef void(*adopt_fun_t)(void*); template<class W> Index: value_wrapper.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/Attic/value_wrapper.hpp,v retrieving revision 1.1.2.7 retrieving revision 1.1.2.7.2.1 diff -u -d -r1.1.2.7 -r1.1.2.7.2.1 --- value_wrapper.hpp 30 Sep 2005 11:19:41 -0000 1.1.2.7 +++ value_wrapper.hpp 24 Oct 2005 00:31:34 -0000 1.1.2.7.2.1 @@ -127,33 +127,25 @@ #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(void(*)(T), ...); - - template<class T> - typename is_value_wrapper<T>::type - is_value_wrapper_arg_check(void(*)(T&), int); - - template<class T> - typename is_value_wrapper<T>::type - is_value_wrapper_arg_check(void(*)(T const&), long); - - boost::mpl::false_ is_value_wrapper_arg_check(...); - + 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((void(*)(T))0, 0L))) + sizeof(to_yesno(is_value_wrapper_arg_check(&x))) == sizeof(yes_t) ); Index: back_reference_fwd.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/back_reference_fwd.hpp,v retrieving revision 1.2 retrieving revision 1.2.4.1 diff -u -d -r1.2 -r1.2.4.1 --- back_reference_fwd.hpp 7 Aug 2004 13:37:10 -0000 1.2 +++ back_reference_fwd.hpp 24 Oct 2005 00:31:34 -0000 1.2.4.1 @@ -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: back_reference.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/back_reference.hpp,v retrieving revision 1.2 retrieving revision 1.2.4.1 diff -u -d -r1.2 -r1.2.4.1 --- back_reference.hpp 7 Aug 2004 13:37:10 -0000 1.2 +++ back_reference.hpp 24 Oct 2005 00:31:34 -0000 1.2.4.1 @@ -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 Index: adopt_policy.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/adopt_policy.hpp,v retrieving revision 1.10 retrieving revision 1.10.4.1 diff -u -d -r1.10 -r1.10.4.1 --- adopt_policy.hpp 7 Aug 2004 13:37:10 -0000 1.10 +++ adopt_policy.hpp 24 Oct 2005 00:31:34 -0000 1.10.4.1 @@ -87,7 +87,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 (move_back_reference::move(L, ptr)) { object_rep* obj = static_cast<object_rep*>(lua_touserdata(L, -1)); obj->set_flags(obj->flags() | object_rep::owner); --- 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 |
From: Daniel W. <dan...@us...> - 2005-10-24 00:31:50
|
Update of /cvsroot/luabind/luabind/luabind/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29574/test Modified Files: Tag: daniel-refactoring Jamfile test_lua_classes.cpp test_value_wrapper.cpp Added Files: Tag: daniel-refactoring test_back_reference.cpp test_def_from_base.cpp test_has_get_pointer.cpp Log Message: merged_beta7-devel2_into_daniel-refactoring_051024 --- 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" ); } --- 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: Jamfile =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/test/Jamfile,v retrieving revision 1.15.2.3 retrieving revision 1.15.2.3.2.1 diff -u -d -r1.15.2.3 -r1.15.2.3.2.1 --- Jamfile 30 Sep 2005 09:19:29 -0000 1.15.2.3 +++ Jamfile 24 Oct 2005 00:31:35 -0000 1.15.2.3.2.1 @@ -3,6 +3,8 @@ use-project /luabind : ../ ; SOURCES = + test_back_reference.cpp + test_def_from_base.cpp test_object.cpp test_abstract_base.cpp test_attributes.cpp @@ -21,7 +23,6 @@ test_separation.cpp test_simple_class.cpp test_yield.cpp - test_value_wrapper.cpp ; project : default-build <link>static ; @@ -38,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 ] + ; Index: test_lua_classes.cpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/test/test_lua_classes.cpp,v retrieving revision 1.26.2.2 retrieving revision 1.26.2.2.2.1 diff -u -d -r1.26.2.2 -r1.26.2.2.2.1 --- test_lua_classes.cpp 29 Jul 2005 02:41:02 -0000 1.26.2.2 +++ test_lua_classes.cpp 24 Oct 2005 00:31:35 -0000 1.26.2.2.2.1 @@ -165,22 +165,12 @@ .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" Index: test_value_wrapper.cpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/test/Attic/test_value_wrapper.cpp,v retrieving revision 1.1.2.1.2.1 retrieving revision 1.1.2.1.2.2 diff -u -d -r1.1.2.1.2.1 -r1.1.2.1.2.2 --- test_value_wrapper.cpp 10 Oct 2005 08:55:05 -0000 1.1.2.1.2.1 +++ test_value_wrapper.cpp 24 Oct 2005 00:31:35 -0000 1.1.2.1.2.2 @@ -21,6 +21,7 @@ // OR OTHER DEALINGS IN THE SOFTWARE. #include <luabind/value_wrapper.hpp> +#include <luabind/object.hpp> #include <boost/mpl/assert.hpp> struct X_tag; @@ -32,24 +33,27 @@ 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&> )); @@ -57,8 +61,9 @@ BOOST_MPL_ASSERT_NOT(( luabind::is_value_wrapper_arg<int> )); BOOST_MPL_ASSERT_NOT(( luabind::is_value_wrapper_arg<int[4]> )); -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 const&> )); +BOOST_MPL_ASSERT(( luabind::is_value_wrapper_arg<luabind::object&> )); +BOOST_MPL_ASSERT(( luabind::is_value_wrapper_arg<luabind::object const&> )); int main() { --- 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" ); } |
From: Daniel W. <dan...@us...> - 2005-10-24 00:31:50
|
Update of /cvsroot/luabind/luabind/luabind/luabind/detail In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29574/luabind/detail Modified Files: Tag: daniel-refactoring call.hpp class_rep.hpp constructor.hpp object_rep.hpp other.hpp overload_rep.hpp policy.hpp signature_match.hpp Added Files: Tag: daniel-refactoring has_get_pointer.hpp most_derived.hpp Log Message: merged_beta7-devel2_into_daniel-refactoring_051024 Index: overload_rep.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/detail/overload_rep.hpp,v retrieving revision 1.6.2.2 retrieving revision 1.6.2.2.2.1 diff -u -d -r1.6.2.2 -r1.6.2.2.2.1 --- overload_rep.hpp 1 Aug 2005 17:24:32 -0000 1.6.2.2 +++ overload_rep.hpp 24 Oct 2005 00:31:35 -0000 1.6.2.2.2.1 @@ -32,12 +32,15 @@ #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 { Index: other.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/detail/other.hpp,v retrieving revision 1.2 retrieving revision 1.2.6.1 diff -u -d -r1.2 -r1.2.6.1 --- other.hpp 14 Jun 2003 21:05:02 -0000 1.2 +++ other.hpp 24 Oct 2005 00:31:35 -0000 1.2.6.1 @@ -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: signature_match.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/detail/signature_match.hpp,v retrieving revision 1.3.2.1 retrieving revision 1.3.2.1.2.1 diff -u -d -r1.3.2.1 -r1.3.2.1.2.1 --- signature_match.hpp 27 Jul 2005 21:25:40 -0000 1.3.2.1 +++ signature_match.hpp 24 Oct 2005 00:31:35 -0000 1.3.2.1.2.1 @@ -48,6 +48,7 @@ #include <luabind/detail/primitives.hpp> #include <luabind/detail/object_rep.hpp> #include <luabind/detail/class_rep.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: call.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/detail/call.hpp,v retrieving revision 1.6 retrieving revision 1.6.4.1 diff -u -d -r1.6 -r1.6.4.1 --- call.hpp 7 Aug 2004 13:37:10 -0000 1.6 +++ call.hpp 24 Oct 2005 00:31:35 -0000 1.6.4.1 @@ -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: class_rep.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/detail/class_rep.hpp,v retrieving revision 1.41.2.3.2.2 retrieving revision 1.41.2.3.2.3 diff -u -d -r1.41.2.3.2.2 -r1.41.2.3.2.3 --- class_rep.hpp 10 Oct 2005 08:55:05 -0000 1.41.2.3.2.2 +++ class_rep.hpp 24 Oct 2005 00:31:35 -0000 1.41.2.3.2.3 @@ -42,6 +42,15 @@ #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 { namespace detail { --- 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: constructor.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/detail/constructor.hpp,v retrieving revision 1.7 retrieving revision 1.7.4.1 diff -u -d -r1.7 -r1.7.4.1 --- constructor.hpp 7 Aug 2004 13:37:10 -0000 1.7 +++ constructor.hpp 24 Oct 2005 00:31:35 -0000 1.7.4.1 @@ -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: object_rep.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/detail/object_rep.hpp,v retrieving revision 1.19 retrieving revision 1.19.4.1 diff -u -d -r1.19 -r1.19.4.1 --- object_rep.hpp 7 Aug 2004 13:37:10 -0000 1.19 +++ object_rep.hpp 24 Oct 2005 00:31:35 -0000 1.19.4.1 @@ -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; --- 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 Index: policy.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/detail/policy.hpp,v retrieving revision 1.50.2.6 retrieving revision 1.50.2.6.2.1 diff -u -d -r1.50.2.6 -r1.50.2.6.2.1 --- policy.hpp 29 Sep 2005 14:58:31 -0000 1.50.2.6 +++ policy.hpp 24 Oct 2005 00:31:35 -0000 1.50.2.6.2.1 @@ -471,7 +471,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); @@ -565,7 +565,7 @@ 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); @@ -711,7 +711,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); @@ -782,7 +782,7 @@ 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); @@ -840,7 +840,7 @@ 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); |
From: Daniel W. <dan...@us...> - 2005-10-24 00:31:47
|
Update of /cvsroot/luabind/luabind/luabind/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29574/src Modified Files: Tag: daniel-refactoring class.cpp Log Message: merged_beta7-devel2_into_daniel-refactoring_051024 Index: class.cpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/src/class.cpp,v retrieving revision 1.10 retrieving revision 1.10.4.1 diff -u -d -r1.10 -r1.10.4.1 --- class.cpp 7 Aug 2004 13:37:11 -0000 1.10 +++ class.cpp 24 Oct 2005 00:31:35 -0000 1.10.4.1 @@ -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-10-23 21:47:35
|
Update of /cvsroot/luabind/luabind/luabind/luabind In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26408 Modified Files: Tag: beta7-devel2 get_pointer.hpp Log Message: Fix for VC6/7. Index: get_pointer.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/Attic/get_pointer.hpp,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -d -r1.1.2.1 -r1.1.2.2 --- get_pointer.hpp 23 Oct 2005 21:37:16 -0000 1.1.2.1 +++ get_pointer.hpp 23 Oct 2005 21:47:27 -0000 1.1.2.2 @@ -24,28 +24,14 @@ # define LUABIND_GET_POINTER_051023_HPP // -// This is essentially just boost/get_pointer.hpp, but we need these -// in the luabind namespace. +// We need these overloads in the luabind namespace. // -// Copyright Peter Dimov and David Abrahams 2002. -// Distributed under the Boost Software License, Version 1.0. (See -// accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) +# include <boost/get_pointer.hpp> namespace luabind { -template<class T> -T* get_pointer(T* p) -{ - return p; -} - -template<class T> -T* get_pointer(std::auto_ptr<T> const& p) -{ - return p.get(); -} +using boost::get_pointer; } // namespace luabind |
From: Daniel W. <dan...@us...> - 2005-10-23 21:38:40
|
Update of /cvsroot/luabind/luabind/luabind/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25052 Modified Files: Tag: beta7-devel2 test_has_get_pointer.cpp Log Message: Removed commented out test code. Index: test_has_get_pointer.cpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/test/Attic/test_has_get_pointer.cpp,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -d -r1.1.2.1 -r1.1.2.2 --- test_has_get_pointer.cpp 23 Oct 2005 21:35:21 -0000 1.1.2.1 +++ test_has_get_pointer.cpp 23 Oct 2005 21:38:32 -0000 1.1.2.2 @@ -56,117 +56,3 @@ BOOST_MPL_ASSERT_NOT(( lb::has_get_pointer<int> )); BOOST_MPL_ASSERT_NOT(( lb::has_get_pointer<test::X> )); -int main() -{ - using namespace luabind; - - test::Y const x; - char* z; - char*& y = z; - - get_pointer(x); -} - -#if 0 -template<class T> -struct X -{ -}; - -#include <boost/mpl/bool.hpp> -#include <boost/get_pointer.hpp> -#include <boost/shared_ptr.hpp> - -namespace luabind { - -#ifdef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP -using boost::get_pointer; -#endif - -namespace has_get_pointer_ -{ - struct any - { - template<class T> - any(T const&); - }; - - struct tag {}; - - tag operator,(tag,int); - -#ifdef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP -} // namespace has_get_pointer_ -#endif - - has_get_pointer_::tag get_pointer(has_get_pointer_::any); - -#ifdef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP -namespace has_get_pointer_ -{ -#endif - - typedef char(&yes)[1]; - typedef char(&no)[2]; - - no check(tag); - template<class T> - yes check(T const&); - - template<class T> - struct impl - { - BOOST_STATIC_CONSTANT(bool, value = sizeof( - check( (get_pointer(*(T*)0),0) )) == sizeof(yes) - ); - - 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 - -struct Y -{ -}; - -#ifdef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP -namespace luabind -{ -#endif - template<class T> - void get_pointer(X<T> const&) - { - ///return (T*)0; - } -#ifdef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP -} // namespace luabind -#endif - -#include <boost/static_assert.hpp> - -int main() -{ - X<int> x; - int* y; - boost::shared_ptr<int> z; - - using namespace luabind; - - //get_pointer(y); -// get_pointer(x); - - BOOST_STATIC_ASSERT((luabind::has_get_pointer<int>::value == 0)); - BOOST_STATIC_ASSERT((luabind::has_get_pointer<X<int> >::value == 1)); - BOOST_STATIC_ASSERT((luabind::has_get_pointer<boost::shared_ptr<int> >::value == 1)); - - return 0; -} - -#endif |
From: Daniel W. <dan...@us...> - 2005-10-23 21:37:24
|
Update of /cvsroot/luabind/luabind/luabind/luabind In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24753 Modified Files: Tag: beta7-devel2 adopt_policy.hpp back_reference.hpp back_reference_fwd.hpp class.hpp Added Files: Tag: beta7-devel2 get_pointer.hpp Log Message: Rewrote back_reference code. Should now work with smart pointers. Index: adopt_policy.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/adopt_policy.hpp,v retrieving revision 1.10 retrieving revision 1.10.2.1 diff -u -d -r1.10 -r1.10.2.1 --- adopt_policy.hpp 7 Aug 2004 13:37:10 -0000 1.10 +++ adopt_policy.hpp 23 Oct 2005 21:37:16 -0000 1.10.2.1 @@ -87,7 +87,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 (move_back_reference::move(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.2.3 retrieving revision 1.63.2.4 diff -u -d -r1.63.2.3 -r1.63.2.4 --- class.hpp 19 Oct 2005 11:46:42 -0000 1.63.2.3 +++ class.hpp 23 Oct 2005 21:37:16 -0000 1.63.2.4 @@ -1141,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_< @@ -1312,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> Index: back_reference_fwd.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/back_reference_fwd.hpp,v retrieving revision 1.2 retrieving revision 1.2.2.1 diff -u -d -r1.2 -r1.2.2.1 --- back_reference_fwd.hpp 7 Aug 2004 13:37:10 -0000 1.2 +++ back_reference_fwd.hpp 23 Oct 2005 21:37:16 -0000 1.2.2.1 @@ -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: back_reference.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/back_reference.hpp,v retrieving revision 1.2 retrieving revision 1.2.2.1 diff -u -d -r1.2 -r1.2.2.1 --- back_reference.hpp 7 Aug 2004 13:37:10 -0000 1.2 +++ back_reference.hpp 23 Oct 2005 21:37:16 -0000 1.2.2.1 @@ -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: 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 // // This is essentially just boost/get_pointer.hpp, but we need these // in the luabind namespace. // // Copyright Peter Dimov and David Abrahams 2002. // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) namespace luabind { template<class T> T* get_pointer(T* p) { return p; } template<class T> T* get_pointer(std::auto_ptr<T> const& p) { return p.get(); } } // namespace luabind #endif // LUABIND_GET_POINTER_051023_HPP |
From: Daniel W. <dan...@us...> - 2005-10-23 21:37:24
|
Update of /cvsroot/luabind/luabind/luabind/luabind/detail In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24753/detail Modified Files: Tag: beta7-devel2 policy.hpp Added Files: Tag: beta7-devel2 has_get_pointer.hpp Log Message: Rewrote back_reference code. Should now work with smart pointers. --- 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: policy.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/detail/policy.hpp,v retrieving revision 1.50.2.6 retrieving revision 1.50.2.7 diff -u -d -r1.50.2.6 -r1.50.2.7 --- policy.hpp 29 Sep 2005 14:58:31 -0000 1.50.2.6 +++ policy.hpp 23 Oct 2005 21:37:16 -0000 1.50.2.7 @@ -471,7 +471,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); @@ -565,7 +565,7 @@ 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); @@ -711,7 +711,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); @@ -782,7 +782,7 @@ 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); @@ -840,7 +840,7 @@ 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); |
From: Daniel W. <dan...@us...> - 2005-10-23 21:35:30
|
Update of /cvsroot/luabind/luabind/luabind/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24439 Modified Files: Tag: beta7-devel2 Jamfile Added Files: Tag: beta7-devel2 test_back_reference.cpp test_has_get_pointer.cpp Log Message: Added back_reference and has_get_pointer tests. --- 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> )); int main() { using namespace luabind; test::Y const x; char* z; char*& y = z; get_pointer(x); } #if 0 template<class T> struct X { }; #include <boost/mpl/bool.hpp> #include <boost/get_pointer.hpp> #include <boost/shared_ptr.hpp> namespace luabind { #ifdef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP using boost::get_pointer; #endif namespace has_get_pointer_ { struct any { template<class T> any(T const&); }; struct tag {}; tag operator,(tag,int); #ifdef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP } // namespace has_get_pointer_ #endif has_get_pointer_::tag get_pointer(has_get_pointer_::any); #ifdef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP namespace has_get_pointer_ { #endif typedef char(&yes)[1]; typedef char(&no)[2]; no check(tag); template<class T> yes check(T const&); template<class T> struct impl { BOOST_STATIC_CONSTANT(bool, value = sizeof( check( (get_pointer(*(T*)0),0) )) == sizeof(yes) ); 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 struct Y { }; #ifdef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP namespace luabind { #endif template<class T> void get_pointer(X<T> const&) { ///return (T*)0; } #ifdef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP } // namespace luabind #endif #include <boost/static_assert.hpp> int main() { X<int> x; int* y; boost::shared_ptr<int> z; using namespace luabind; //get_pointer(y); // get_pointer(x); BOOST_STATIC_ASSERT((luabind::has_get_pointer<int>::value == 0)); BOOST_STATIC_ASSERT((luabind::has_get_pointer<X<int> >::value == 1)); BOOST_STATIC_ASSERT((luabind::has_get_pointer<boost::shared_ptr<int> >::value == 1)); return 0; } #endif Index: Jamfile =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/test/Jamfile,v retrieving revision 1.15.2.8 retrieving revision 1.15.2.9 diff -u -d -r1.15.2.8 -r1.15.2.9 --- Jamfile 23 Oct 2005 10:45:03 -0000 1.15.2.8 +++ Jamfile 23 Oct 2005 21:35:21 -0000 1.15.2.9 @@ -3,6 +3,7 @@ use-project /luabind : ../ ; SOURCES = + test_back_reference.cpp test_def_from_base.cpp test_object.cpp test_abstract_base.cpp @@ -41,5 +42,6 @@ test-suite luabind-test : $(tests) [ compile test_typetraits.cpp ] [ compile test_value_wrapper.cpp ] + [ compile test_has_get_pointer.cpp ] ; --- 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" ); } |
From: Arvid N. <ar...@us...> - 2005-10-23 10:45:17
|
Update of /cvsroot/luabind/luabind/luabind/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26303 Modified Files: Tag: beta7-devel2 Jamfile Log Message: fixed a mistake in the Jamfile Index: Jamfile =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/test/Jamfile,v retrieving revision 1.15.2.7 retrieving revision 1.15.2.8 diff -u -d -r1.15.2.7 -r1.15.2.8 --- Jamfile 22 Oct 2005 10:42:33 -0000 1.15.2.7 +++ Jamfile 23 Oct 2005 10:45:03 -0000 1.15.2.8 @@ -22,7 +22,6 @@ test_separation.cpp test_simple_class.cpp test_yield.cpp - test_yield2.cpp ; project : default-build <link>static ; |