1997-11-19 20:31:19 +03:00
|
|
|
/*
|
1999-11-22 16:12:07 +03:00
|
|
|
** $Id: lstate.c,v 1.16 1999/11/10 15:39:35 roberto Exp roberto $
|
1997-11-19 20:31:19 +03:00
|
|
|
** Global State
|
|
|
|
** See Copyright Notice in lua.h
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
1999-11-22 16:12:07 +03:00
|
|
|
#define LUA_REENTRANT
|
|
|
|
|
1997-11-19 20:31:19 +03:00
|
|
|
#include "lbuiltin.h"
|
|
|
|
#include "ldo.h"
|
1997-12-01 23:31:25 +03:00
|
|
|
#include "lgc.h"
|
1997-11-19 20:31:19 +03:00
|
|
|
#include "llex.h"
|
|
|
|
#include "lmem.h"
|
1999-11-10 18:39:35 +03:00
|
|
|
#include "lref.h"
|
1997-11-19 20:31:19 +03:00
|
|
|
#include "lstate.h"
|
|
|
|
#include "lstring.h"
|
|
|
|
#include "ltm.h"
|
|
|
|
|
|
|
|
|
1998-06-03 00:37:04 +04:00
|
|
|
lua_State *lua_state = NULL;
|
1997-11-19 20:31:19 +03:00
|
|
|
|
|
|
|
|
1999-11-22 16:12:07 +03:00
|
|
|
lua_State *lua_newstate (void) {
|
|
|
|
lua_State *L = luaM_new(NULL, lua_State);
|
1997-11-19 20:31:19 +03:00
|
|
|
L->Cstack.base = 0;
|
|
|
|
L->Cstack.lua2C = 0;
|
|
|
|
L->Cstack.num = 0;
|
|
|
|
L->errorJmp = NULL;
|
1999-04-13 23:30:51 +04:00
|
|
|
L->Mbuffer = NULL;
|
|
|
|
L->Mbuffbase = 0;
|
|
|
|
L->Mbuffsize = 0;
|
|
|
|
L->Mbuffnext = 0;
|
1999-05-11 18:19:32 +04:00
|
|
|
L->Cblocks = NULL;
|
1999-04-13 23:30:51 +04:00
|
|
|
L->numCblocks = 0;
|
1999-02-04 20:47:59 +03:00
|
|
|
L->debug = 0;
|
|
|
|
L->callhook = NULL;
|
|
|
|
L->linehook = NULL;
|
1999-10-04 21:51:04 +04:00
|
|
|
L->rootproto = NULL;
|
|
|
|
L->rootcl = NULL;
|
|
|
|
L->rootglobal = NULL;
|
|
|
|
L->roottable = NULL;
|
1999-04-13 23:30:51 +04:00
|
|
|
L->IMtable = NULL;
|
1997-11-19 20:31:19 +03:00
|
|
|
L->refArray = NULL;
|
|
|
|
L->refSize = 0;
|
1999-11-10 18:39:35 +03:00
|
|
|
L->refFree = NONEXT;
|
1997-11-19 20:31:19 +03:00
|
|
|
L->nblocks = 0;
|
1999-11-10 18:39:35 +03:00
|
|
|
L->GCthreshold = MAX_INT; /* to avoid GC during pre-definitions */
|
1999-11-22 16:12:07 +03:00
|
|
|
luaD_init(L);
|
|
|
|
luaS_init(L);
|
|
|
|
luaX_init(L);
|
|
|
|
luaT_init(L);
|
|
|
|
luaB_predefine(L);
|
|
|
|
return L;
|
1999-11-10 18:39:35 +03:00
|
|
|
L->GCthreshold = L->nblocks*4;
|
1997-11-19 20:31:19 +03:00
|
|
|
}
|
|
|
|
|
1997-12-01 23:31:25 +03:00
|
|
|
|
1999-11-22 16:12:07 +03:00
|
|
|
void lua_close (lua_State *L) {
|
|
|
|
luaC_collect(L, 1); /* collect all elements */
|
|
|
|
LUA_ASSERT(L, L->rootproto == NULL, "list should be empty");
|
|
|
|
LUA_ASSERT(L, L->rootcl == NULL, "list should be empty");
|
|
|
|
LUA_ASSERT(L, L->rootglobal == NULL, "list should be empty");
|
|
|
|
LUA_ASSERT(L, L->roottable == NULL, "list should be empty");
|
|
|
|
luaS_freeall(L);
|
|
|
|
luaM_free(L, L->stack.stack);
|
|
|
|
luaM_free(L, L->IMtable);
|
|
|
|
luaM_free(L, L->refArray);
|
|
|
|
luaM_free(L, L->Mbuffer);
|
|
|
|
luaM_free(L, L->Cblocks);
|
|
|
|
LUA_ASSERT(L, L->nblocks == 0, "wrong count for nblocks");
|
|
|
|
luaM_free(L, L);
|
|
|
|
LUA_ASSERT(L, numblocks == 0, "memory leak!");
|
|
|
|
LUA_ASSERT(L, totalmem == 0,"memory leak!");
|
1997-12-01 23:31:25 +03:00
|
|
|
L = NULL;
|
|
|
|
}
|
1998-06-03 00:37:04 +04:00
|
|
|
|