#include #include #include #include #include #define lua_check(x) if(x != LUA_OK) printf("ERR: %s\n", lua_tostring(L, -1)) #define LUA_ARGS lua_State* L #define arg(type) lua_to##type(L, 1) int logfn(LUA_ARGS) { const char* value = arg(string); printf("[LOG] %s\n", value); return 0; } int main() { lua_State* L = luaL_newstate(); assert(L != NULL); luaL_openlibs(L); lua_pushcfunction(L, logfn); lua_setglobal(L, "log"); lua_check(luaL_dofile(L, "test.lua")); void* data = lua_newuserdata(L); }