summaryrefslogtreecommitdiff
path: root/lstate.c
diff options
context:
space:
mode:
Diffstat (limited to 'lstate.c')
-rw-r--r--lstate.c52
1 files changed, 27 insertions, 25 deletions
diff --git a/lstate.c b/lstate.c
index 57aa292d..d996420a 100644
--- a/lstate.c
+++ b/lstate.c
@@ -1,10 +1,12 @@
1/* 1/*
2** $Id: lstate.c,v 1.15 1999/10/14 17:53:35 roberto Exp roberto $ 2** $Id: lstate.c,v 1.16 1999/11/10 15:39:35 roberto Exp roberto $
3** Global State 3** Global State
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
6 6
7 7
8#define LUA_REENTRANT
9
8#include "lbuiltin.h" 10#include "lbuiltin.h"
9#include "ldo.h" 11#include "ldo.h"
10#include "lgc.h" 12#include "lgc.h"
@@ -19,9 +21,8 @@
19lua_State *lua_state = NULL; 21lua_State *lua_state = NULL;
20 22
21 23
22void lua_open (void) { 24lua_State *lua_newstate (void) {
23 if (lua_state) return; 25 lua_State *L = luaM_new(NULL, lua_State);
24 lua_state = luaM_new(lua_State);
25 L->Cstack.base = 0; 26 L->Cstack.base = 0;
26 L->Cstack.lua2C = 0; 27 L->Cstack.lua2C = 0;
27 L->Cstack.num = 0; 28 L->Cstack.num = 0;
@@ -45,31 +46,32 @@ void lua_open (void) {
45 L->refFree = NONEXT; 46 L->refFree = NONEXT;
46 L->nblocks = 0; 47 L->nblocks = 0;
47 L->GCthreshold = MAX_INT; /* to avoid GC during pre-definitions */ 48 L->GCthreshold = MAX_INT; /* to avoid GC during pre-definitions */
48 luaD_init(); 49 luaD_init(L);
49 luaS_init(); 50 luaS_init(L);
50 luaX_init(); 51 luaX_init(L);
51 luaT_init(); 52 luaT_init(L);
52 luaB_predefine(); 53 luaB_predefine(L);
54 return L;
53 L->GCthreshold = L->nblocks*4; 55 L->GCthreshold = L->nblocks*4;
54} 56}
55 57
56 58
57void lua_close (void) { 59void lua_close (lua_State *L) {
58 luaC_collect(1); /* collect all elements */ 60 luaC_collect(L, 1); /* collect all elements */
59 LUA_ASSERT(L->rootproto == NULL, "list should be empty"); 61 LUA_ASSERT(L, L->rootproto == NULL, "list should be empty");
60 LUA_ASSERT(L->rootcl == NULL, "list should be empty"); 62 LUA_ASSERT(L, L->rootcl == NULL, "list should be empty");
61 LUA_ASSERT(L->rootglobal == NULL, "list should be empty"); 63 LUA_ASSERT(L, L->rootglobal == NULL, "list should be empty");
62 LUA_ASSERT(L->roottable == NULL, "list should be empty"); 64 LUA_ASSERT(L, L->roottable == NULL, "list should be empty");
63 luaS_freeall(); 65 luaS_freeall(L);
64 luaM_free(L->stack.stack); 66 luaM_free(L, L->stack.stack);
65 luaM_free(L->IMtable); 67 luaM_free(L, L->IMtable);
66 luaM_free(L->refArray); 68 luaM_free(L, L->refArray);
67 luaM_free(L->Mbuffer); 69 luaM_free(L, L->Mbuffer);
68 luaM_free(L->Cblocks); 70 luaM_free(L, L->Cblocks);
69 LUA_ASSERT(L->nblocks == 0, "wrong count for nblocks"); 71 LUA_ASSERT(L, L->nblocks == 0, "wrong count for nblocks");
70 luaM_free(L); 72 luaM_free(L, L);
71 LUA_ASSERT(numblocks == 0, "memory leak!"); 73 LUA_ASSERT(L, numblocks == 0, "memory leak!");
72 LUA_ASSERT(totalmem == 0,"memory leak!"); 74 LUA_ASSERT(L, totalmem == 0,"memory leak!");
73 L = NULL; 75 L = NULL;
74} 76}
75 77