Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <lua.h>
- #include <lualib.h>
- #include <lauxlib.h>
- #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
- const char script[] =
- "function TestFunction()\n"
- "if counter < 10 then\n"
- "counter = counter + 1\n"
- "return TestFunction()\n"
- "end\n"
- "return \"TEST\"\n"
- "end\n";
- int main() {
- lua_State* lua_state = luaL_newstate();
- luaL_openlibs(lua_state);
- lua_pushinteger(lua_state, 0);
- lua_setglobal(lua_state, "counter");
- luaL_dostring(lua_state, script);
- const char lua_script[] = "print(TestFunction())";
- luaL_dostring(lua_state, lua_script);
- lua_pushinteger(lua_state, 0);
- lua_setglobal(lua_state, "counter");
- 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