int main(int argc, char *argv[]) { int filename_pos = 1; if (argc != filename_pos + 1) { fprintf(stderr, "Usage: delua file.lua\n"); exit(1); } char *filename = argv[filename_pos]; FILE *f = fopen(filename, "rb"); if (f == NULL) { perror(filename); exit(1); } lua_open(); ZIO z; luaZ_Fopen(&z, f, filename); TProtoFunc *tf = luaU_undump1(&z); fclose(f); if (tf == NULL) { fprintf(stderr, "%s isn't a valid lua script\n", filename); exit(1); } decompile(std::cout, tf, "", NULL, 0); lua_close(); return 0; }
static Proto* load(const char* filename) { Proto* tf; ZIO z; char source[512]; FILE* f; int c,undump; if (filename==NULL) { f=stdin; filename="(stdin)"; } else f=efopen(filename,"r"); c=ungetc(fgetc(f),f); if (ferror(f)) { fprintf(stderr,"luac: cannot read from "); perror(filename); exit(1); } undump=(c==ID_CHUNK); if (undump && f!=stdin) { fclose(f); f=efopen(filename,"rb"); } sprintf(source,"@%.*s",Sizeof(source)-2,filename); luaZ_Fopen(&z,f,source); tf = undump ? luaU_undump(L,&z) : luaY_parser(L,&z); if (f!=stdin) fclose(f); return tf; }
static int parse_file (lua_State *L, const char *filename) { ZIO z; int status; int bin; /* flag for file mode */ int c; /* look ahead char */ PHYSFS_file *f = PHYSFS_openRead(filename, -1); if (f == NULL) return LUA_ERRFILE; /* unable to open file */ c = my_physfs_fgetc(f); PHYSFS_close(f); f = PHYSFS_openRead(filename, -1); bin = (c == ID_CHUNK); lua_pushstring(L, "@"); lua_pushstring(L, filename); lua_concat(L, 2); filename = lua_tostring(L, -1); /* filename = '@'..filename */ lua_pop(L, 1); /* OK: there is no GC during parser */ luaZ_Fopen(&z, f, filename); status = protectedparser(L, &z, bin); PHYSFS_close(f); return status; }
int lua_dofile (char *filename) { ZIO z; int status; int c; int bin; char source[MAXFILENAME]; FILE *f = (filename == NULL) ? stdin : fopen(filename, "r"); if (f == NULL) return 2; luaL_filesource(source, filename, sizeof(source)); c = fgetc(f); ungetc(c, f); bin = (c == ID_CHUNK); if (bin && f != stdin) { f = freopen(filename, "rb", f); /* set binary mode */ if (f == NULL) return 2; } luaZ_Fopen(&z, f, source); status = do_main(&z, bin); if (f != stdin) fclose(f); return status; }
static Proto* load(const char* filename) { Proto* tf; ZIO z; char source[512]; PHYSFS_file* f; /* Open the file */ f = efopen(filename, "r"); sprintf(source,"@%.*s",Sizeof(source)-2,filename); luaZ_Fopen(&z,f,source); /* Parse the lua code */ tf = luaY_parser(compile_lua_state,&z); /* Close the file */ my_fclose(f); return tf; }