| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 
 | template <typename Ret, typename... Args>
 typename std::enable_if<!std::is_void<Ret>::value, std::function<Ret(Args...)> >::type 
  _get(_id<std::function<Ret(Args...)> >, lua_State *l, const int index) 
{
	lua_pushvalue(l, index);
	auto lambda = [l](Args... args) -> Ret {
		//Get the reference
		lua_rawgeti(l, LUA_REGISTRYINDEX, luaL_ref(l, LUA_REGISTRYINDEX));
		State s(l);
		//Push the arguments on the stack
		s.push(args...);
		constexpr int num_args = sizeof...(Args);
		//Call the function
        lua_call(l, num_args, 1);
        Ret ret = s.read<Ret>(-1);
        lua_settop(l, 0);
        return ret;
	};
    return lambda;
}
 
template <typename Ret, typename... Args>
 typename std::enable_if<std::is_void<Ret>::value, std::function<Ret(Args...)> >::type 
 _get(_id<std::function<Ret(Args...)> >, lua_State *l, const int index) 
{
	lua_pushvalue(l, index);
	auto lambda = [l](Args... args) {
		//Get the reference
		lua_rawgeti(l, LUA_REGISTRYINDEX, luaL_ref(l, LUA_REGISTRYINDEX));
		State s(l);
		//Push the arguments on the stack
		s.push(args...);
		constexpr int num_args = sizeof...(Args);
		//Call the function
        lua_call(l, num_args, 1);
        lua_settop(l, 0);
	};
    return lambda;
} | 
Partager