Created
June 15, 2014 04:27
-
-
Save azyu/d4e0feda04ddbe2d9f45 to your computer and use it in GitHub Desktop.
lua_tinker call with variadic templates (Visual Studio 2013)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#if _MSC_VER >= 1800 | |
template<typename T, typename ... TArgs> | |
void push(lua_State *L, T ret, const TArgs& ... args) { push(L, ret); push(L, args...); } | |
template<typename RVal, typename ... TArgs> | |
RVal call(lua_State* L, const char* name, const TArgs&... args) | |
{ | |
lua_pushcclosure(L, on_error, 0); | |
int errfunc = lua_gettop(L); | |
lua_getglobal(L, name); | |
if (lua_isfunction(L, -1)) | |
{ | |
push(L, args...); | |
if (lua_pcall(L, sizeof...(args), 1, errfunc) != 0) | |
{ | |
lua_pop(L, 1); | |
} | |
} | |
else | |
{ | |
print_error(L, "lua_tinker::call() attempt to call global `%s' (not a function)", name); | |
} | |
lua_remove(L, -2); | |
return pop<RVal>(L); | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Lua
C++
Result is 78.