lua-users home
lua-l archive

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



On 12-Oct-05, at 10:44 PM, David Morris-Oliveros wrote:

It asserts on line 4 of the code below. Now my question is, is it supposed to be L->ci->top or just L->top? Because lua_gettop() is (L->top - L->base), and like 9 below is very similar to this.

L->ci->top is the end of the allocated stack (allocated in the sense that you've done lua_checkstack() to make sure that you have that stack space available; if you don't do that, you have 20 slots.) L->top is the top of the actual stack.

If L->ci->top < L->top, something evil has happened (this could happen if you didn't do a lua_checkstack(), but in that case the index would be >20).

It's not an api error to refer to a stack slot that has been allocated, even if it is beyond the end of the current stack. (Although it's highly questionable.) On the other hand, a negative index greater than the current end is clearly a non-existent stack slot. That's why those two lines are different.

I wonder if your problem has to do with the fact that there are two stacks in play when you're doing coroutines. It's pretty easy to use the wrong one by mistake.

Rici