back to "lua_upvalue"... (seems better choice)
This commit is contained in:
21
liolib.c
21
liolib.c
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: liolib.c,v 1.9 1997/12/09 13:50:08 roberto Exp roberto $
|
||||
** $Id: liolib.c,v 1.10 1997/12/17 20:48:58 roberto Exp roberto $
|
||||
** Standard I/O (and system) library
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@@ -39,9 +39,6 @@
|
||||
#define FOUTPUT "_OUTPUT"
|
||||
|
||||
|
||||
#define FIRSTARG 3 /* 1st and 2nd are upvalues */
|
||||
|
||||
|
||||
#ifdef POPEN
|
||||
FILE *popen();
|
||||
int pclose();
|
||||
@@ -53,7 +50,7 @@ int pclose();
|
||||
|
||||
static int gettag (int i)
|
||||
{
|
||||
return lua_getnumber(lua_getparam(i));
|
||||
return lua_getnumber(lua_upvalue(i));
|
||||
}
|
||||
|
||||
|
||||
@@ -128,7 +125,7 @@ static void setreturn (FILE *f, char *name)
|
||||
static void io_readfrom (void)
|
||||
{
|
||||
FILE *current;
|
||||
lua_Object f = lua_getparam(FIRSTARG);
|
||||
lua_Object f = lua_getparam(1);
|
||||
if (f == LUA_NOOBJECT) {
|
||||
closefile(FINPUT);
|
||||
current = stdin;
|
||||
@@ -136,7 +133,7 @@ static void io_readfrom (void)
|
||||
else if (lua_tag(f) == gettag(IOTAG))
|
||||
current = lua_getuserdata(f);
|
||||
else {
|
||||
char *s = luaL_check_string(FIRSTARG);
|
||||
char *s = luaL_check_string(1);
|
||||
current = (*s == '|') ? popen(s+1, "r") : fopen(s, "r");
|
||||
if (current == NULL) {
|
||||
pushresult(0);
|
||||
@@ -150,7 +147,7 @@ static void io_readfrom (void)
|
||||
static void io_writeto (void)
|
||||
{
|
||||
FILE *current;
|
||||
lua_Object f = lua_getparam(FIRSTARG);
|
||||
lua_Object f = lua_getparam(1);
|
||||
if (f == LUA_NOOBJECT) {
|
||||
closefile(FOUTPUT);
|
||||
current = stdout;
|
||||
@@ -158,7 +155,7 @@ static void io_writeto (void)
|
||||
else if (lua_tag(f) == gettag(IOTAG))
|
||||
current = lua_getuserdata(f);
|
||||
else {
|
||||
char *s = luaL_check_string(FIRSTARG);
|
||||
char *s = luaL_check_string(1);
|
||||
current = (*s == '|') ? popen(s+1,"w") : fopen(s,"w");
|
||||
if (current == NULL) {
|
||||
pushresult(0);
|
||||
@@ -171,7 +168,7 @@ static void io_writeto (void)
|
||||
|
||||
static void io_appendto (void)
|
||||
{
|
||||
char *s = luaL_check_string(FIRSTARG);
|
||||
char *s = luaL_check_string(1);
|
||||
FILE *fp = fopen (s, "a");
|
||||
if (fp != NULL)
|
||||
setreturn(fp, FOUTPUT);
|
||||
@@ -184,7 +181,7 @@ static void io_appendto (void)
|
||||
|
||||
static void io_read (void)
|
||||
{
|
||||
int arg = FIRSTARG;
|
||||
int arg = 1;
|
||||
FILE *f = getfileparam(FINPUT, &arg);
|
||||
char *buff;
|
||||
char *p = luaL_opt_string(arg, "[^\n]*{\n}");
|
||||
@@ -236,7 +233,7 @@ static void io_read (void)
|
||||
|
||||
static void io_write (void)
|
||||
{
|
||||
int arg = FIRSTARG;
|
||||
int arg = 1;
|
||||
FILE *f = getfileparam(FOUTPUT, &arg);
|
||||
int status = 1;
|
||||
char *s;
|
||||
|
||||
Reference in New Issue
Block a user