浏览代码

no varargs in Lua API

Roberto Ierusalimschy 25 年之前
父节点
当前提交
ae55f3eead
共有 4 个文件被更改,包括 12 次插入38 次删除
  1. 3 27
      lstate.c
  2. 2 3
      ltests.c
  3. 4 5
      lua.c
  4. 3 3
      lua.h

+ 3 - 27
lstate.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lstate.c,v 1.27 2000/06/12 13:52:05 roberto Exp roberto $
+** $Id: lstate.c,v 1.28 2000/06/30 14:35:17 roberto Exp roberto $
 ** Global State
 ** See Copyright Notice in lua.h
 */
@@ -27,7 +27,7 @@
 lua_State *lua_state = NULL;
 
 
-static lua_State *newstate_aux (int stacksize, int put_builtin) {
+lua_State *lua_newstate (int stacksize, int put_builtin) {
   lua_State *L = luaM_new(NULL, lua_State);
   L->errorJmp = NULL;
   L->Mbuffer = NULL;
@@ -50,6 +50,7 @@ static lua_State *newstate_aux (int stacksize, int put_builtin) {
   L->linehook = NULL;
   L->allowhooks = 1;
   L->gt = luaH_new(L, 10);
+  if (stacksize == 0) stacksize = DEFAULT_STACK_SIZE;
   luaD_init(L, stacksize);
   luaS_init(L);
   luaX_init(L);
@@ -61,31 +62,6 @@ static lua_State *newstate_aux (int stacksize, int put_builtin) {
 }
 
 
-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->rootproto == NULL, "list should be empty");

+ 2 - 3
ltests.c

@@ -1,5 +1,5 @@
 /*
-** $Id: ltests.c,v 1.27 2000/06/26 19:28:31 roberto Exp roberto $
+** $Id: ltests.c,v 1.28 2000/06/28 17:06:07 roberto Exp roberto $
 ** Internal Module for Debugging of the Lua Implementation
 ** See Copyright Notice in lua.h
 */
@@ -374,8 +374,7 @@ static void testC (void) {
     }
     else if EQ("newstate") {
       int stacksize = getnum(&pc);
-      lua_State *L1 = lua_newstate("stack", stacksize,
-                                   "builtin", getnum(&pc), NULL);
+      lua_State *L1 = lua_newstate(stacksize, getnum(&pc));
       lua_pushuserdata(L1);
     }
     else if EQ("closestate") {

+ 4 - 5
lua.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lua.c,v 1.40 2000/06/16 17:16:34 roberto Exp roberto $
+** $Id: lua.c,v 1.41 2000/06/19 13:15:15 roberto Exp roberto $
 ** Lua stand-alone interpreter
 ** See Copyright Notice in lua.h
 */
@@ -175,17 +175,16 @@ int main (int argc, char *argv[]) {
   int toclose = 0;
   int status = EXIT_SUCCESS;
   int i = 1;
+  int stacksize = 0;
   if (i < argc && argv[1][0] == '-' && argv[1][1] == 's') {
-    int stacksize = atoi(&argv[1][2]);
+    stacksize = atoi(&argv[1][2]);
     if (stacksize == 0) {
       fprintf(stderr, "lua: invalid stack size ('%s')\n", &argv[1][2]);
       exit(EXIT_FAILURE);
     }
     i++;
-    lua_state = lua_newstate("stack", stacksize, NULL);
   }
-  else
-    lua_state = lua_newstate(NULL);
+  lua_state = lua_newstate(stacksize, 1);
   lua_userinit();
   lua_pushuserdata(argv);
   lua_pushcclosure(l_getargs, 1);

+ 3 - 3
lua.h

@@ -1,5 +1,5 @@
 /*
-** $Id: lua.h,v 1.53 2000/05/24 13:54:49 roberto Exp roberto $
+** $Id: lua.h,v 1.54 2000/05/26 19:17:57 roberto Exp roberto $
 ** Lua - An Extensible Extension Language
 ** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil
 ** e-mail: [email protected]
@@ -39,7 +39,7 @@ typedef struct lua_TObject *lua_Object;
 #define LUA_NOOBJECT	((lua_Object)0)
 
 
-lua_State     *lua_newstate (const char *s, ...);
+lua_State     *lua_newstate (int stacksize, int builtin);
 void           lua_close (lua_State *L);
 
 lua_Object     lua_settagmethod (lua_State *L, int tag, const char *event);
@@ -162,7 +162,7 @@ long	       lua_collectgarbage (lua_State *L, long limit);
 
 extern lua_State *lua_state;
 
-#define lua_open()	((void)(lua_state?0:(lua_state=lua_newstate(0))))
+#define lua_open()	((void)(lua_state?0:(lua_state=lua_newstate(0, 1))))
 
 #define lua_close()		(lua_close)(lua_state)
 #define lua_settagmethod(tag,event)	(lua_settagmethod)(lua_state, tag,event)