lua-users home
lua-l archive

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


> [...] That was the perfect occasion
> to dive into Lua 5.2's new lua_yieldk feature. But I'm faced with an
> oddity, which I believe is either a bug or a documentation problem.
> 
> When a first call to lua_resume returns, only the yielded values are
> on the stack. Any other values in the thread stack (in the
> lua_CFunction that called lua_yieldk) are not accessible (but will be
> in the continuation). So far so good. However if I let those return
> values there, push a couple other ones, and call lua_resume with nargs
> equal to 1 or 2, the continuation receives 1) the non returned value
> from the initial coroutine resume at the bottom, 2) the nargs values
> passed to the second resume at the top, but also 3) any other yielded
> values, and any other pushed values before the second call to
> lua_resume. In other words it seems the nargs of a second lua_resume
> seems to be ignored, and all values on the thread stack at the moment
> of the resume are passed to the continuation function.

This is a documentation problem. When a coroutine resumes after the
first time, the stack cannot contain anything besides the arguments to
resume. 'nargs' is mostly ignored (except for error handling and API
checks).

-- Roberto