src/lua_thread.h
branchlua-threads
changeset 204 7dfc3d7bd92b
parent 203 ffdf53fd0337
child 210 05abca972db0
equal deleted inserted replaced
203:ffdf53fd0337 204:7dfc3d7bd92b
    13  * Forward-declare
    13  * Forward-declare
    14  */
    14  */
    15 struct lua_thread;
    15 struct lua_thread;
    16 
    16 
    17 /**
    17 /**
    18  * Callback for async execution completion.
    18  * Callback for async execution completion. The thread will be cleaned up for re-use before this is called.
    19  *
    19  *
    20  * Called with err == NULL for success, error code otherwise.
    20  * Called with err == NULL for success, error code otherwise.
       
    21  *
       
    22  * XXX: also return execution results (as a lua_State arg)?
    21  */
    23  */
    22 typedef void (*lua_thread_cb) (struct lua_thread *thread, const error_t *err, void *arg);
    24 typedef void (*lua_thread_cb) (const error_t *err, void *arg);
    23 
    25 
    24 /**
    26 /**
    25  * A thread of execution
    27  * A thread of execution
    26  */
    28  */
    27 struct lua_thread {
    29 struct lua_thread {
    49  * Execute the given chunk in a thread context.
    51  * Execute the given chunk in a thread context.
    50  *
    52  *
    51  * This should be called from unprotected mode, and the thread must currently not be active.
    53  * This should be called from unprotected mode, and the thread must currently not be active.
    52  *
    54  *
    53  * This will load the chunk, create a new lua thread state off the lua_nexus, and then do the initial 'lua_resume' call
    55  * This will load the chunk, create a new lua thread state off the lua_nexus, and then do the initial 'lua_resume' call
    54  * on the loaded chunk.
    56  * on the loaded chunk, to execute up to the first yield or final return.
    55  *
    57  *
    56  * If this process raises an error, it will be returned directly. Otherwise, the thread's callback function will
    58  * If this process raises an error, it will be returned directly. If the called chunk simply returns without yielding,
       
    59  * this returns 0, and the callback is *NOT* called. Otherwise, this returns >0 and the thread's callback function will
    57  * eventually be called once the thread either errors out or finishes execution.
    60  * eventually be called once the thread either errors out or finishes execution.
    58  */
    61  */
    59 err_t lua_thread_start (struct lua_thread *thread, const char *chunk, error_t *err);
    62 int lua_thread_start (struct lua_thread *thread, const char *chunk, error_t *err);
    60 
    63 
    61 /**
    64 /**
    62  * Protected-mode function to resume execution of the given lua_State, which must be a lua_State created with
    65  * Protected-mode function to resume execution of the given lua_State, which must be a lua_State created with
    63  * lua_thread_start.
    66  * lua_thread_start.
    64  */
    67  */