summaryrefslogtreecommitdiff
path: root/lstate.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1999-12-06 09:41:28 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1999-12-06 09:41:28 -0200
commit968ad49da6522c1cf413bd86323a613176d12c07 (patch)
tree6961b75297c9533963f3b2d7db4f06900ed4f9f7 /lstate.c
parent1fdb445e7dae6d08b67e46e1979f285b38bbc18d (diff)
downloadlua-github-968ad49da6522c1cf413bd86323a613176d12c07.tar.gz
`lua_newstate' gets the inital stack size and other arguments
Diffstat (limited to 'lstate.c')
-rw-r--r--lstate.c51
1 files changed, 44 insertions, 7 deletions
diff --git a/lstate.c b/lstate.c
index fe2b4830..3306c780 100644
--- a/lstate.c
+++ b/lstate.c
@@ -1,12 +1,15 @@
/*
-** $Id: lstate.c,v 1.18 1999/11/29 19:12:07 roberto Exp roberto $
+** $Id: lstate.c,v 1.19 1999/12/01 19:50:08 roberto Exp roberto $
** Global State
** See Copyright Notice in lua.h
*/
+#include <stdarg.h>
+
#define LUA_REENTRANT
+#include "lauxlib.h"
#include "lbuiltin.h"
#include "ldo.h"
#include "lgc.h"
@@ -18,10 +21,15 @@
#include "ltm.h"
+#ifndef DEFAULT_STACK_SIZE
+#define DEFAULT_STACK_SIZE 1024
+#endif
+
+
lua_State *lua_state = NULL;
-lua_State *lua_newstate (void) {
+static lua_State *newstate_aux (int stacksize, int put_builtin) {
lua_State *L = luaM_new(NULL, lua_State);
L->errorJmp = NULL;
L->Mbuffer = NULL;
@@ -43,16 +51,42 @@ lua_State *lua_newstate (void) {
L->refFree = NONEXT;
L->nblocks = 0;
L->GCthreshold = MAX_INT; /* to avoid GC during pre-definitions */
- luaD_init(L);
+ luaD_init(L, stacksize);
luaS_init(L);
luaX_init(L);
luaT_init(L);
- luaB_predefine(L);
+ if (put_builtin)
+ luaB_predefine(L);
L->GCthreshold = L->nblocks*4;
return L;
}
+lua_State *lua_newstate (const char *s, ...) {
+ static const char *const ops[] = {"stack", "builtin", NULL};
+ va_list ap;
+ int stacksize = DEFAULT_STACK_SIZE;
+ int put_builtin = 1;
+ va_start(ap, s);
+ while (s) {
+ switch (luaL_findstring(s, ops)) {
+ case 0: /* stack */
+ stacksize = va_arg(ap, int);
+ break;
+ case 1: /* builtin */
+ put_builtin = va_arg(ap, int);
+ break;
+ default: /* invalid argument */
+ va_end(ap);
+ return NULL;
+ }
+ s = va_arg(ap, const char *);
+ }
+ va_end(ap);
+ return newstate_aux(stacksize, put_builtin);
+}
+
+
void lua_close (lua_State *L) {
luaC_collect(L, 1); /* collect all elements */
LUA_ASSERT(L, L->rootproto == NULL, "list should be empty");
@@ -66,9 +100,12 @@ void lua_close (lua_State *L) {
luaM_free(L, L->Mbuffer);
luaM_free(L, L->Cblocks);
LUA_ASSERT(L, L->nblocks == 0, "wrong count for nblocks");
+ LUA_ASSERT(L, L != lua_state || L->Cstack.lua2C == L->stack, "bad stack");
+ LUA_ASSERT(L, L != lua_state || L->Cstack.base == L->stack, "bad stack");
luaM_free(L, L);
- LUA_ASSERT(L, numblocks == 0, "memory leak!");
- LUA_ASSERT(L, totalmem == 0,"memory leak!");
- L = NULL;
+ LUA_ASSERT(L, L != lua_state || numblocks == 0, "memory leak!");
+ LUA_ASSERT(L, L != lua_state || totalmem == 0,"memory leak!");
+ if (L == lua_state)
+ lua_state = NULL;
}