Hello!
On Tue, May 21, 2013 at 3:54 AM, roelboel wrote:
> Is it correct that one cannot use coroutines inside pcalled environments?
> Here a minimal sample:
>
> local function func()
> local c = coroutine.create(function() coroutine.yield("hello") end)
> coroutine.resume(c)
> end
>
> pcall(func)
>
> fails with "lua entry thread aborted: runtime error: attempt to call a nil
> value" in my nginx error log; removing the pcall and adding () to func works
> though. Is there any work around? I cannot use luaJIT (for complicated
> reasons).
>
Your example works perfectly on my side with LuaJIT 2.0.
You're getting that error with the standard Lua 5.1 interpreter
because it has various limitations in pcall due to the fact that it is
implemented as a C function there. And the coroutine.* API implemented
in ngx_lua (and other nonblocking I/O API like cosockets and
subrequests) requires coroutine yielding right to the top level while
coroutine yielding can never go across the C function call boundary.
Best regards,
-agentzh