lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


#include <lua.hpp>
#define QUOTE(...) #__VA_ARGS__

static void call_hook(lua_State *L, lua_Debug *ar){
  printf("call_hook %d %d\n", ar->event, lua_status(L));
  lua_yield(L, 0);
}

int main(int argc, char* argv[]) {
  lua_State *L = luaL_newstate();
  lua_State *l = lua_newthread(L);
  luaL_openlibs(l);
  luaL_loadstring(l, QUOTE(
        print("hello1")
        print("hello2")
        print("hello3")
  ));

  int rc = 1;
  while (rc) {
    int nres;
    lua_sethook(l, call_hook, LUA_MASKCALL, 0);
    rc = lua_resume(l, NULL, 0, &nres);
    printf("rc = %d\n", rc);
  }

  lua_close(L);
}
----------------------------------------------------
output:

call_hook 0 0
call_hook 0 1
rc = 1
hello2
hello3
rc = 0


why print("hello1") disappeared?