mirror of https://github.com/rusefi/lua.git
"zio" now keeps its "name".
This commit is contained in:
parent
a78eecee48
commit
03f3f9e707
28
ldo.c
28
ldo.c
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: ldo.c,v 1.16 1997/12/17 20:57:20 roberto Exp roberto $
|
** $Id: ldo.c,v 1.17 1997/12/18 18:32:39 roberto Exp roberto $
|
||||||
** Stack and Call structure of Lua
|
** Stack and Call structure of Lua
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -296,7 +296,7 @@ int luaD_protectedrun (int nResults)
|
||||||
/*
|
/*
|
||||||
** returns 0 = chunk loaded; 1 = error; 2 = no more chunks to load
|
** returns 0 = chunk loaded; 1 = error; 2 = no more chunks to load
|
||||||
*/
|
*/
|
||||||
static int protectedparser (ZIO *z, char *chunkname, int bin)
|
static int protectedparser (ZIO *z, int bin)
|
||||||
{
|
{
|
||||||
int status;
|
int status;
|
||||||
TProtoFunc *tf;
|
TProtoFunc *tf;
|
||||||
|
@ -304,7 +304,7 @@ static int protectedparser (ZIO *z, char *chunkname, int bin)
|
||||||
jmp_buf *oldErr = L->errorJmp;
|
jmp_buf *oldErr = L->errorJmp;
|
||||||
L->errorJmp = &myErrorJmp;
|
L->errorJmp = &myErrorJmp;
|
||||||
if (setjmp(myErrorJmp) == 0) {
|
if (setjmp(myErrorJmp) == 0) {
|
||||||
tf = bin ? luaU_undump1(z, chunkname) : luaY_parser(z, chunkname);
|
tf = bin ? luaU_undump1(z) : luaY_parser(z);
|
||||||
status = 0;
|
status = 0;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -322,12 +322,12 @@ static int protectedparser (ZIO *z, char *chunkname, int bin)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int do_main (ZIO *z, char *chunkname, int bin)
|
static int do_main (ZIO *z, int bin)
|
||||||
{
|
{
|
||||||
int status;
|
int status;
|
||||||
do {
|
do {
|
||||||
long old_blocks = (luaC_checkGC(), L->nblocks);
|
long old_blocks = (luaC_checkGC(), L->nblocks);
|
||||||
status = protectedparser(z, chunkname, bin);
|
status = protectedparser(z, bin);
|
||||||
if (status == 1) return 1; /* error */
|
if (status == 1) return 1; /* error */
|
||||||
else if (status == 2) return 0; /* 'natural' end */
|
else if (status == 2) return 0; /* 'natural' end */
|
||||||
else {
|
else {
|
||||||
|
@ -368,8 +368,8 @@ int lua_dofile (char *filename)
|
||||||
bin = (c == ID_CHUNK);
|
bin = (c == ID_CHUNK);
|
||||||
if (bin)
|
if (bin)
|
||||||
f = freopen(filename, "rb", f); /* set binary mode */
|
f = freopen(filename, "rb", f); /* set binary mode */
|
||||||
luaZ_Fopen(&z, f);
|
luaZ_Fopen(&z, f, filename);
|
||||||
status = do_main(&z, filename, bin);
|
status = do_main(&z, bin);
|
||||||
if (f != stdin)
|
if (f != stdin)
|
||||||
fclose(f);
|
fclose(f);
|
||||||
return status;
|
return status;
|
||||||
|
@ -383,15 +383,15 @@ int lua_dofile (char *filename)
|
||||||
int lua_dostring (char *str)
|
int lua_dostring (char *str)
|
||||||
{
|
{
|
||||||
int status;
|
int status;
|
||||||
char buff[SIZE_PREF+25];
|
char name[SIZE_PREF+25];
|
||||||
char *temp;
|
char *temp;
|
||||||
ZIO z;
|
ZIO z;
|
||||||
if (str == NULL) return 1;
|
if (str == NULL) return 1;
|
||||||
sprintf(buff, "(dostring) >> %." SSIZE_PREF "s", str);
|
sprintf(name, "(dostring) >> %." SSIZE_PREF "s", str);
|
||||||
temp = strchr(buff, '\n');
|
temp = strchr(name, '\n');
|
||||||
if (temp) *temp = 0; /* end string after first line */
|
if (temp) *temp = 0; /* end string after first line */
|
||||||
luaZ_sopen(&z, str);
|
luaZ_sopen(&z, str, name);
|
||||||
status = do_main(&z, buff, 0);
|
status = do_main(&z, 0);
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -401,8 +401,8 @@ int lua_dobuffer (char *buff, int size)
|
||||||
{
|
{
|
||||||
int status;
|
int status;
|
||||||
ZIO z;
|
ZIO z;
|
||||||
luaZ_mopen(&z, buff, size);
|
luaZ_mopen(&z, buff, size, "(buffer)");
|
||||||
status = do_main(&z, "(buffer)", 1);
|
status = do_main(&z, 1);
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: $
|
** $Id: lparser.h,v 1.1 1997/09/16 19:25:59 roberto Exp roberto $
|
||||||
** Syntax analizer and code generator
|
** Syntax analizer and code generator
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -12,7 +12,7 @@
|
||||||
|
|
||||||
|
|
||||||
void luaY_codedebugline (int line);
|
void luaY_codedebugline (int line);
|
||||||
TProtoFunc *luaY_parser (ZIO *z, char *chunkname);
|
TProtoFunc *luaY_parser (ZIO *z);
|
||||||
void luaY_error (char *s);
|
void luaY_error (char *s);
|
||||||
void luaY_syntaxerror (char *s, char *token);
|
void luaY_syntaxerror (char *s, char *token);
|
||||||
|
|
||||||
|
|
6
lua.stx
6
lua.stx
|
@ -1,6 +1,6 @@
|
||||||
%{
|
%{
|
||||||
/*
|
/*
|
||||||
** $Id: lua.stx,v 1.23 1997/12/15 16:17:20 roberto Exp roberto $
|
** $Id: lua.stx,v 1.24 1997/12/22 17:24:11 roberto Exp roberto $
|
||||||
** Syntax analizer and code generator
|
** Syntax analizer and code generator
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -619,14 +619,14 @@ static TProtoFunc *close_func (void)
|
||||||
/*
|
/*
|
||||||
** Parse Lua code.
|
** Parse Lua code.
|
||||||
*/
|
*/
|
||||||
TProtoFunc *luaY_parser (ZIO *z, char *chunkname)
|
TProtoFunc *luaY_parser (ZIO *z)
|
||||||
{
|
{
|
||||||
struct LexState lexstate;
|
struct LexState lexstate;
|
||||||
FuncState state[MAXSTATES];
|
FuncState state[MAXSTATES];
|
||||||
L->currState = L->mainState = &state[0];
|
L->currState = L->mainState = &state[0];
|
||||||
L->lexstate = &lexstate;
|
L->lexstate = &lexstate;
|
||||||
luaX_setinput(z);
|
luaX_setinput(z);
|
||||||
init_state(luaS_new(chunkname));
|
init_state(luaS_new(zname(z)));
|
||||||
if (luaY_parse()) lua_error("parse error");
|
if (luaY_parse()) lua_error("parse error");
|
||||||
return close_func();
|
return close_func();
|
||||||
}
|
}
|
||||||
|
|
12
lzio.c
12
lzio.c
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: lzio.c,v 1.1 1997/09/16 19:25:59 roberto Exp roberto $
|
** $Id: lzio.c,v 1.2 1997/11/21 19:00:46 roberto Exp roberto $
|
||||||
** a generic input stream interface
|
** a generic input stream interface
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -20,22 +20,23 @@ static int zmfilbuf (ZIO* z)
|
||||||
return EOZ;
|
return EOZ;
|
||||||
}
|
}
|
||||||
|
|
||||||
ZIO* zmopen (ZIO* z, char* b, int size)
|
ZIO* zmopen (ZIO* z, char* b, int size, char *name)
|
||||||
{
|
{
|
||||||
if (b==NULL) return NULL;
|
if (b==NULL) return NULL;
|
||||||
z->n=size;
|
z->n=size;
|
||||||
z->p= (unsigned char *)b;
|
z->p= (unsigned char *)b;
|
||||||
z->filbuf=zmfilbuf;
|
z->filbuf=zmfilbuf;
|
||||||
z->u=NULL;
|
z->u=NULL;
|
||||||
|
z->name=name;
|
||||||
return z;
|
return z;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ------------------------------------------------------------ strings --- */
|
/* ------------------------------------------------------------ strings --- */
|
||||||
|
|
||||||
ZIO* zsopen (ZIO* z, char* s)
|
ZIO* zsopen (ZIO* z, char* s, char *name)
|
||||||
{
|
{
|
||||||
if (s==NULL) return NULL;
|
if (s==NULL) return NULL;
|
||||||
return zmopen(z,s,strlen(s));
|
return zmopen(z,s,strlen(s),name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------------------------------------------- FILEs --- */
|
/* -------------------------------------------------------------- FILEs --- */
|
||||||
|
@ -50,13 +51,14 @@ static int zffilbuf (ZIO* z)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ZIO* zFopen (ZIO* z, FILE* f)
|
ZIO* zFopen (ZIO* z, FILE* f, char *name)
|
||||||
{
|
{
|
||||||
if (f==NULL) return NULL;
|
if (f==NULL) return NULL;
|
||||||
z->n=0;
|
z->n=0;
|
||||||
z->p=z->buffer;
|
z->p=z->buffer;
|
||||||
z->filbuf=zffilbuf;
|
z->filbuf=zffilbuf;
|
||||||
z->u=f;
|
z->u=f;
|
||||||
|
z->name=name;
|
||||||
return z;
|
return z;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
11
lzio.h
11
lzio.h
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: lzio.h,v 1.1 1997/09/16 19:25:59 roberto Exp roberto $
|
** $Id: lzio.h,v 1.2 1997/11/21 19:00:46 roberto Exp roberto $
|
||||||
** Buffered streams
|
** Buffered streams
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -22,15 +22,15 @@
|
||||||
|
|
||||||
typedef struct zio ZIO;
|
typedef struct zio ZIO;
|
||||||
|
|
||||||
ZIO* zFopen (ZIO* z, FILE* f); /* open FILEs */
|
ZIO* zFopen (ZIO* z, FILE* f, char *name); /* open FILEs */
|
||||||
ZIO* zsopen (ZIO* z, char* s); /* string */
|
ZIO* zsopen (ZIO* z, char* s, char *name); /* string */
|
||||||
ZIO* zmopen (ZIO* z, char* b, int size); /* memory */
|
ZIO* zmopen (ZIO* z, char* b, int size, char *name); /* memory */
|
||||||
|
|
||||||
int zread (ZIO* z, void* b, int n); /* read next n bytes */
|
int zread (ZIO* z, void* b, int n); /* read next n bytes */
|
||||||
|
|
||||||
#define zgetc(z) (--(z)->n>=0 ? ((int)*(z)->p++): (z)->filbuf(z))
|
#define zgetc(z) (--(z)->n>=0 ? ((int)*(z)->p++): (z)->filbuf(z))
|
||||||
#define zungetc(z) (++(z)->n,--(z)->p)
|
#define zungetc(z) (++(z)->n,--(z)->p)
|
||||||
|
#define zname(z) ((z)->name)
|
||||||
|
|
||||||
|
|
||||||
/* --------- Private Part ------------------ */
|
/* --------- Private Part ------------------ */
|
||||||
|
@ -43,6 +43,7 @@ struct zio {
|
||||||
int (*filbuf)(ZIO* z);
|
int (*filbuf)(ZIO* z);
|
||||||
void* u; /* additional data */
|
void* u; /* additional data */
|
||||||
unsigned char buffer[ZBSIZE]; /* buffer */
|
unsigned char buffer[ZBSIZE]; /* buffer */
|
||||||
|
char *name;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue