Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <lua.h>
- #include <lualib.h>
- #include <lauxlib.h>
- static int counter = 0;
- #if LUA_VERSION_NUM <= 503
- #define lua_resumec(state, from, nargs, res) lua_resume(state, from, nargs)
- #else
- #define lua_resumec(state, from, nargs, res) lua_resume(state, from, nargs, res)
- #endif
- static int test(lua_State* L) {
- if(counter < 10) {
- counter++;
- lua_getglobal(L, "TestFunction");
- lua_pcall(L, 0, 1, 0);
- } else
- lua_pushstring(L, "TEST");
- return 1;
- }
- int main() {
- lua_State* lua_state = luaL_newstate();
- luaL_openlibs(lua_state);
- lua_register(lua_state, "TestFunction", test);
- const char lua_script[] = "print(TestFunction())";
- luaL_loadbuffer(lua_state, lua_script, sizeof(lua_script) - 1, lua_script);
- lua_pcall(lua_state, 0, 0, 0);
- counter = 0;
- lua_State* rthread = lua_newthread(lua_state);
- luaL_loadbuffer(rthread, lua_script, sizeof(lua_script) - 1, lua_script);
- int result = lua_resumec(rthread, 0, 0, &result);
- lua_close(lua_state);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement