/* weet: * 创建一个新的Lua协程 * */ LUA_API lua_State *lua_newthread (lua_State *L) { lua_State *L1; lua_lock(L); luaC_checkGC(L); L1 = luaE_newthread(L); setthvalue(L->top, L1); api_incr_top(L); lua_unlock(L); lua_userstateopen(L1); // weet: 一个空的宏 return L1; }
LUA_API lua_State *lua_open (void) { lua_State *L = mallocstate(NULL); if (L) { /* allocation OK? */ L->tt = LUA_TTHREAD; L->marked = 0; L->next = L->gclist = NULL; preinit_state(L); L->l_G = NULL; if (luaD_rawrunprotected(L, f_luaopen, NULL) != 0) { /* memory allocation error: free partial state */ close_state(L); L = NULL; } } lua_userstateopen(L); return L; }
LUA_API lua_State *lua_open (void) { lua_State *L; global_State globalState; lua_State luaState; #ifdef _DEBUG luaState.allocName = "Lua_lua_State"; #endif _DEBUG luaState.l_G = &globalState; globalState.reallocFunc = luaHelper_Realloc; globalState.freeFunc = luaHelper_Free; globalState.memData = luaHelper_memData; globalState.nblocks = sizeof(lua_State) + sizeof(global_State); // Bogus. L = mallocstate(&luaState); if (L) { /* allocation OK? */ L->tt = LUA_TTHREAD; L->marked = 0; L->next = NULL; #if LUA_REFCOUNT L->prev = NULL; L->gclist_head.next = (GCObject*)&L->gclist_tail; L->gclist_head.prev = NULL; L->gclist_tail.next = NULL; L->gclist_tail.prev = (GCObject*)&L->gclist_head; L->gclist_head.tt = LUA_TNIL; L->gclist_head.marked = 0; L->gclist_head.ref = 0; L->gclist_tail.tt = LUA_TNIL; L->gclist_tail.marked = 0; L->gclist_tail.ref = 0; L->ref = 0; #else !LUA_REFCOUNT L->gclist = NULL; #endif LUA_REFCOUNT preinit_state(L); L->l_G = NULL; if (luaD_rawrunprotected(L, f_luaopen, NULL) != 0) { /* memory allocation error: free partial state */ close_state(L); L = NULL; } } lua_userstateopen(L); return L; }