merge lua_thread_setup bcak into _lua_thread_start, as everything can be done on the main lua state
authorTero Marttila <terom@fixme.fi>
Thu, 21 May 2009 17:08:47 +0300
changeset 214 0d5d46ab49d5
parent 213 f0e52e026197
child 215 85863b89e38b
merge lua_thread_setup bcak into _lua_thread_start, as everything can be done on the main lua state
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))