potential luabind fix for gcc

Conflicts:
	mp/src/thirdparty/luabind/detail/call_function.hpp
	mp/src/thirdparty/luabind/detail/call_member.hpp
	mp/src/thirdparty/luabind/wrapper_base.hpp
This commit is contained in:
Dexter 2013-10-30 02:13:31 +00:00 committed by squeek
parent f8b8321865
commit 1609c58888
3 changed files with 999 additions and 996 deletions

View file

@ -1,443 +1,444 @@
// Copyright (c) 2003 Daniel Wallin and Arvid Norberg // Copyright (c) 2003 Daniel Wallin and Arvid Norberg
// Permission is hereby granted, free of charge, to any person obtaining a // Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"), // copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation // to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, // the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the // 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: // Software is furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included // The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software. // in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
// ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED // ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT // PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
// SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR // SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
// ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN // ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
// OR OTHER DEALINGS IN THE SOFTWARE. // OR OTHER DEALINGS IN THE SOFTWARE.
#if !BOOST_PP_IS_ITERATING #if !BOOST_PP_IS_ITERATING
#ifndef LUABIND_CALL_FUNCTION_HPP_INCLUDED #ifndef LUABIND_CALL_FUNCTION_HPP_INCLUDED
#define LUABIND_CALL_FUNCTION_HPP_INCLUDED #define LUABIND_CALL_FUNCTION_HPP_INCLUDED
#include <luabind/config.hpp> #include <luabind/config.hpp>
#include <boost/mpl/if.hpp> #include <boost/mpl/if.hpp>
#include <boost/tuple/tuple.hpp> #include <boost/tuple/tuple.hpp>
#include <boost/mpl/or.hpp> #include <boost/mpl/or.hpp>
#include <boost/preprocessor/repeat.hpp> #include <boost/preprocessor/repeat.hpp>
#include <boost/preprocessor/iteration/iterate.hpp> #include <boost/preprocessor/iteration/iterate.hpp>
#include <boost/preprocessor/repetition/enum.hpp> #include <boost/preprocessor/repetition/enum.hpp>
#include <boost/preprocessor/repetition/enum_params.hpp> #include <boost/preprocessor/repetition/enum_params.hpp>
#include <boost/preprocessor/repetition/enum_binary_params.hpp> #include <boost/preprocessor/repetition/enum_binary_params.hpp>
#include <boost/preprocessor/punctuation/comma_if.hpp> #include <boost/preprocessor/punctuation/comma_if.hpp>
#include <luabind/error.hpp> #include <luabind/error.hpp>
#include <luabind/detail/convert_to_lua.hpp> #include <luabind/detail/convert_to_lua.hpp>
#include <luabind/detail/pcall.hpp> #include <luabind/detail/pcall.hpp>
namespace luabind namespace luabind
{ {
namespace detail namespace detail
{ {
// if the proxy_function_caller returns non-void // if the proxy_function_caller returns non-void
template<class Ret, class Tuple> template<class Ret, class Tuple>
class proxy_function_caller class proxy_function_caller
{ {
// friend class luabind::object; // friend class luabind::object;
public: public:
typedef int(*function_t)(lua_State*, int, int); typedef int(*function_t)(lua_State*, int, int);
proxy_function_caller( proxy_function_caller(
lua_State* L lua_State* L
, int params , int params
, function_t fun , function_t fun
, const Tuple args) , const Tuple args)
: m_state(L) : m_state(L)
, m_params(params) , m_params(params)
, m_fun(fun) , m_fun(fun)
, m_args(args) , m_args(args)
, m_called(false) , m_called(false)
{ {
} }
proxy_function_caller(const proxy_function_caller& rhs) proxy_function_caller(const proxy_function_caller& rhs)
: m_state(rhs.m_state) : m_state(rhs.m_state)
, m_params(rhs.m_params) , m_params(rhs.m_params)
, m_fun(rhs.m_fun) , m_fun(rhs.m_fun)
, m_args(rhs.m_args) , m_args(rhs.m_args)
, m_called(rhs.m_called) , m_called(rhs.m_called)
{ {
rhs.m_called = true; rhs.m_called = true;
} }
~proxy_function_caller() ~proxy_function_caller()
{ {
if (m_called) return; if (m_called) return;
m_called = true; m_called = true;
lua_State* L = m_state; lua_State* L = m_state;
int top = lua_gettop(L); int top = lua_gettop(L);
push_args_from_tuple<1>::apply(L, m_args); push_args_from_tuple<1>::apply(L, m_args);
if (m_fun(L, boost::tuples::length<Tuple>::value, 0)) if (m_fun(L, boost::tuples::length<Tuple>::value, 0))
{ {
assert(lua_gettop(L) == top - m_params + 1); assert(lua_gettop(L) == top - m_params + 1);
#ifndef LUABIND_NO_EXCEPTIONS #ifndef LUABIND_NO_EXCEPTIONS
throw luabind::error(L); throw luabind::error(L);
#else #else
error_callback_fun e = get_error_callback(); error_callback_fun e = get_error_callback();
if (e) e(L); if (e) e(L);
assert(0 && "the lua function threw an error and exceptions are disabled." assert(0 && "the lua function threw an error and exceptions are disabled."
" If you want to handle the error you can use luabind::set_error_callback()"); " If you want to handle the error you can use luabind::set_error_callback()");
std::terminate(); std::terminate();
#endif #endif
} }
// pops the return values from the function call // pops the return values from the function call
stack_pop pop(L, lua_gettop(L) - top + m_params); stack_pop pop(L, lua_gettop(L) - top + m_params);
} }
operator Ret() operator Ret()
{ {
typename mpl::apply_wrap2<default_policy,Ret,lua_to_cpp>::type converter; typename mpl::apply_wrap2<default_policy,Ret,lua_to_cpp>::type converter;
m_called = true; m_called = true;
lua_State* L = m_state; lua_State* L = m_state;
int top = lua_gettop(L); int top = lua_gettop(L);
push_args_from_tuple<1>::apply(L, m_args); push_args_from_tuple<1>::apply(L, m_args);
if (m_fun(L, boost::tuples::length<Tuple>::value, 1)) if (m_fun(L, boost::tuples::length<Tuple>::value, 1))
{ {
assert(lua_gettop(L) == top - m_params + 1); assert(lua_gettop(L) == top - m_params + 1);
#ifndef LUABIND_NO_EXCEPTIONS #ifndef LUABIND_NO_EXCEPTIONS
throw luabind::error(L); throw luabind::error(L);
#else #else
error_callback_fun e = get_error_callback(); error_callback_fun e = get_error_callback();
if (e) e(L); if (e) e(L);
assert(0 && "the lua function threw an error and exceptions are disabled." assert(0 && "the lua function threw an error and exceptions are disabled."
" If you want to handle the error you can use luabind::set_error_callback()"); " If you want to handle the error you can use luabind::set_error_callback()");
std::terminate(); std::terminate();
#endif #endif
} }
// pops the return values from the function call // pops the return values from the function call
stack_pop pop(L, lua_gettop(L) - top + m_params); stack_pop pop(L, lua_gettop(L) - top + m_params);
#ifndef LUABIND_NO_ERROR_CHECKING #ifndef LUABIND_NO_ERROR_CHECKING
if (converter.match(L, LUABIND_DECORATE_TYPE(Ret), -1) < 0) if (converter.match(L, LUABIND_DECORATE_TYPE(Ret), -1) < 0)
{ {
#ifndef LUABIND_NO_EXCEPTIONS #ifndef LUABIND_NO_EXCEPTIONS
throw cast_failed(L, typeid(Ret)); throw cast_failed(L, typeid(Ret));
#else #else
cast_failed_callback_fun e = get_cast_failed_callback(); cast_failed_callback_fun e = get_cast_failed_callback();
if (e) e(L, typeid(Ret)); if (e) e(L, typeid(Ret));
assert(0 && "the lua function's return value could not be converted." assert(0 && "the lua function's return value could not be converted."
" If you want to handle the error you can use luabind::set_error_callback()"); " If you want to handle the error you can use luabind::set_error_callback()");
std::terminate(); std::terminate();
#endif #endif
} }
#endif #endif
return converter.apply(L, LUABIND_DECORATE_TYPE(Ret), -1); return converter.apply(L, LUABIND_DECORATE_TYPE(Ret), -1);
} }
template<class Policies> template<class Policies>
Ret operator[](const Policies& p) Ret operator[](const Policies& p)
{ {
typedef typename detail::find_conversion_policy<0, Policies>::type converter_policy; typedef typename detail::find_conversion_policy<0, Policies>::type converter_policy;
typename mpl::apply_wrap2<converter_policy,Ret,lua_to_cpp>::type converter; typename mpl::apply_wrap2<converter_policy,Ret,lua_to_cpp>::type converter;
m_called = true; m_called = true;
lua_State* L = m_state; lua_State* L = m_state;
int top = lua_gettop(L); int top = lua_gettop(L);
detail::push_args_from_tuple<1>::apply(L, m_args, p); detail::push_args_from_tuple<1>::apply(L, m_args, p);
if (m_fun(L, boost::tuples::length<Tuple>::value, 1)) if (m_fun(L, boost::tuples::length<Tuple>::value, 1))
{ {
assert(lua_gettop(L) == top - m_params + 1); assert(lua_gettop(L) == top - m_params + 1);
#ifndef LUABIND_NO_EXCEPTIONS #ifndef LUABIND_NO_EXCEPTIONS
throw error(L); throw error(L);
#else #else
error_callback_fun e = get_error_callback(); error_callback_fun e = get_error_callback();
if (e) e(L); if (e) e(L);
assert(0 && "the lua function threw an error and exceptions are disabled." assert(0 && "the lua function threw an error and exceptions are disabled."
" If you want to handle the error you can use luabind::set_error_callback()"); " If you want to handle the error you can use luabind::set_error_callback()");
std::terminate(); std::terminate();
#endif #endif
} }
// pops the return values from the function call // pops the return values from the function call
stack_pop pop(L, lua_gettop(L) - top + m_params); stack_pop pop(L, lua_gettop(L) - top + m_params);
#ifndef LUABIND_NO_ERROR_CHECKING #ifndef LUABIND_NO_ERROR_CHECKING
if (converter.match(L, LUABIND_DECORATE_TYPE(Ret), -1) < 0) if (converter.match(L, LUABIND_DECORATE_TYPE(Ret), -1) < 0)
{ {
#ifndef LUABIND_NO_EXCEPTIONS #ifndef LUABIND_NO_EXCEPTIONS
throw cast_failed(L, typeid(Ret)); throw cast_failed(L, typeid(Ret));
#else #else
cast_failed_callback_fun e = get_cast_failed_callback(); cast_failed_callback_fun e = get_cast_failed_callback();
if (e) e(L, typeid(Ret)); if (e) e(L, typeid(Ret));
assert(0 && "the lua function's return value could not be converted." assert(0 && "the lua function's return value could not be converted."
" If you want to handle the error you can use luabind::set_error_callback()"); " If you want to handle the error you can use luabind::set_error_callback()");
std::terminate(); std::terminate();
#endif #endif
} }
#endif #endif
return converter.apply(L, LUABIND_DECORATE_TYPE(Ret), -1); return converter.apply(L, LUABIND_DECORATE_TYPE(Ret), -1);
} }
private: private:
lua_State* m_state; lua_State* m_state;
int m_params; int m_params;
function_t m_fun; function_t m_fun;
Tuple m_args; Tuple m_args;
mutable bool m_called; mutable bool m_called;
}; };
// if the proxy_member_caller returns void // if the proxy_member_caller returns void
template<class Tuple> template<class Tuple>
class proxy_function_void_caller class proxy_function_void_caller
{ {
friend class luabind::object; friend class luabind::object;
public: public:
typedef int(*function_t)(lua_State*, int, int); typedef int(*function_t)(lua_State*, int, int);
proxy_function_void_caller( proxy_function_void_caller(
lua_State* L lua_State* L
, int params , int params
, function_t fun , function_t fun
, const Tuple args) , const Tuple args)
: m_state(L) : m_state(L)
, m_params(params) , m_params(params)
, m_fun(fun) , m_fun(fun)
, m_args(args) , m_args(args)
, m_called(false) , m_called(false)
{ {
} }
proxy_function_void_caller(const proxy_function_void_caller& rhs) proxy_function_void_caller(const proxy_function_void_caller& rhs)
: m_state(rhs.m_state) : m_state(rhs.m_state)
, m_params(rhs.m_params) , m_params(rhs.m_params)
, m_fun(rhs.m_fun) , m_fun(rhs.m_fun)
, m_args(rhs.m_args) , m_args(rhs.m_args)
, m_called(rhs.m_called) , m_called(rhs.m_called)
{ {
rhs.m_called = true; rhs.m_called = true;
} }
~proxy_function_void_caller() ~proxy_function_void_caller()
{ {
if (m_called) return; if (m_called) return;
m_called = true; m_called = true;
lua_State* L = m_state; lua_State* L = m_state;
int top = lua_gettop(L); int top = lua_gettop(L);
push_args_from_tuple<1>::apply(L, m_args); push_args_from_tuple<1>::apply(L, m_args);
if (m_fun(L, boost::tuples::length<Tuple>::value, 0)) if (m_fun(L, boost::tuples::length<Tuple>::value, 0))
{ {
assert(lua_gettop(L) == top - m_params + 1); assert(lua_gettop(L) == top - m_params + 1);
#ifndef LUABIND_NO_EXCEPTIONS #ifndef LUABIND_NO_EXCEPTIONS
throw luabind::error(L); throw luabind::error(L);
#else #else
error_callback_fun e = get_error_callback(); error_callback_fun e = get_error_callback();
if (e) e(L); if (e) e(L);
assert(0 && "the lua function threw an error and exceptions are disabled." assert(0 && "the lua function threw an error and exceptions are disabled."
" If you want to handle the error you can use luabind::set_error_callback()"); " If you want to handle the error you can use luabind::set_error_callback()");
std::terminate(); std::terminate();
#endif #endif
} }
// pops the return values from the function call // pops the return values from the function call
stack_pop pop(L, lua_gettop(L) - top + m_params); stack_pop pop(L, lua_gettop(L) - top + m_params);
} }
template<class Policies> template<class Policies>
void operator[](const Policies& p) void operator[](const Policies& p)
{ {
m_called = true; m_called = true;
lua_State* L = m_state; lua_State* L = m_state;
int top = lua_gettop(L); int top = lua_gettop(L);
detail::push_args_from_tuple<1>::apply(L, m_args, p); detail::push_args_from_tuple<1>::apply(L, m_args, p);
if (m_fun(L, boost::tuples::length<Tuple>::value, 0)) if (m_fun(L, boost::tuples::length<Tuple>::value, 0))
{ {
assert(lua_gettop(L) == top - m_params + 1); assert(lua_gettop(L) == top - m_params + 1);
#ifndef LUABIND_NO_EXCEPTIONS #ifndef LUABIND_NO_EXCEPTIONS
throw error(L); throw error(L);
#else #else
error_callback_fun e = get_error_callback(); error_callback_fun e = get_error_callback();
if (e) e(L); if (e) e(L);
assert(0 && "the lua function threw an error and exceptions are disabled." assert(0 && "the lua function threw an error and exceptions are disabled."
" If you want to handle the error you can use luabind::set_error_callback()"); " If you want to handle the error you can use luabind::set_error_callback()");
std::terminate(); std::terminate();
#endif #endif
} }
// pops the return values from the function call // pops the return values from the function call
stack_pop pop(L, lua_gettop(L) - top + m_params); stack_pop pop(L, lua_gettop(L) - top + m_params);
} }
private: private:
lua_State* m_state; lua_State* m_state;
int m_params; int m_params;
function_t m_fun; function_t m_fun;
Tuple m_args; Tuple m_args;
mutable bool m_called; mutable bool m_called;
}; };
} }
#define BOOST_PP_ITERATION_PARAMS_1 (4, (0, LUABIND_MAX_ARITY, <luabind/detail/call_function.hpp>, 1)) #define BOOST_PP_ITERATION_PARAMS_1 (4, (0, LUABIND_MAX_ARITY, <luabind/detail/call_function.hpp>, 1))
#include BOOST_PP_ITERATE() #include BOOST_PP_ITERATE()
} }
#endif // LUABIND_CALL_FUNCTION_HPP_INCLUDED #endif // LUABIND_CALL_FUNCTION_HPP_INCLUDED
#elif BOOST_PP_ITERATION_FLAGS() == 1 #else // FF dexter gcc fix
#if BOOST_PP_ITERATION_FLAGS() == 1
#define LUABIND_TUPLE_PARAMS(z, n, data) const A##n *
#define LUABIND_OPERATOR_PARAMS(z, n, data) const A##n & a##n #define LUABIND_TUPLE_PARAMS(z, n, data) const A##n *
#define LUABIND_OPERATOR_PARAMS(z, n, data) const A##n & a##n
template<class Ret BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), class A)>
typename boost::mpl::if_<boost::is_void<Ret> template<class Ret BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), class A)>
, luabind::detail::proxy_function_void_caller<boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> > typename boost::mpl::if_<boost::is_void<Ret>
, luabind::detail::proxy_function_caller<Ret, boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> > >::type , luabind::detail::proxy_function_void_caller<boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> >
call_function(lua_State* L, const char* name BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_OPERATOR_PARAMS, _) ) , luabind::detail::proxy_function_caller<Ret, boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> > >::type
{ call_function(lua_State* L, const char* name BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_OPERATOR_PARAMS, _) )
assert(name && "luabind::call_function() expects a function name"); {
typedef boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> tuple_t; assert(name && "luabind::call_function() expects a function name");
#if BOOST_PP_ITERATION() == 0 typedef boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> tuple_t;
tuple_t args; #if BOOST_PP_ITERATION() == 0
#else tuple_t args;
tuple_t args(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), &a)); #else
#endif tuple_t args(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), &a));
typedef typename boost::mpl::if_<boost::is_void<Ret> #endif
, luabind::detail::proxy_function_void_caller<boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> > typedef typename boost::mpl::if_<boost::is_void<Ret>
, luabind::detail::proxy_function_caller<Ret, boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> > >::type proxy_type; , luabind::detail::proxy_function_void_caller<boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> >
, luabind::detail::proxy_function_caller<Ret, boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> > >::type proxy_type;
lua_pushstring(L, name);
lua_gettable(L, LUA_GLOBALSINDEX); lua_pushstring(L, name);
lua_gettable(L, LUA_GLOBALSINDEX);
return proxy_type(L, 1, &detail::pcall, args);
} return proxy_type(L, 1, &detail::pcall, args);
}
template<class Ret BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), class A)>
typename boost::mpl::if_<boost::is_void<Ret> template<class Ret BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), class A)>
, luabind::detail::proxy_function_void_caller<boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> > typename boost::mpl::if_<boost::is_void<Ret>
, luabind::detail::proxy_function_caller<Ret, boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> > >::type , luabind::detail::proxy_function_void_caller<boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> >
call_function(luabind::object const& obj BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_OPERATOR_PARAMS, _) ) , luabind::detail::proxy_function_caller<Ret, boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> > >::type
{ call_function(luabind::object const& obj BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_OPERATOR_PARAMS, _) )
typedef boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> tuple_t; {
#if BOOST_PP_ITERATION() == 0 typedef boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> tuple_t;
tuple_t args; #if BOOST_PP_ITERATION() == 0
#else tuple_t args;
tuple_t args(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), &a)); #else
#endif tuple_t args(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), &a));
typedef typename boost::mpl::if_<boost::is_void<Ret> #endif
, luabind::detail::proxy_function_void_caller<boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> > typedef typename boost::mpl::if_<boost::is_void<Ret>
, luabind::detail::proxy_function_caller<Ret, boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> > >::type proxy_type; , luabind::detail::proxy_function_void_caller<boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> >
, luabind::detail::proxy_function_caller<Ret, boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> > >::type proxy_type;
obj.push(obj.interpreter());
return proxy_type(obj.interpreter(), 1, &detail::pcall, args); obj.push(obj.interpreter());
} return proxy_type(obj.interpreter(), 1, &detail::pcall, args);
}
template<class Ret BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), class A)>
typename boost::mpl::if_<boost::is_void<Ret> template<class Ret BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), class A)>
, luabind::detail::proxy_function_void_caller<boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> > typename boost::mpl::if_<boost::is_void<Ret>
, luabind::detail::proxy_function_caller<Ret, boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> > >::type , luabind::detail::proxy_function_void_caller<boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> >
resume_function(lua_State* L, const char* name BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_OPERATOR_PARAMS, _) ) , luabind::detail::proxy_function_caller<Ret, boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> > >::type
{ resume_function(lua_State* L, const char* name BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_OPERATOR_PARAMS, _) )
assert(name && "luabind::resume_function() expects a function name"); {
typedef boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> tuple_t; assert(name && "luabind::resume_function() expects a function name");
#if BOOST_PP_ITERATION() == 0 typedef boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> tuple_t;
tuple_t args; #if BOOST_PP_ITERATION() == 0
#else tuple_t args;
tuple_t args(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), &a)); #else
#endif tuple_t args(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), &a));
typedef typename boost::mpl::if_<boost::is_void<Ret> #endif
, luabind::detail::proxy_function_void_caller<boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> > typedef typename boost::mpl::if_<boost::is_void<Ret>
, luabind::detail::proxy_function_caller<Ret, boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> > >::type proxy_type; , luabind::detail::proxy_function_void_caller<boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> >
, luabind::detail::proxy_function_caller<Ret, boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> > >::type proxy_type;
lua_pushstring(L, name);
lua_gettable(L, LUA_GLOBALSINDEX); lua_pushstring(L, name);
lua_gettable(L, LUA_GLOBALSINDEX);
return proxy_type(L, 1, &detail::resume_impl, args);
} return proxy_type(L, 1, &detail::resume_impl, args);
}
template<class Ret BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), class A)>
typename boost::mpl::if_<boost::is_void<Ret> template<class Ret BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), class A)>
, luabind::detail::proxy_function_void_caller<boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> > typename boost::mpl::if_<boost::is_void<Ret>
, luabind::detail::proxy_function_caller<Ret, boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> > >::type , luabind::detail::proxy_function_void_caller<boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> >
resume_function(luabind::object const& obj BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_OPERATOR_PARAMS, _) ) , luabind::detail::proxy_function_caller<Ret, boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> > >::type
{ resume_function(luabind::object const& obj BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_OPERATOR_PARAMS, _) )
typedef boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> tuple_t; {
#if BOOST_PP_ITERATION() == 0 typedef boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> tuple_t;
tuple_t args; #if BOOST_PP_ITERATION() == 0
#else tuple_t args;
tuple_t args(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), &a)); #else
#endif tuple_t args(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), &a));
typedef typename boost::mpl::if_<boost::is_void<Ret> #endif
, luabind::detail::proxy_function_void_caller<boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> > typedef typename boost::mpl::if_<boost::is_void<Ret>
, luabind::detail::proxy_function_caller<Ret, boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> > >::type proxy_type; , luabind::detail::proxy_function_void_caller<boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> >
, luabind::detail::proxy_function_caller<Ret, boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> > >::type proxy_type;
obj.push(obj.interpreter());
return proxy_type(obj.interpreter(), 1, &detail::resume_impl, args); obj.push(obj.interpreter());
} return proxy_type(obj.interpreter(), 1, &detail::resume_impl, args);
}
template<class Ret BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), class A)>
typename boost::mpl::if_<boost::is_void<Ret> template<class Ret BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), class A)>
, luabind::detail::proxy_function_void_caller<boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> > typename boost::mpl::if_<boost::is_void<Ret>
, luabind::detail::proxy_function_caller<Ret, boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> > >::type , luabind::detail::proxy_function_void_caller<boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> >
resume(lua_State* L BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_OPERATOR_PARAMS, _) ) , luabind::detail::proxy_function_caller<Ret, boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> > >::type
{ resume(lua_State* L BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_OPERATOR_PARAMS, _) )
typedef boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> tuple_t; {
#if BOOST_PP_ITERATION() == 0 typedef boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> tuple_t;
tuple_t args; #if BOOST_PP_ITERATION() == 0
#else tuple_t args;
tuple_t args(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), &a)); #else
#endif tuple_t args(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), &a));
typedef typename boost::mpl::if_<boost::is_void<Ret> #endif
, luabind::detail::proxy_function_void_caller<boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> > typedef typename boost::mpl::if_<boost::is_void<Ret>
, luabind::detail::proxy_function_caller<Ret, boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> > >::type proxy_type; , luabind::detail::proxy_function_void_caller<boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> >
, luabind::detail::proxy_function_caller<Ret, boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> > >::type proxy_type;
return proxy_type(L, 0, &detail::resume_impl, args);
} return proxy_type(L, 0, &detail::resume_impl, args);
}
#undef LUABIND_OPERATOR_PARAMS
#undef LUABIND_TUPLE_PARAMS #undef LUABIND_OPERATOR_PARAMS
#undef LUABIND_TUPLE_PARAMS
#endif #endif
#endif

View file

@ -1,363 +1,364 @@
// Copyright (c) 2003 Daniel Wallin and Arvid Norberg // Copyright (c) 2003 Daniel Wallin and Arvid Norberg
// Permission is hereby granted, free of charge, to any person obtaining a // Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"), // copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation // to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, // the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the // 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: // Software is furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included // The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software. // in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
// ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED // ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT // PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
// SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR // SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
// ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN // ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
// OR OTHER DEALINGS IN THE SOFTWARE. // OR OTHER DEALINGS IN THE SOFTWARE.
#if !BOOST_PP_IS_ITERATING #if !BOOST_PP_IS_ITERATING
#ifndef LUABIND_CALL_MEMBER_HPP_INCLUDED #ifndef LUABIND_CALL_MEMBER_HPP_INCLUDED
#define LUABIND_CALL_MEMBER_HPP_INCLUDED #define LUABIND_CALL_MEMBER_HPP_INCLUDED
#include <luabind/config.hpp> #include <luabind/config.hpp>
#include <luabind/detail/convert_to_lua.hpp> #include <luabind/detail/convert_to_lua.hpp>
#include <luabind/detail/pcall.hpp> #include <luabind/detail/pcall.hpp>
#include <luabind/error.hpp> #include <luabind/error.hpp>
#include <luabind/detail/stack_utils.hpp> #include <luabind/detail/stack_utils.hpp>
#include <luabind/object.hpp> // TODO: REMOVE DEPENDENCY #include <luabind/object.hpp> // TODO: REMOVE DEPENDENCY
#include <boost/tuple/tuple.hpp> #include <boost/tuple/tuple.hpp>
#include <boost/preprocessor/control/if.hpp> #include <boost/preprocessor/control/if.hpp>
#include <boost/preprocessor/facilities/expand.hpp> #include <boost/preprocessor/facilities/expand.hpp>
#include <boost/preprocessor/repetition/enum.hpp> #include <boost/preprocessor/repetition/enum.hpp>
#include <boost/mpl/apply_wrap.hpp> #include <boost/mpl/apply_wrap.hpp>
namespace luabind namespace luabind
{ {
namespace detail namespace detail
{ {
namespace mpl = boost::mpl; namespace mpl = boost::mpl;
// if the proxy_member_caller returns non-void // if the proxy_member_caller returns non-void
template<class Ret, class Tuple> template<class Ret, class Tuple>
class proxy_member_caller class proxy_member_caller
{ {
// friend class luabind::object; // friend class luabind::object;
public: public:
proxy_member_caller(lua_State* L_, const Tuple args) proxy_member_caller(lua_State* L_, const Tuple args)
: L(L_) : L(L_)
, m_args(args) , m_args(args)
, m_called(false) , m_called(false)
{ {
} }
proxy_member_caller(const proxy_member_caller& rhs) proxy_member_caller(const proxy_member_caller& rhs)
: L(rhs.L) : L(rhs.L)
, m_args(rhs.m_args) , m_args(rhs.m_args)
, m_called(rhs.m_called) , m_called(rhs.m_called)
{ {
rhs.m_called = true; rhs.m_called = true;
} }
~proxy_member_caller() ~proxy_member_caller()
{ {
if (m_called) return; if (m_called) return;
m_called = true; m_called = true;
// don't count the function and self-reference // don't count the function and self-reference
// since those will be popped by pcall // since those will be popped by pcall
int top = lua_gettop(L) - 2; int top = lua_gettop(L) - 2;
// pcall will pop the function and self reference // pcall will pop the function and self reference
// and all the parameters // and all the parameters
push_args_from_tuple<1>::apply(L, m_args); push_args_from_tuple<1>::apply(L, m_args);
if (pcall(L, boost::tuples::length<Tuple>::value + 1, 0)) if (pcall(L, boost::tuples::length<Tuple>::value + 1, 0))
{ {
assert(lua_gettop(L) == top + 1); assert(lua_gettop(L) == top + 1);
#ifndef LUABIND_NO_EXCEPTIONS #ifndef LUABIND_NO_EXCEPTIONS
throw luabind::error(L); throw luabind::error(L);
#else #else
error_callback_fun e = get_error_callback(); error_callback_fun e = get_error_callback();
if (e) e(L); if (e) e(L);
assert(0 && "the lua function threw an error and exceptions are disabled." assert(0 && "the lua function threw an error and exceptions are disabled."
"If you want to handle this error use luabind::set_error_callback()"); "If you want to handle this error use luabind::set_error_callback()");
std::terminate(); std::terminate();
#endif #endif
} }
// pops the return values from the function // pops the return values from the function
stack_pop pop(L, lua_gettop(L) - top); stack_pop pop(L, lua_gettop(L) - top);
} }
operator Ret() operator Ret()
{ {
typename mpl::apply_wrap2<default_policy,Ret,lua_to_cpp>::type converter; typename mpl::apply_wrap2<default_policy,Ret,lua_to_cpp>::type converter;
m_called = true; m_called = true;
// don't count the function and self-reference // don't count the function and self-reference
// since those will be popped by pcall // since those will be popped by pcall
int top = lua_gettop(L) - 2; int top = lua_gettop(L) - 2;
// pcall will pop the function and self reference // pcall will pop the function and self reference
// and all the parameters // and all the parameters
push_args_from_tuple<1>::apply(L, m_args); push_args_from_tuple<1>::apply(L, m_args);
if (pcall(L, boost::tuples::length<Tuple>::value + 1, 1)) if (pcall(L, boost::tuples::length<Tuple>::value + 1, 1))
{ {
assert(lua_gettop(L) == top + 1); assert(lua_gettop(L) == top + 1);
#ifndef LUABIND_NO_EXCEPTIONS #ifndef LUABIND_NO_EXCEPTIONS
throw luabind::error(L); throw luabind::error(L);
#else #else
error_callback_fun e = get_error_callback(); error_callback_fun e = get_error_callback();
if (e) e(L); if (e) e(L);
assert(0 && "the lua function threw an error and exceptions are disabled." assert(0 && "the lua function threw an error and exceptions are disabled."
"If you want to handle this error use luabind::set_error_callback()"); "If you want to handle this error use luabind::set_error_callback()");
std::terminate(); std::terminate();
#endif #endif
} }
// pops the return values from the function // pops the return values from the function
stack_pop pop(L, lua_gettop(L) - top); stack_pop pop(L, lua_gettop(L) - top);
#ifndef LUABIND_NO_ERROR_CHECKING #ifndef LUABIND_NO_ERROR_CHECKING
if (converter.match(L, LUABIND_DECORATE_TYPE(Ret), -1) < 0) if (converter.match(L, LUABIND_DECORATE_TYPE(Ret), -1) < 0)
{ {
assert(lua_gettop(L) == top + 1); assert(lua_gettop(L) == top + 1);
#ifndef LUABIND_NO_EXCEPTIONS #ifndef LUABIND_NO_EXCEPTIONS
throw cast_failed(L, typeid(Ret)); throw cast_failed(L, typeid(Ret));
#else #else
cast_failed_callback_fun e = get_cast_failed_callback(); cast_failed_callback_fun e = get_cast_failed_callback();
if (e) e(L, typeid(Ret)); if (e) e(L, typeid(Ret));
assert(0 && "the lua function's return value could not be converted." assert(0 && "the lua function's return value could not be converted."
"If you want to handle this error use luabind::set_error_callback()"); "If you want to handle this error use luabind::set_error_callback()");
std::terminate(); std::terminate();
#endif #endif
} }
#endif #endif
return converter.apply(L, LUABIND_DECORATE_TYPE(Ret), -1); return converter.apply(L, LUABIND_DECORATE_TYPE(Ret), -1);
} }
template<class Policies> template<class Policies>
Ret operator[](const Policies& p) Ret operator[](const Policies& p)
{ {
typedef typename find_conversion_policy<0, Policies>::type converter_policy; typedef typename find_conversion_policy<0, Policies>::type converter_policy;
typename mpl::apply_wrap2<converter_policy,Ret,lua_to_cpp>::type converter; typename mpl::apply_wrap2<converter_policy,Ret,lua_to_cpp>::type converter;
m_called = true; m_called = true;
// don't count the function and self-reference // don't count the function and self-reference
// since those will be popped by pcall // since those will be popped by pcall
int top = lua_gettop(L) - 2; int top = lua_gettop(L) - 2;
// pcall will pop the function and self reference // pcall will pop the function and self reference
// and all the parameters // and all the parameters
detail::push_args_from_tuple<1>::apply(L, m_args, p); detail::push_args_from_tuple<1>::apply(L, m_args, p);
if (pcall(L, boost::tuples::length<Tuple>::value + 1, 1)) if (pcall(L, boost::tuples::length<Tuple>::value + 1, 1))
{ {
assert(lua_gettop(L) == top + 1); assert(lua_gettop(L) == top + 1);
#ifndef LUABIND_NO_EXCEPTIONS #ifndef LUABIND_NO_EXCEPTIONS
throw error(L); throw error(L);
#else #else
error_callback_fun e = get_error_callback(); error_callback_fun e = get_error_callback();
if (e) e(L); if (e) e(L);
assert(0 && "the lua function threw an error and exceptions are disabled." assert(0 && "the lua function threw an error and exceptions are disabled."
"If you want to handle this error use luabind::set_error_callback()"); "If you want to handle this error use luabind::set_error_callback()");
std::terminate(); std::terminate();
#endif #endif
} }
// pops the return values from the function // pops the return values from the function
stack_pop pop(L, lua_gettop(L) - top); stack_pop pop(L, lua_gettop(L) - top);
#ifndef LUABIND_NO_ERROR_CHECKING #ifndef LUABIND_NO_ERROR_CHECKING
if (converter.match(L, LUABIND_DECORATE_TYPE(Ret), -1) < 0) if (converter.match(L, LUABIND_DECORATE_TYPE(Ret), -1) < 0)
{ {
assert(lua_gettop(L) == top + 1); assert(lua_gettop(L) == top + 1);
#ifndef LUABIND_NO_EXCEPTIONS #ifndef LUABIND_NO_EXCEPTIONS
throw cast_failed(L, typeid(Ret)); throw cast_failed(L, typeid(Ret));
#else #else
cast_failed_callback_fun e = get_cast_failed_callback(); cast_failed_callback_fun e = get_cast_failed_callback();
if (e) e(L, typeid(Ret)); if (e) e(L, typeid(Ret));
assert(0 && "the lua function's return value could not be converted." assert(0 && "the lua function's return value could not be converted."
"If you want to handle this error use luabind::set_error_callback()"); "If you want to handle this error use luabind::set_error_callback()");
std::terminate(); std::terminate();
#endif #endif
} }
#endif #endif
return converter.apply(L, LUABIND_DECORATE_TYPE(Ret), -1); return converter.apply(L, LUABIND_DECORATE_TYPE(Ret), -1);
} }
private: private:
lua_State* L; lua_State* L;
Tuple m_args; Tuple m_args;
mutable bool m_called; mutable bool m_called;
}; };
// if the proxy_member_caller returns void // if the proxy_member_caller returns void
template<class Tuple> template<class Tuple>
class proxy_member_void_caller class proxy_member_void_caller
{ {
friend class luabind::object; friend class luabind::object;
public: public:
proxy_member_void_caller(lua_State* L_, const Tuple args) proxy_member_void_caller(lua_State* L_, const Tuple args)
: L(L_) : L(L_)
, m_args(args) , m_args(args)
, m_called(false) , m_called(false)
{ {
} }
proxy_member_void_caller(const proxy_member_void_caller& rhs) proxy_member_void_caller(const proxy_member_void_caller& rhs)
: L(rhs.L) : L(rhs.L)
, m_args(rhs.m_args) , m_args(rhs.m_args)
, m_called(rhs.m_called) , m_called(rhs.m_called)
{ {
rhs.m_called = true; rhs.m_called = true;
} }
~proxy_member_void_caller() ~proxy_member_void_caller()
{ {
if (m_called) return; if (m_called) return;
m_called = true; m_called = true;
// don't count the function and self-reference // don't count the function and self-reference
// since those will be popped by pcall // since those will be popped by pcall
int top = lua_gettop(L) - 2; int top = lua_gettop(L) - 2;
// pcall will pop the function and self reference // pcall will pop the function and self reference
// and all the parameters // and all the parameters
push_args_from_tuple<1>::apply(L, m_args); push_args_from_tuple<1>::apply(L, m_args);
if (pcall(L, boost::tuples::length<Tuple>::value + 1, 0)) if (pcall(L, boost::tuples::length<Tuple>::value + 1, 0))
{ {
assert(lua_gettop(L) == top + 1); assert(lua_gettop(L) == top + 1);
#ifndef LUABIND_NO_EXCEPTIONS #ifndef LUABIND_NO_EXCEPTIONS
throw luabind::error(L); throw luabind::error(L);
#else #else
error_callback_fun e = get_error_callback(); error_callback_fun e = get_error_callback();
if (e) e(L); if (e) e(L);
assert(0 && "the lua function threw an error and exceptions are disabled." assert(0 && "the lua function threw an error and exceptions are disabled."
"If you want to handle this error use luabind::set_error_callback()"); "If you want to handle this error use luabind::set_error_callback()");
std::terminate(); std::terminate();
#endif #endif
} }
// pops the return values from the function // pops the return values from the function
stack_pop pop(L, lua_gettop(L) - top); stack_pop pop(L, lua_gettop(L) - top);
} }
template<class Policies> template<class Policies>
void operator[](const Policies& p) void operator[](const Policies& p)
{ {
m_called = true; m_called = true;
// don't count the function and self-reference // don't count the function and self-reference
// since those will be popped by pcall // since those will be popped by pcall
int top = lua_gettop(L) - 2; int top = lua_gettop(L) - 2;
// pcall will pop the function and self reference // pcall will pop the function and self reference
// and all the parameters // and all the parameters
detail::push_args_from_tuple<1>::apply(L, m_args, p); detail::push_args_from_tuple<1>::apply(L, m_args, p);
if (pcall(L, boost::tuples::length<Tuple>::value + 1, 0)) if (pcall(L, boost::tuples::length<Tuple>::value + 1, 0))
{ {
assert(lua_gettop(L) == top + 1); assert(lua_gettop(L) == top + 1);
#ifndef LUABIND_NO_EXCEPTIONS #ifndef LUABIND_NO_EXCEPTIONS
throw error(L); throw error(L);
#else #else
error_callback_fun e = get_error_callback(); error_callback_fun e = get_error_callback();
if (e) e(L); if (e) e(L);
assert(0 && "the lua function threw an error and exceptions are disabled." assert(0 && "the lua function threw an error and exceptions are disabled."
"If you want to handle this error use luabind::set_error_callback()"); "If you want to handle this error use luabind::set_error_callback()");
std::terminate(); std::terminate();
#endif #endif
} }
// pops the return values from the function // pops the return values from the function
stack_pop pop(L, lua_gettop(L) - top); stack_pop pop(L, lua_gettop(L) - top);
} }
private: private:
lua_State* L; lua_State* L;
Tuple m_args; Tuple m_args;
mutable bool m_called; mutable bool m_called;
}; };
} // detail } // detail
#define BOOST_PP_ITERATION_PARAMS_1 (4, (0, LUABIND_MAX_ARITY, <luabind/detail/call_member.hpp>, 1)) #define BOOST_PP_ITERATION_PARAMS_1 (4, (0, LUABIND_MAX_ARITY, <luabind/detail/call_member.hpp>, 1))
#include BOOST_PP_ITERATE() #include BOOST_PP_ITERATE()
} }
#endif // LUABIND_CALL_MEMBER_HPP_INCLUDED #endif // LUABIND_CALL_MEMBER_HPP_INCLUDED
#elif BOOST_PP_ITERATION_FLAGS() == 1 #else // FF dexter gcc fix
#if BOOST_PP_ITERATION_FLAGS() == 1
#define LUABIND_TUPLE_PARAMS(z, n, data) const A##n *
#define LUABIND_OPERATOR_PARAMS(z, n, data) const A##n & a##n #define LUABIND_TUPLE_PARAMS(z, n, data) const A##n *
#define LUABIND_OPERATOR_PARAMS(z, n, data) const A##n & a##n
template<class R BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), class A)>
typename boost::mpl::if_<boost::is_void<R> template<class R BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), class A)>
, luabind::detail::proxy_member_void_caller<boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> > typename boost::mpl::if_<boost::is_void<R>
, luabind::detail::proxy_member_caller<R, boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> > >::type , luabind::detail::proxy_member_void_caller<boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> >
call_member(object const& obj, const char* name BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_OPERATOR_PARAMS, _)) , luabind::detail::proxy_member_caller<R, boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> > >::type
{ call_member(object const& obj, const char* name BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_OPERATOR_PARAMS, _))
typedef boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> tuple_t; {
#if BOOST_PP_ITERATION() == 0 typedef boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> tuple_t;
tuple_t args; #if BOOST_PP_ITERATION() == 0
#else tuple_t args;
tuple_t args(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), &a)); #else
#endif tuple_t args(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), &a));
#endif
typedef typename boost::mpl::if_<boost::is_void<R>
, luabind::detail::proxy_member_void_caller<boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> > typedef typename boost::mpl::if_<boost::is_void<R>
, luabind::detail::proxy_member_caller<R, boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> > >::type proxy_type; , luabind::detail::proxy_member_void_caller<boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> >
, luabind::detail::proxy_member_caller<R, boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> > >::type proxy_type;
// this will be cleaned up by the proxy object
// once the call has been made // this will be cleaned up by the proxy object
// once the call has been made
// get the function
obj.push(obj.interpreter()); // get the function
lua_pushstring(obj.interpreter(), name); obj.push(obj.interpreter());
lua_gettable(obj.interpreter(), -2); lua_pushstring(obj.interpreter(), name);
// duplicate the self-object lua_gettable(obj.interpreter(), -2);
lua_pushvalue(obj.interpreter(), -2); // duplicate the self-object
// remove the bottom self-object lua_pushvalue(obj.interpreter(), -2);
lua_remove(obj.interpreter(), -3); // remove the bottom self-object
lua_remove(obj.interpreter(), -3);
// now the function and self objects
// are on the stack. These will both // now the function and self objects
// be popped by pcall // are on the stack. These will both
return proxy_type(obj.interpreter(), args); // be popped by pcall
} return proxy_type(obj.interpreter(), args);
}
#undef LUABIND_OPERATOR_PARAMS
#undef LUABIND_TUPLE_PARAMS #undef LUABIND_OPERATOR_PARAMS
#undef LUABIND_TUPLE_PARAMS
#endif #endif
#endif

View file

@ -1,190 +1,191 @@
// Copyright (c) 2003 Daniel Wallin and Arvid Norberg // Copyright (c) 2003 Daniel Wallin and Arvid Norberg
// Permission is hereby granted, free of charge, to any person obtaining a // Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"), // copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation // to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, // the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the // 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: // Software is furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included // The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software. // in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
// ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED // ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT // PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
// SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR // SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
// ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN // ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
// OR OTHER DEALINGS IN THE SOFTWARE. // OR OTHER DEALINGS IN THE SOFTWARE.
#if !BOOST_PP_IS_ITERATING #if !BOOST_PP_IS_ITERATING
#ifndef LUABIND_WRAPPER_BASE_HPP_INCLUDED #ifndef LUABIND_WRAPPER_BASE_HPP_INCLUDED
#define LUABIND_WRAPPER_BASE_HPP_INCLUDED #define LUABIND_WRAPPER_BASE_HPP_INCLUDED
#include <luabind/config.hpp> #include <luabind/config.hpp>
#include <luabind/weak_ref.hpp> #include <luabind/weak_ref.hpp>
#include <luabind/detail/ref.hpp> #include <luabind/detail/ref.hpp>
#include <luabind/detail/call_member.hpp> #include <luabind/detail/call_member.hpp>
#include <boost/preprocessor/repetition/enum_trailing_params.hpp> #include <boost/preprocessor/repetition/enum_trailing_params.hpp>
#include <boost/preprocessor/repetition/enum_trailing_binary_params.hpp> #include <boost/preprocessor/repetition/enum_trailing_binary_params.hpp>
#include <stdexcept> #include <stdexcept>
namespace luabind namespace luabind
{ {
namespace detail namespace detail
{ {
struct wrap_access; struct wrap_access;
// implements the selection between dynamic dispatch // implements the selection between dynamic dispatch
// or default implementation calls from within a virtual // or default implementation calls from within a virtual
// function wrapper. The input is the self reference on // function wrapper. The input is the self reference on
// the top of the stack. Output is the function to call // the top of the stack. Output is the function to call
// on the top of the stack (the input self reference will // on the top of the stack (the input self reference will
// be popped) // be popped)
LUABIND_API void do_call_member_selection(lua_State* L, char const* name); LUABIND_API void do_call_member_selection(lua_State* L, char const* name);
} }
struct wrapped_self_t: weak_ref struct wrapped_self_t: weak_ref
{ {
detail::lua_reference m_strong_ref; detail::lua_reference m_strong_ref;
}; };
struct wrap_base struct wrap_base
{ {
friend struct detail::wrap_access; friend struct detail::wrap_access;
wrap_base() {} wrap_base() {}
#define BOOST_PP_ITERATION_PARAMS_1 (4, (0, LUABIND_MAX_ARITY, <luabind/wrapper_base.hpp>, 1)) #define BOOST_PP_ITERATION_PARAMS_1 (4, (0, LUABIND_MAX_ARITY, <luabind/wrapper_base.hpp>, 1))
#include BOOST_PP_ITERATE() #include BOOST_PP_ITERATE()
private: private:
wrapped_self_t m_self; wrapped_self_t m_self;
}; };
#define BOOST_PP_ITERATION_PARAMS_1 (4, (0, LUABIND_MAX_ARITY, <luabind/wrapper_base.hpp>, 2)) #define BOOST_PP_ITERATION_PARAMS_1 (4, (0, LUABIND_MAX_ARITY, <luabind/wrapper_base.hpp>, 2))
#include BOOST_PP_ITERATE() #include BOOST_PP_ITERATE()
namespace detail namespace detail
{ {
struct wrap_access struct wrap_access
{ {
static wrapped_self_t const& ref(wrap_base const& b) static wrapped_self_t const& ref(wrap_base const& b)
{ {
return b.m_self; return b.m_self;
} }
static wrapped_self_t& ref(wrap_base& b) static wrapped_self_t& ref(wrap_base& b)
{ {
return b.m_self; return b.m_self;
} }
}; };
} }
} }
#endif // LUABIND_WRAPPER_BASE_HPP_INCLUDED #endif // LUABIND_WRAPPER_BASE_HPP_INCLUDED
#elif BOOST_PP_ITERATION_FLAGS() == 1 #else // FF dexter gcc fix
#if BOOST_PP_ITERATION_FLAGS() == 1
#define LUABIND_TUPLE_PARAMS(z, n, data) const A##n *
#define LUABIND_OPERATOR_PARAMS(z, n, data) const A##n & a##n #define LUABIND_TUPLE_PARAMS(z, n, data) const A##n *
#define LUABIND_OPERATOR_PARAMS(z, n, data) const A##n & a##n
template<class R BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), class A)>
typename boost::mpl::if_<boost::is_void<R> template<class R BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), class A)>
, luabind::detail::proxy_member_void_caller<boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> > typename boost::mpl::if_<boost::is_void<R>
, luabind::detail::proxy_member_caller<R, boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> > >::type , luabind::detail::proxy_member_void_caller<boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> >
call(char const* name BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_OPERATOR_PARAMS, _), detail::type_<R>* = 0) const , luabind::detail::proxy_member_caller<R, boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> > >::type
{ call(char const* name BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_OPERATOR_PARAMS, _), detail::type_<R>* = 0) const
typedef boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> tuple_t; {
#if BOOST_PP_ITERATION() == 0 typedef boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> tuple_t;
tuple_t args; #if BOOST_PP_ITERATION() == 0
#else tuple_t args;
tuple_t args(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), &a)); #else
#endif tuple_t args(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), &a));
#endif
typedef typename boost::mpl::if_<boost::is_void<R>
, luabind::detail::proxy_member_void_caller<boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> > typedef typename boost::mpl::if_<boost::is_void<R>
, luabind::detail::proxy_member_caller<R, boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> > >::type proxy_type; , luabind::detail::proxy_member_void_caller<boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> >
, luabind::detail::proxy_member_caller<R, boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> > >::type proxy_type;
// this will be cleaned up by the proxy object
// once the call has been made // this will be cleaned up by the proxy object
// once the call has been made
// TODO: what happens if this virtual function is
// dispatched from a lua thread where the state // TODO: what happens if this virtual function is
// pointer is different? // dispatched from a lua thread where the state
// pointer is different?
// get the function
lua_State* L = m_self.state(); // get the function
m_self.get(L); lua_State* L = m_self.state();
assert(!lua_isnil(L, -1)); m_self.get(L);
detail::do_call_member_selection(L, name); assert(!lua_isnil(L, -1));
detail::do_call_member_selection(L, name);
if (lua_isnil(L, -1))
{ if (lua_isnil(L, -1))
lua_pop(L, 1); {
throw std::runtime_error("Attempt to call nonexistent function"); lua_pop(L, 1);
} throw std::runtime_error("Attempt to call nonexistent function");
}
// push the self reference as the first parameter
m_self.get(L); // push the self reference as the first parameter
m_self.get(L);
// now the function and self objects
// are on the stack. These will both // now the function and self objects
// be popped by pcall // are on the stack. These will both
return proxy_type(L, args); // be popped by pcall
} return proxy_type(L, args);
}
#undef LUABIND_CALL_MEMBER_NAME
#undef LUABIND_OPERATOR_PARAMS #undef LUABIND_CALL_MEMBER_NAME
#undef LUABIND_TUPLE_PARAMS #undef LUABIND_OPERATOR_PARAMS
#undef LUABIND_TUPLE_PARAMS
#else // free call_member forwardarding functions #else // free call_member forwardarding functions
#define N BOOST_PP_ITERATION() #define N BOOST_PP_ITERATION()
#define LUABIND_TUPLE_PARAMS(z, n, data) const A##n * #define LUABIND_TUPLE_PARAMS(z, n, data) const A##n *
#define LUABIND_OPERATOR_PARAMS(z, n, data) const A##n & a##n #define LUABIND_OPERATOR_PARAMS(z, n, data) const A##n & a##n
template< template<
class R class R
BOOST_PP_ENUM_TRAILING_PARAMS(N, class A) BOOST_PP_ENUM_TRAILING_PARAMS(N, class A)
> >
typename boost::mpl::if_< typename boost::mpl::if_<
boost::is_void<R> boost::is_void<R>
, detail::proxy_member_void_caller< , detail::proxy_member_void_caller<
boost::tuples::tuple< boost::tuples::tuple<
BOOST_PP_ENUM(N, LUABIND_TUPLE_PARAMS, _) BOOST_PP_ENUM(N, LUABIND_TUPLE_PARAMS, _)
> >
> >
, detail::proxy_member_caller< , detail::proxy_member_caller<
R R
, boost::tuples::tuple< , boost::tuples::tuple<
BOOST_PP_ENUM(N, LUABIND_TUPLE_PARAMS, _) BOOST_PP_ENUM(N, LUABIND_TUPLE_PARAMS, _)
> >
> >
>::type >::type
call_member( call_member(
wrap_base const* self wrap_base const* self
, char const* fn , char const* fn
BOOST_PP_ENUM_TRAILING_BINARY_PARAMS(N, A, &a) BOOST_PP_ENUM_TRAILING_BINARY_PARAMS(N, A, &a)
, detail::type_<R>* = 0 , detail::type_<R>* = 0
) )
{ {
return self->call( return self->call(
fn fn
BOOST_PP_ENUM_TRAILING_PARAMS(N, a) BOOST_PP_ENUM_TRAILING_PARAMS(N, a)
, (detail::type_<R>*)0 , (detail::type_<R>*)0
); );
} }
#undef LUABIND_OPERATOR_PARAMS #undef LUABIND_OPERATOR_PARAMS
#undef LUABIND_TUPLE_PARAMS #undef LUABIND_TUPLE_PARAMS
#undef N #undef N
#endif #endif
#endif