lua-users home
lua-l archive

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


>[Roberto Ierusalimschy <roberto@inf.puc-rio.br>]
>> > Is it possible to yield from the opcode count hook under Lua 5.0 beta?
>> 
>> Yes. Just finish your hook with 
>> 
>>   lua_yield(L, 0);
>
>And this will never cause the "attempt to yield across metamethod/C-call
>boundary" error (that can happen in lua_yield() if L->nCcalls > 0? 

Curious, indeed. I've just got that error message.

Let me describe my program:

It's written in C++. I have objects that are called when a HOOKCOUNT event happens. The object that's called for the count event depends on the lua_State that originated the event. So I have a function (my global hook function) that retrieves a lightuserdata from the registry and calls the appropriated object.

That object, then, calls lua_yield(), and the above described error is thrown.

The object I'm talking about here is used to implement a strategy pattern. Each lua_State has it's own way of handling hook events. For that, each lua_State is associated to an instance of a "hook-object". I use a function to "dispatch" events to the right "hook-object", and then only the "hook-object" calls lua_yield(). That's it. Oh, I'm not sure if it matters or not but all my hook-object methods are virtual.

Is this intentional (and thus an illegal design), or is it a bug?

I tried to move my call to lua_yield() from the hook-object to my "dispatch" function, and then everything worked.

I admit it's a very annoying limitation. Are there other wayouts for me?

Obrigado in advance,
Thiago Bastos