45 template<
typename Tuple>
47 typedef typename std::tuple_element<N-1, Tuple>::type ValueType;
54 template<
typename Tuple>
59 template<
typename Ret,
typename F,
typename... Args>
60 typename std::enable_if<!std::is_void<Ret>::value,
int>::type
68 template<
typename Ret,
typename F,
typename... Args>
69 typename std::enable_if<std::is_void<Ret>::value,
int>::type
76 template<
int N,
typename Ret>
78 template<
typename Tuple,
typename F,
typename... Args>
79 static int call(
const Tuple& tuple,
const F& f,
LuaInterface* lua,
const Args&... args) {
83 template<
typename Ret>
85 template<
typename Tuple,
typename F,
typename... Args>
86 static int call(
const Tuple& tuple,
const F& f,
LuaInterface* lua,
const Args&... args) {
87 return call_fun_and_push_result<Ret>(f, lua, args...);
92 template<
typename Ret,
typename F,
typename Tuple>
94 enum { N = std::tuple_size<Tuple>::value };
96 while(lua->stackSize() != N) {
97 if(lua->stackSize() < N)
115 template<
typename Ret,
typename... Args>
117 typedef typename std::tuple<typename stdext::remove_const_ref<Args>::type...> Tuple;
118 return bind_fun_specializer<typename stdext::remove_const_ref<Ret>::type,
127 template<
typename Lambda,
typename Ret,
typename... Args>
130 typedef typename std::tuple<typename stdext::remove_const_ref<Args>::type...> Tuple;
131 return bind_fun_specializer<typename stdext::remove_const_ref<Ret>::type,
138 template<
typename Lambda>
139 typename std::enable_if<std::is_constructible<decltype(&Lambda::operator())>::value,
LuaCppFunction>::type
bind_fun(
const Lambda& f) {
140 typedef decltype(&Lambda::operator()) F;
145 template<
typename Ret,
typename... Args>
147 return bind_fun(std::function<Ret(Args...)>(f));
151 template<
typename Ret,
typename C,
typename... Args>
153 auto mf = std::mem_fn(f);
156 throw LuaException(
"failed to call a member function because the passed object is nil");
157 return mf(obj.
get(), args...);
160 template<
typename C,
typename... Args>
162 auto mf = std::mem_fn(f);
165 throw LuaException(
"failed to call a member function because the passed object is nil");
166 mf(obj.
get(), args...);
171 template<
typename Ret,
typename C,
typename... Args>
173 auto mf = std::mem_fn(f);
174 return [=](Args... args)
mutable -> Ret {
return mf(instance, args...); };
176 template<
typename C,
typename... Args>
178 auto mf = std::mem_fn(f);
179 return [=](Args... args)
mutable ->
void { mf(instance, args...); };
184 template<
typename C,
typename Ret,
class FC,
typename... Args>
187 auto lambda = make_mem_func<Ret,FC>(f);
188 return bind_fun_specializer<typename stdext::remove_const_ref<Ret>::type,
194 template<
typename C,
typename Ret,
class FC,
typename... Args>
196 typedef typename std::tuple<typename stdext::remove_const_ref<Args>::type...> Tuple;
198 auto lambda = make_mem_func_singleton<Ret,FC>(f,
static_cast<FC*
>(instance));
199 return bind_fun_specializer<typename stdext::remove_const_ref<Ret>::type,
207 auto mf = std::mem_fn(f);