mirror of
https://github.com/lua/lua
synced 2025-04-11 07:22:53 +03:00
no varargs in Lua API
This commit is contained in:
parent
cfba572076
commit
ae55f3eead
30
lstate.c
30
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
|
** Global State
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@ -27,7 +27,7 @@
|
|||||||
lua_State *lua_state = NULL;
|
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);
|
lua_State *L = luaM_new(NULL, lua_State);
|
||||||
L->errorJmp = NULL;
|
L->errorJmp = NULL;
|
||||||
L->Mbuffer = NULL;
|
L->Mbuffer = NULL;
|
||||||
@ -50,6 +50,7 @@ static lua_State *newstate_aux (int stacksize, int put_builtin) {
|
|||||||
L->linehook = NULL;
|
L->linehook = NULL;
|
||||||
L->allowhooks = 1;
|
L->allowhooks = 1;
|
||||||
L->gt = luaH_new(L, 10);
|
L->gt = luaH_new(L, 10);
|
||||||
|
if (stacksize == 0) stacksize = DEFAULT_STACK_SIZE;
|
||||||
luaD_init(L, stacksize);
|
luaD_init(L, stacksize);
|
||||||
luaS_init(L);
|
luaS_init(L);
|
||||||
luaX_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) {
|
void lua_close (lua_State *L) {
|
||||||
luaC_collect(L, 1); /* collect all elements */
|
luaC_collect(L, 1); /* collect all elements */
|
||||||
LUA_ASSERT(L->rootproto == NULL, "list should be empty");
|
LUA_ASSERT(L->rootproto == NULL, "list should be empty");
|
||||||
|
5
ltests.c
5
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
|
** Internal Module for Debugging of the Lua Implementation
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@ -374,8 +374,7 @@ static void testC (void) {
|
|||||||
}
|
}
|
||||||
else if EQ("newstate") {
|
else if EQ("newstate") {
|
||||||
int stacksize = getnum(&pc);
|
int stacksize = getnum(&pc);
|
||||||
lua_State *L1 = lua_newstate("stack", stacksize,
|
lua_State *L1 = lua_newstate(stacksize, getnum(&pc));
|
||||||
"builtin", getnum(&pc), NULL);
|
|
||||||
lua_pushuserdata(L1);
|
lua_pushuserdata(L1);
|
||||||
}
|
}
|
||||||
else if EQ("closestate") {
|
else if EQ("closestate") {
|
||||||
|
9
lua.c
9
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
|
** Lua stand-alone interpreter
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@ -175,17 +175,16 @@ int main (int argc, char *argv[]) {
|
|||||||
int toclose = 0;
|
int toclose = 0;
|
||||||
int status = EXIT_SUCCESS;
|
int status = EXIT_SUCCESS;
|
||||||
int i = 1;
|
int i = 1;
|
||||||
|
int stacksize = 0;
|
||||||
if (i < argc && argv[1][0] == '-' && argv[1][1] == 's') {
|
if (i < argc && argv[1][0] == '-' && argv[1][1] == 's') {
|
||||||
int stacksize = atoi(&argv[1][2]);
|
stacksize = atoi(&argv[1][2]);
|
||||||
if (stacksize == 0) {
|
if (stacksize == 0) {
|
||||||
fprintf(stderr, "lua: invalid stack size ('%s')\n", &argv[1][2]);
|
fprintf(stderr, "lua: invalid stack size ('%s')\n", &argv[1][2]);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
lua_state = lua_newstate("stack", stacksize, NULL);
|
|
||||||
}
|
}
|
||||||
else
|
lua_state = lua_newstate(stacksize, 1);
|
||||||
lua_state = lua_newstate(NULL);
|
|
||||||
lua_userinit();
|
lua_userinit();
|
||||||
lua_pushuserdata(argv);
|
lua_pushuserdata(argv);
|
||||||
lua_pushcclosure(l_getargs, 1);
|
lua_pushcclosure(l_getargs, 1);
|
||||||
|
6
lua.h
6
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
|
** Lua - An Extensible Extension Language
|
||||||
** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil
|
** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil
|
||||||
** e-mail: lua@tecgraf.puc-rio.br
|
** e-mail: lua@tecgraf.puc-rio.br
|
||||||
@ -39,7 +39,7 @@ typedef struct lua_TObject *lua_Object;
|
|||||||
#define LUA_NOOBJECT ((lua_Object)0)
|
#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);
|
void lua_close (lua_State *L);
|
||||||
|
|
||||||
lua_Object lua_settagmethod (lua_State *L, int tag, const char *event);
|
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;
|
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_close() (lua_close)(lua_state)
|
||||||
#define lua_settagmethod(tag,event) (lua_settagmethod)(lua_state, tag,event)
|
#define lua_settagmethod(tag,event) (lua_settagmethod)(lua_state, tag,event)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user