diff -urN lua-4.0.1/include/lua.h lua-4.0.1.patched/include/lua.h --- lua-4.0.1/include/lua.h Thu Jun 20 03:51:24 2002 +++ lua-4.0.1.patched/include/lua.h Mon Jul 29 17:03:42 2002 @@ -7,6 +7,11 @@ ** See Copyright Notice at the end of this file */ +/* +** Modified by lua_dolines patch v1.0 +** (c) Juergen Fuhrmann +** email: fuhrmann@wias-berlin.de +*/ #ifndef lua_h #define lua_h @@ -15,6 +20,9 @@ /* definition of `size_t' */ #include +/* definition of 'FILE' */ +#include + /* mark for all API functions */ #ifndef LUA_API @@ -26,6 +34,7 @@ #define LUA_COPYRIGHT "Copyright (C) 1994-2000 TeCGraf, PUC-Rio" #define LUA_AUTHORS "W. Celes, R. Ierusalimschy & L. H. de Figueiredo" +#define LUA_DOLINES 1.1 /* name of global variable with error handler */ #define LUA_ERRORMESSAGE "_ERRORMESSAGE" @@ -157,6 +166,7 @@ LUA_API int lua_call (lua_State *L, int nargs, int nresults); LUA_API void lua_rawcall (lua_State *L, int nargs, int nresults); LUA_API int lua_dofile (lua_State *L, const char *filename); +LUA_API int lua_dolines (lua_State *L, const char *filename, FILE *f, int *lineno); LUA_API int lua_dostring (lua_State *L, const char *str); LUA_API int lua_dobuffer (lua_State *L, const char *buff, size_t size, const char *name); diff -urN lua-4.0.1/src/ldo.c lua-4.0.1.patched/src/ldo.c --- lua-4.0.1/src/ldo.c Thu Jun 20 16:24:40 2002 +++ lua-4.0.1.patched/src/ldo.c Mon Jul 29 17:03:42 2002 @@ -230,20 +230,22 @@ struct ParserS { /* data to `f_parser' */ ZIO *z; int bin; + int lineno; }; static void f_parser (lua_State *L, void *ud) { struct ParserS *p = (struct ParserS *)ud; - Proto *tf = p->bin ? luaU_undump(L, p->z) : luaY_parser(L, p->z); + Proto *tf = p->bin ? luaU_undump(L, p->z) : luaY_parser(L, p->z, &p->lineno); luaV_Lclosure(L, tf, 0); } -static int protectedparser (lua_State *L, ZIO *z, int bin) { +static int protectedparser (lua_State *L, ZIO *z, int bin, int *lineno) { struct ParserS p; unsigned long old_blocks; int status; p.z = z; p.bin = bin; + p.lineno= *lineno; /* before parsing, give a (good) chance to GC */ if (L->nblocks/8>= L->GCthreshold/10) luaC_collectgarbage(L); @@ -255,6 +257,7 @@ } else if (status == LUA_ERRRUN) /* an error occurred: correct error code */ status = LUA_ERRSYNTAX; + *lineno=p.lineno; return status; } @@ -264,6 +267,7 @@ int status; int bin; /* flag for file mode */ int c; /* look ahead char */ + int lineno; /* linenumber */ FILE *f = (filename == NULL) ? stdin : fopen(filename, "r"); if (f == NULL) return LUA_ERRFILE; /* unable to open file */ c = fgetc(f); @@ -279,7 +283,8 @@ c = lua_gettop(L); filename = lua_tostring(L, c); /* filename = '@'..filename */ luaZ_Fopen(&z, f, filename); - status = protectedparser(L, &z, bin); + lineno=1; + status = protectedparser(L, &z, bin, &lineno); lua_remove(L, c); /* remove `filename' from the stack */ if (f != stdin) fclose(f); @@ -295,12 +300,59 @@ } +static int zlfilbuf (ZIO* z) { + size_t n; + if (feof((FILE *)z->u)) return EOZ; + if (fgets((char*)z->buffer,ZBSIZE,(FILE *)z->u)==NULL) return EOZ; + n = 0; + while(z->buffer[n]!='0円') n++; + if (n==0) return EOZ; + z->n = n-1; + z->p = z->buffer; + return *(z->p++); +} + +LUA_API int lua_dolines (lua_State *L, const char *filename, FILE *f, int *lineno) { + ZIO z; + int status; + int bin; /* flag for file mode */ + int fn; /* filename */ + int c; /* look ahead char */ + if (f == NULL) return LUA_ERRFILE; /* unable to access file */ + c = fgetc(f); + ungetc(c, f); + bin = (c == ID_CHUNK); + if (bin && f != stdin) { + return LUA_ERRFILE; /* unable to handle binary file */ + } + lua_pushstring(L, "@"); + lua_pushstring(L, (filename == NULL) ? "(stdin)" : filename); + lua_concat(L, 2); + fn = lua_gettop(L); + filename = lua_tostring(L, fn); /* filename = '@'..filename */ + luaZ_Fopen(&z, f, filename); + z.filbuf=zlfilbuf; + status=0; + status = protectedparser(L, &z, bin, lineno); + if (status == 0) /* parse OK? */ + { + status = lua_call(L, 0, LUA_MULTRET); /* call main */ + } + lua_remove(L, fn); /* remove `filename' from the stack */ + lua_pushstring(L, z.p-1); + lua_setglobal(L,"_lua_dolines_last_line"); + return status; +} + + + static int parse_buffer (lua_State *L, const char *buff, size_t size, const char *name) { ZIO z; + int lineno=1; if (!name) name = "?"; luaZ_mopen(&z, buff, size, name); - return protectedparser(L, &z, buff[0]==ID_CHUNK); + return protectedparser(L, &z, buff[0]==ID_CHUNK,&lineno); } diff -urN lua-4.0.1/src/llex.c lua-4.0.1.patched/src/llex.c --- lua-4.0.1/src/llex.c Fri Oct 20 18:39:03 2000 +++ lua-4.0.1.patched/src/llex.c Mon Jul 29 17:03:42 2002 @@ -291,7 +291,7 @@ continue; case '$': - luaX_error(LS, "unexpected `$' (pragmas are no longer supported)", '$'); + return TK_EOS; break; case '-': diff -urN lua-4.0.1/src/lparser.c lua-4.0.1.patched/src/lparser.c --- lua-4.0.1/src/lparser.c Wed Nov 29 12:57:42 2000 +++ lua-4.0.1.patched/src/lparser.c Mon Jul 29 17:03:42 2002 @@ -344,14 +344,16 @@ } -Proto *luaY_parser (lua_State *L, ZIO *z) { +Proto *luaY_parser (lua_State *L, ZIO *z, int *lineno) { struct LexState lexstate; struct FuncState funcstate; luaX_setinput(L, &lexstate, z, luaS_new(L, zname(z))); + lexstate.linenumber=*lineno; open_func(&lexstate, &funcstate); next(&lexstate); /* read first token */ chunk(&lexstate); check_condition(&lexstate, (lexstate.t.token == TK_EOS), " expected"); + *lineno=lexstate.linenumber; close_func(&lexstate); LUA_ASSERT(funcstate.prev == NULL, "wrong list end"); LUA_ASSERT(funcstate.nupvalues == 0, "no upvalues in main"); diff -urN lua-4.0.1/src/lparser.h lua-4.0.1.patched/src/lparser.h --- lua-4.0.1/src/lparser.h Mon Oct 9 15:47:46 2000 +++ lua-4.0.1.patched/src/lparser.h Mon Jul 29 17:03:42 2002 @@ -54,7 +54,7 @@ } FuncState; -Proto *luaY_parser (lua_State *L, ZIO *z); +Proto *luaY_parser (lua_State *L, ZIO *z, int *lineno); #endif diff -urN lua-4.0.1/src/luac/luac.c lua-4.0.1.patched/src/luac/luac.c --- lua-4.0.1/src/luac/luac.c Mon Nov 6 21:06:27 2000 +++ lua-4.0.1.patched/src/luac/luac.c Mon Jul 29 17:03:42 2002 @@ -120,7 +120,7 @@ ZIO z; char source[512]; FILE* f; - int c,undump; + int c,undump,lineno; if (filename==NULL) { f=stdin; @@ -143,7 +143,7 @@ } sprintf(source,"@%.*s",Sizeof(source)-2,filename); luaZ_Fopen(&z,f,source); - tf = undump ? luaU_undump(L,&z) : luaY_parser(L,&z); + tf = undump ? luaU_undump(L,&z) : luaY_parser(L,&z, &lineno); if (f!=stdin) fclose(f); return tf; }

AltStyle によって変換されたページ (->オリジナル) /