lua-users home
lua-l archive

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


On Thu, Jul 31, 2008 at 4:21 AM, Ivan Gagis <igagis@gmail.com> wrote:
> Hi Patrick,
>
> i'm not sure how can I achieve that with debug hooks. I can set a callback
> to be called when every ,say, 10 instructions are executed, but then I need
> to see how much time they were executing and then execute other lua thread
> (lua_state). How can I do this from within the called callback function? if
> I return from this function the same lua_State will continue execution...

What you are asking for should be done in coroutines; that is, you
want a function to be resumable and the thread to yield after a
certain number of instructions. You set a debug hook function in C
that will quite simply yield the thread, preferably with a unique
return value you can differentiate from actual return values in your
dispatcher (e.g. a light userdata sentinel). Your dispatcher will then
resume threads constantly until all are finished. For this to work,
you need to somehow handle a thread running other threads using
coroutine.resume (perhaps do nothing if this is acceptable).

Cheers,

-- 
-Patrick Donnelly

"One of the lessons of history is that nothing is often a good thing
to do and always a clever thing to say."

-Will Durant