Exemplo n.º 1
0
static void *thread_entry(void *arg) {
    p_states st = (p_states) arg;
    int n = 1;
    int status;
    /* right now, we have the args table and the function on the stack */
    /* extract function arguments from args table */
    while (1) {
        lua_rawgeti(st->child, 1, n++);
        if (lua_isnil(st->child, -1)) break;
    }
    /* args table is garbage now */
    lua_remove(st->child, 1);
    /* detach thread and invoke lua function with args */
    pthread_detach(pthread_self());
    status = lua_pcall(st->child, n-1, 0, 0);
    callalert(st->child, status);
    /* kill registry reference to thread object */
    lua_pushlightuserdata(st->parent, st->child);
    lua_pushnil(st->parent);
    lua_settable(st->parent, LUA_REGISTRYINDEX);
    /* clean up */
    free(st);
    pthread_cleanup(pthread_self());
    return NULL;
}
Exemplo n.º 2
0
static void *thread_entry(void *arg) {
    lua_State *child = (lua_State *) arg;
    int n = 1; 
    /* right now, we have the args table and the function on the stack */
    /* extract function arguments from args table */
    while (1) {
        lua_rawgeti(child, 1, n++);
        if (lua_isnil(child, -1)) break;
    }
    /* args table is garbage now */
    lua_remove(child, 1); 
    /* detach thread and invoke lua function with args */
    pthread_detach(pthread_self());
    lua_call(child, n-1, 0);
    /* kill registry reference to thread object */
    lua_pushlightuserdata(child, child);
    lua_pushnil(child);
    lua_settable(child, LUA_REGISTRYINDEX);
    /* announce the fact we are not running anymore */
    lt_activedownandsignal(child);
    pthread_cleanup(pthread_self());
    return NULL;
}