Skip to content

Instantly share code, notes, and snippets.

@cloudwu
Created August 25, 2022 02:10
Show Gist options
  • Save cloudwu/29b59a0a35bb009d785fb10eed92deed to your computer and use it in GitHub Desktop.
Save cloudwu/29b59a0a35bb009d785fb10eed92deed to your computer and use it in GitHub Desktop.
Resume lua main thread
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
#include <stdio.h>
const char * source = "print 'A' ; coroutine.yield() ; print 'B'";
int
main() {
lua_State *L = luaL_newstate();
luaL_openlibs(L);
luaL_loadstring(L, source);
printf("step 1\n");
int r;
lua_resume(L, NULL, 0, &r);
printf("step 2\n");
lua_resume(L, NULL, 0, &r);
lua_close(L);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment