diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-06-30 16:17:08 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-06-30 16:17:08 -0300 |
commit | ae55f3eeada102f3fa8345173410feaf1db42cde (patch) | |
tree | eaddcc592b75b5035abc35ccd7fc99dd9aa95ea4 | |
parent | cfba57207660fd27ddac9ea51cdeb263c2d6b418 (diff) | |
download | lua-ae55f3eeada102f3fa8345173410feaf1db42cde.tar.gz lua-ae55f3eeada102f3fa8345173410feaf1db42cde.tar.bz2 lua-ae55f3eeada102f3fa8345173410feaf1db42cde.zip |
no varargs in Lua API
-rw-r--r-- | lstate.c | 30 | ||||
-rw-r--r-- | ltests.c | 5 | ||||
-rw-r--r-- | lua.c | 9 | ||||
-rw-r--r-- | lua.h | 6 |
4 files changed, 12 insertions, 38 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstate.c,v 1.27 2000/06/12 13:52:05 roberto Exp roberto $ | 2 | ** $Id: lstate.c,v 1.28 2000/06/30 14:35:17 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 | */ |
@@ -27,7 +27,7 @@ | |||
27 | lua_State *lua_state = NULL; | 27 | lua_State *lua_state = NULL; |
28 | 28 | ||
29 | 29 | ||
30 | static lua_State *newstate_aux (int stacksize, int put_builtin) { | 30 | lua_State *lua_newstate (int stacksize, int put_builtin) { |
31 | lua_State *L = luaM_new(NULL, lua_State); | 31 | lua_State *L = luaM_new(NULL, lua_State); |
32 | L->errorJmp = NULL; | 32 | L->errorJmp = NULL; |
33 | L->Mbuffer = NULL; | 33 | L->Mbuffer = NULL; |
@@ -50,6 +50,7 @@ static lua_State *newstate_aux (int stacksize, int put_builtin) { | |||
50 | L->linehook = NULL; | 50 | L->linehook = NULL; |
51 | L->allowhooks = 1; | 51 | L->allowhooks = 1; |
52 | L->gt = luaH_new(L, 10); | 52 | L->gt = luaH_new(L, 10); |
53 | if (stacksize == 0) stacksize = DEFAULT_STACK_SIZE; | ||
53 | luaD_init(L, stacksize); | 54 | luaD_init(L, stacksize); |
54 | luaS_init(L); | 55 | luaS_init(L); |
55 | luaX_init(L); | 56 | luaX_init(L); |
@@ -61,31 +62,6 @@ static lua_State *newstate_aux (int stacksize, int put_builtin) { | |||
61 | } | 62 | } |
62 | 63 | ||
63 | 64 | ||
64 | lua_State *lua_newstate (const char *s, ...) { | ||
65 | static const char *const ops[] = {"stack", "builtin", NULL}; | ||
66 | va_list ap; | ||
67 | int stacksize = DEFAULT_STACK_SIZE; | ||
68 | int put_builtin = 1; | ||
69 | va_start(ap, s); | ||
70 | while (s) { | ||
71 | switch (luaL_findstring(s, ops)) { | ||
72 | case 0: /* stack */ | ||
73 | stacksize = va_arg(ap, int); | ||
74 | break; | ||
75 | case 1: /* builtin */ | ||
76 | put_builtin = va_arg(ap, int); | ||
77 | break; | ||
78 | default: /* invalid argument */ | ||
79 | va_end(ap); | ||
80 | return NULL; | ||
81 | } | ||
82 | s = va_arg(ap, const char *); | ||
83 | } | ||
84 | va_end(ap); | ||
85 | return newstate_aux(stacksize, put_builtin); | ||
86 | } | ||
87 | |||
88 | |||
89 | void lua_close (lua_State *L) { | 65 | void lua_close (lua_State *L) { |
90 | luaC_collect(L, 1); /* collect all elements */ | 66 | luaC_collect(L, 1); /* collect all elements */ |
91 | LUA_ASSERT(L->rootproto == NULL, "list should be empty"); | 67 | LUA_ASSERT(L->rootproto == NULL, "list should be empty"); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltests.c,v 1.27 2000/06/26 19:28:31 roberto Exp roberto $ | 2 | ** $Id: ltests.c,v 1.28 2000/06/28 17:06:07 roberto Exp roberto $ |
3 | ** Internal Module for Debugging of the Lua Implementation | 3 | ** Internal Module for Debugging of the Lua Implementation |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -374,8 +374,7 @@ static void testC (void) { | |||
374 | } | 374 | } |
375 | else if EQ("newstate") { | 375 | else if EQ("newstate") { |
376 | int stacksize = getnum(&pc); | 376 | int stacksize = getnum(&pc); |
377 | lua_State *L1 = lua_newstate("stack", stacksize, | 377 | lua_State *L1 = lua_newstate(stacksize, getnum(&pc)); |
378 | "builtin", getnum(&pc), NULL); | ||
379 | lua_pushuserdata(L1); | 378 | lua_pushuserdata(L1); |
380 | } | 379 | } |
381 | else if EQ("closestate") { | 380 | else if EQ("closestate") { |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lua.c,v 1.40 2000/06/16 17:16:34 roberto Exp roberto $ | 2 | ** $Id: lua.c,v 1.41 2000/06/19 13:15:15 roberto Exp roberto $ |
3 | ** Lua stand-alone interpreter | 3 | ** Lua stand-alone interpreter |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -175,17 +175,16 @@ int main (int argc, char *argv[]) { | |||
175 | int toclose = 0; | 175 | int toclose = 0; |
176 | int status = EXIT_SUCCESS; | 176 | int status = EXIT_SUCCESS; |
177 | int i = 1; | 177 | int i = 1; |
178 | int stacksize = 0; | ||
178 | if (i < argc && argv[1][0] == '-' && argv[1][1] == 's') { | 179 | if (i < argc && argv[1][0] == '-' && argv[1][1] == 's') { |
179 | int stacksize = atoi(&argv[1][2]); | 180 | stacksize = atoi(&argv[1][2]); |
180 | if (stacksize == 0) { | 181 | if (stacksize == 0) { |
181 | fprintf(stderr, "lua: invalid stack size ('%s')\n", &argv[1][2]); | 182 | fprintf(stderr, "lua: invalid stack size ('%s')\n", &argv[1][2]); |
182 | exit(EXIT_FAILURE); | 183 | exit(EXIT_FAILURE); |
183 | } | 184 | } |
184 | i++; | 185 | i++; |
185 | lua_state = lua_newstate("stack", stacksize, NULL); | ||
186 | } | 186 | } |
187 | else | 187 | lua_state = lua_newstate(stacksize, 1); |
188 | lua_state = lua_newstate(NULL); | ||
189 | lua_userinit(); | 188 | lua_userinit(); |
190 | lua_pushuserdata(argv); | 189 | lua_pushuserdata(argv); |
191 | lua_pushcclosure(l_getargs, 1); | 190 | lua_pushcclosure(l_getargs, 1); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lua.h,v 1.53 2000/05/24 13:54:49 roberto Exp roberto $ | 2 | ** $Id: lua.h,v 1.54 2000/05/26 19:17:57 roberto Exp roberto $ |
3 | ** Lua - An Extensible Extension Language | 3 | ** Lua - An Extensible Extension Language |
4 | ** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil | 4 | ** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil |
5 | ** e-mail: lua@tecgraf.puc-rio.br | 5 | ** e-mail: lua@tecgraf.puc-rio.br |
@@ -39,7 +39,7 @@ typedef struct lua_TObject *lua_Object; | |||
39 | #define LUA_NOOBJECT ((lua_Object)0) | 39 | #define LUA_NOOBJECT ((lua_Object)0) |
40 | 40 | ||
41 | 41 | ||
42 | lua_State *lua_newstate (const char *s, ...); | 42 | lua_State *lua_newstate (int stacksize, int builtin); |
43 | void lua_close (lua_State *L); | 43 | void lua_close (lua_State *L); |
44 | 44 | ||
45 | lua_Object lua_settagmethod (lua_State *L, int tag, const char *event); | 45 | lua_Object lua_settagmethod (lua_State *L, int tag, const char *event); |
@@ -162,7 +162,7 @@ long lua_collectgarbage (lua_State *L, long limit); | |||
162 | 162 | ||
163 | extern lua_State *lua_state; | 163 | extern lua_State *lua_state; |
164 | 164 | ||
165 | #define lua_open() ((void)(lua_state?0:(lua_state=lua_newstate(0)))) | 165 | #define lua_open() ((void)(lua_state?0:(lua_state=lua_newstate(0, 1)))) |
166 | 166 | ||
167 | #define lua_close() (lua_close)(lua_state) | 167 | #define lua_close() (lua_close)(lua_state) |
168 | #define lua_settagmethod(tag,event) (lua_settagmethod)(lua_state, tag,event) | 168 | #define lua_settagmethod(tag,event) (lua_settagmethod)(lua_state, tag,event) |