lua-users home
lua-l archive

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


On 5/10/07, jm_list@cameraid.com <jm_list@cameraid.com> wrote:
I have been trying to use COPAS to do asynchronous HTTP requests. I keep
getting the "attempt to yield across metamethod/C-call boundary" error
even after I converted my pcalls to calls etc.
......
There could be any number of things causing the metamethod/C-call
yield issue (looks like its somewhere inside your http.request
function..)
.....
For a language as beautifully designed as Lua, the limitations on
coroutines seem very vague and constricting.
The limitations are not for the language, but for the fact that C does
not offer a way to do coroutines itself.
Quick explanation as to why you may run into limitations:

Lua sets up coroutine which does the following:
 - calls a C function
 - C function calls into Lua
 - Lua yields -- ** boom **
 Basic lua 'stack' at this point:
 * Lua: Function that called the C function
 * C Function
 * Lua: Function that yielded

The 'yield' needs to switch the current stack to the one that started
the co-routine, but there is no way to switch a stack when C is
involved.
The better 'fix' is to rework the logic.
The quick fix is to use Coco [1], an extension that allows for
yielding through C functions.  The downside is that you have to (IIRR)
predict how much stack will be used by all C functions inside that
co-routine.  In any case you end up w/ another C stack instead of the
lightweight Lua stack.

http://luajit.luaforge.net/coco.html
--
Thomas Harning Jr.