lua-users home
lua-l archive

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



On 15-Dec-06, at 9:52 PM, Andrew Yount wrote:

<snip>
    // function main() = <loaded script>                // STACK  '...'=string    [...]=table   ...()=function   <...>=number   {...}=thread   ?...=boolean     lua_pushstring( p_state, func_name );               // -> 'func_name'     lua_load( p_state, Chunkreader, this, m_package );  // -> 'func_name'  script()     lua_settable( p_state, LUA_GLOBALSINDEX );          // ->                                                                 ( sets func_name = the script function )     lua_pushstring( p_state, "coroutine" );             // -> 'coroutine'

You might find it easier (or at least fewer lines of code)
to create the coroutine with lua_newthread(). You can then resume it
with lua_resume(). These functions do the same thing as the code
you're using (roughly) but with quite a bit less work.

I’m setting the hook with:
 
    lua_sethook( m_p_state, InstructionCountHook, LUA_MASKCOUNT, 1000 );
 
… just prior to loading the script. I have verified that my hook is set properly just before resuming the coroutine.  This code works fine, everything runs as expected… BUT
The hook function is never called.

Although it's not clear from the manual, every thread has its own
indepedent hook settings. You have to call sethook on the coroutine
thread (which would be easy to do if you'd created it with
lua_newthread() :) ).