Beispiel #1
0
lua_State *luaE_newthread (lua_State *L) {
  lua_State *L1 = mallocstate(L);
  luaC_link(L, valtogco(L1), LUA_TTHREAD);
  preinit_state(L1);
  L1->l_G = L->l_G;
  stack_init(L1, L);  /* init stack */
  setobj2n(gt(L1), gt(L));  /* share table of globals */
  return L1;
}
Beispiel #2
0
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;
}
Beispiel #3
0
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;
}
Beispiel #4
0
lua_State *luaE_newthread (lua_State *L) {
  lua_State *L1 = mallocstate(L);
  luaC_link(L, valtogco(L1), LUA_TTHREAD);
  preinit_state(L1);
  L1->l_G = L->l_G;
#if LUA_REFCOUNT
  L1->gclist_head.next = (GCObject*)&L->gclist_tail;
  L1->gclist_head.prev = NULL;
  L1->gclist_tail.next = NULL;
  L1->gclist_tail.prev = (GCObject*)&L->gclist_head;
  L1->gclist_head.tt = LUA_TNIL;
  L1->gclist_head.marked = 0;
  L1->gclist_head.ref = 0;
  L1->gclist_tail.tt = LUA_TNIL;
  L1->gclist_tail.marked = 0;
  L1->gclist_tail.ref = 0;
  L1->ref = 0;
#endif LUA_REFCOUNT
  stack_init(L1, L);  /* init stack */
  setobj2n(gt(L1), gt(L));  /* share table of globals */
  return L1;
}