lua-users home
lua-l archive

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

If I call lua_yield(L,0) from a lua_Hook function , and then call lua_getlocal on this yielded thread, it crashes. (Both on lua 5.2 and lua 5.3)

local hook = require "hook"

local co = coroutine.create(function(a)
return a
coroutine.resume(co, 1)
debug.getlocal(co, 0, 1)   -- crashes
#include <lua.h>
#include <lauxlib.h>

static void
lhook(lua_State *L, lua_Debug *ar) {

static int
hook(lua_State *L) {
lua_State *L1 = lua_tothread(L, 1);
lua_sethook(L1, lhook, LUA_MASKLINE, 0);
return 0;

luaopen_hook(lua_State *L) {
lua_pushcfunction(L, hook);
return 1;

I guess the reason is : when yield from a hook, the top function in the yielded thread is a lua function, but the L->ci->func is not a valid lua function object. so lua_getlocal (and other debug api) can't work.