fix(api): fail fast if has_lua_imp retval looks wrong #39866

This commit is contained in:
Justin M. Keyes
2026-05-20 11:52:22 -04:00
committed by GitHub
parent 584dfdb76d
commit 9f0ecad6d9
2 changed files with 17 additions and 2 deletions

View File

@@ -1808,6 +1808,9 @@ static int mode_ret(LuaRetMode mode)
Object nlua_call_ref_ctx(bool fast, LuaRef ref, const char *name, Array args, LuaRetMode mode,
Arena *arena, Error *err)
{
// Use active_lstate (set by ENTER_LUA_ACTIVE_STATE in gen_api_dispatch.lua) so callbacks run on
// the caller's Lua thread. This matters for coroutines: with global_lstate, return values pushed
// by kRetMultiStack would land on the main thread's stack, instead of coroutine stack.
lua_State *const lstate = active_lstate;
int top = lua_gettop(lstate);
nlua_pushref(lstate, ref);