diff options
Diffstat (limited to 'engines/sword25/util/lua/lauxlib.cpp')
-rw-r--r-- | engines/sword25/util/lua/lauxlib.cpp | 39 |
1 files changed, 23 insertions, 16 deletions
diff --git a/engines/sword25/util/lua/lauxlib.cpp b/engines/sword25/util/lua/lauxlib.cpp index ce61827e0f..3b54cf98f1 100644 --- a/engines/sword25/util/lua/lauxlib.cpp +++ b/engines/sword25/util/lua/lauxlib.cpp @@ -22,7 +22,8 @@ #include "lua.h" #include "lauxlib.h" - +#include "scummvm_file.h" +#include "common\textconsole.h" #define FREELIST_REF 0 /* free list of references */ @@ -520,7 +521,7 @@ LUALIB_API void luaL_unref (lua_State *L, int t, int ref) { typedef struct LoadF { int extraline; - FILE *f; + Sword25::Sword25FileProxy *f; char buff[LUAL_BUFFERSIZE]; } LoadF; @@ -533,8 +534,8 @@ static const char *getF (lua_State *L, void *ud, size_t *size) { *size = 1; return "\n"; } - if (feof(lf->f)) return NULL; - *size = fread(lf->buff, 1, sizeof(lf->buff), lf->f); + if (lf->f->eof()) return NULL; + *size = lf->f->read(lf->buff, 1, sizeof(lf->buff)); return (*size > 0) ? lf->buff : NULL; } @@ -551,9 +552,13 @@ static int errfile (lua_State *L, const char *what, int fnameindex) { LUALIB_API int luaL_loadfile (lua_State *L, const char *filename) { LoadF lf; int status, readstatus; - int c; +// int c; int fnameindex = lua_gettop(L) + 1; /* index of filename on the stack */ lf.extraline = 0; + + lua_pushfstring(L, "@%s", filename); + lf.f = new Sword25::Sword25FileProxy(filename, "r"); +/* if (filename == NULL) { lua_pushliteral(L, "=stdin"); lf.f = stdin; @@ -563,23 +568,25 @@ LUALIB_API int luaL_loadfile (lua_State *L, const char *filename) { lf.f = fopen(filename, "r"); if (lf.f == NULL) return errfile(L, "open", fnameindex); } - c = getc(lf.f); - if (c == '#') { /* Unix exec. file? */ + + c = lf.f->getc(); + if (c == '#') { // Unix exec. file? lf.extraline = 1; - while ((c = getc(lf.f)) != EOF && c != '\n') ; /* skip first line */ - if (c == '\n') c = getc(lf.f); + while ((c = lf.f->getc()) != EOF && c != '\n') ; // skip first line + if (c == '\n') c = lf.f->getc(); } - if (c == LUA_SIGNATURE[0] && filename) { /* binary file? */ - lf.f = freopen(filename, "rb", lf.f); /* reopen in binary mode */ + if (c == LUA_SIGNATURE[0] && filename) { // binary file? + lf.f = freopen(filename, "rb", lf.f); // reopen in binary mode if (lf.f == NULL) return errfile(L, "reopen", fnameindex); - /* skip eventual `#!...' */ - while ((c = getc(lf.f)) != EOF && c != LUA_SIGNATURE[0]) ; + // skip eventual `#!...' + while ((c = lf.f->getc()) != EOF && c != LUA_SIGNATURE[0]) ; lf.extraline = 0; } ungetc(c, lf.f); +*/ status = lua_load(L, getF, &lf, lua_tostring(L, -1)); - readstatus = ferror(lf.f); - if (filename) fclose(lf.f); /* close file (even in case of errors) */ + readstatus = 0; //ferror(lf.f); + if (filename) delete lf.f; // close file (even in case of errors) if (readstatus) { lua_settop(L, fnameindex); /* ignore results from `lua_load' */ return errfile(L, "read", fnameindex); @@ -637,7 +644,7 @@ static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) { static int panic (lua_State *L) { (void)L; /* to avoid warnings */ - fprintf(stderr, "PANIC: unprotected error in call to Lua API (%s)\n", + warning("PANIC: unprotected error in call to Lua API (%s)\n", lua_tostring(L, -1)); return 0; } |