# HG changeset patch # User Tero Marttila # Date 1242914927 -10800 # Node ID 0d5d46ab49d591baeffa94dab126c236ef373b5f # Parent f0e52e026197e8da99b3195bfda7cbf2fa2fbc78 merge lua_thread_setup bcak into _lua_thread_start, as everything can be done on the main lua state diff -r f0e52e026197 -r 0d5d46ab49d5 src/lua_thread.c --- a/src/lua_thread.c Thu May 21 16:57:56 2009 +0300 +++ b/src/lua_thread.c Thu May 21 17:08:47 2009 +0300 @@ -68,33 +68,6 @@ }; /** - * Setup the given newthread's state - */ -static int lua_thread_setup (lua_State *L) -{ - struct lua_thread_start_ctx *ctx; - - // read the ctx argument off the stack - if ((ctx = lua_touserdata(L, 1)) == NULL) - return luaL_error(L, "lua_touserdata"); - - // push the thread state as the key - lua_pushthread(L); - - // push the lua_thread as the value - lua_pushlightuserdata(L, ctx->thread); - - // store L -> lua_thread mapping in the registry - lua_settable(L, LUA_REGISTRYINDEX); - - // clean up the stack - lua_pop(L, 1); - - // ok - return 0; -} - -/** * Create a new thread, set it up, and run the initial resume, returning the boolean result of that * (true for yielded, false for done). */ @@ -116,10 +89,12 @@ // create new thread TL = lua_newthread(L); - - // create thread and do setup on it - if (nexus_lua_error(TL, lua_cpcall(TL, lua_thread_setup, ctx), &err)) - goto error; + + // push the lua_thread as the value + lua_pushlightuserdata(L, ctx->thread); + + // store L -> lua_thread mapping in the registry + lua_settable(L, LUA_REGISTRYINDEX); // load the chunk as a lua function into the thread's state if (nexus_lua_error(TL, luaL_loadstring(TL, ctx->chunk), &err))