[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: yield from C debug hook on a coroutine in LuaJIT 2.1 beta2
- From: Ye Xing <ealexing@...>
- Date: Wed, 22 Jun 2016 07:11:41 +0800
Is it possible to yield form a debug hook on a coroutine in LuaJIT 2.1?
I got an error "attempt to yield across C-call boundary."
Here is the code:
//hook.c
//-----------------------------------------------------------
#include "lua.h"
#include "lauxlib.h"
static void hook(lua_State *L, lua_Debug *ar) {
printf("hooked\n");
lua_yield(L,0);
}
static int sethook(lua_State *L) {
lua_State *L1 = lua_tothread(L, 1);
lua_sethook(L1, hook, LUA_MASKLINE, 0);
return 0;
}
int luaopen_hook(lua_State *L) {
lua_pushcfunction(L, sethook);
// lua_setglobal(L, "sethook");
return 1;
}
--hook.lua
-----------------------------------------------------
local co = coroutine.create(function()
print(1)
print(2)
print(3)
end)
local hook = require "hook"
hook(co)
print(coroutine.resume(co))
commands to compile the .so file
------------------------------------------------------
LUA_DIR=“./luajit-2.0/src"
LUA_LIB="luajit"
gcc -I$LUA_DIR -c hook.c -o hook.o
gcc -L$LUA_DIR -l$LUA_LIB hook.o -o hook.so -shared
It's on OS X 10.11.5 and Xcode 7.3.1