lua-users home
lua-l archive

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

Jonathan Shaw wrote:
> We've come across an interesting behaviour when calling a
> function in the context of a coroutine that's yielded.

The only thing you're allowed to do with a coroutine in yielded
state is to resume it. Calling a function on a lua_State object
which is in any state other than 0 (as returned by lua_status())
is invoking undefined behavior.

You may get away with it in the current version of Lua, but that's
not a guarantee for future versions or different VMs implementing
the Lua ABI. The problem you've just discovered illustrates one
meaning of 'undefined'.

In general it's not advisable to mix resume/yield and call/pcall
on the same lua_State. Lua states/coroutines are cheap to create,
so better create extra ones for different purposes.

Summary: not a bug in Lua, please fix your application.