lua/lstate.c

76 lines
1.7 KiB
C
Raw Normal View History

1997-11-19 20:31:19 +03:00
/*
** $Id: lstate.c,v 1.15 1999/10/14 17:53:35 roberto Exp roberto $
1997-11-19 20:31:19 +03:00
** Global State
** See Copyright Notice in lua.h
*/
#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"
#include "lref.h"
1997-11-19 20:31:19 +03:00
#include "lstate.h"
#include "lstring.h"
#include "ltm.h"
lua_State *lua_state = NULL;
1997-11-19 20:31:19 +03:00
1999-08-17 00:52:00 +04:00
void lua_open (void) {
1997-11-19 20:31:19 +03:00
if (lua_state) return;
lua_state = luaM_new(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;
L->Mbuffer = NULL;
L->Mbuffbase = 0;
L->Mbuffsize = 0;
L->Mbuffnext = 0;
1999-05-11 18:19:32 +04:00
L->Cblocks = NULL;
L->numCblocks = 0;
L->debug = 0;
L->callhook = NULL;
L->linehook = NULL;
L->rootproto = NULL;
L->rootcl = NULL;
L->rootglobal = NULL;
L->roottable = NULL;
L->IMtable = NULL;
1997-11-19 20:31:19 +03:00
L->refArray = NULL;
L->refSize = 0;
L->refFree = NONEXT;
1997-11-19 20:31:19 +03:00
L->nblocks = 0;
L->GCthreshold = MAX_INT; /* to avoid GC during pre-definitions */
1997-11-19 20:31:19 +03:00
luaD_init();
luaS_init();
luaX_init();
luaT_init();
luaB_predefine();
L->GCthreshold = L->nblocks*4;
1997-11-19 20:31:19 +03:00
}
1997-12-01 23:31:25 +03:00
1999-08-17 00:52:00 +04:00
void lua_close (void) {
luaC_collect(1); /* collect all elements */
1999-10-14 21:53:35 +04:00
LUA_ASSERT(L->rootproto == NULL, "list should be empty");
LUA_ASSERT(L->rootcl == NULL, "list should be empty");
LUA_ASSERT(L->rootglobal == NULL, "list should be empty");
LUA_ASSERT(L->roottable == NULL, "list should be empty");
1997-12-01 23:31:25 +03:00
luaS_freeall();
luaM_free(L->stack.stack);
luaM_free(L->IMtable);
luaM_free(L->refArray);
luaM_free(L->Mbuffer);
1999-05-11 18:19:32 +04:00
luaM_free(L->Cblocks);
LUA_ASSERT(L->nblocks == 0, "wrong count for nblocks");
1997-12-01 23:31:25 +03:00
luaM_free(L);
1999-10-14 21:53:35 +04:00
LUA_ASSERT(numblocks == 0, "memory leak!");
LUA_ASSERT(totalmem == 0,"memory leak!");
1997-12-01 23:31:25 +03:00
L = NULL;
}