static int pmain(lua_State* L) { struct Smain* s = (struct Smain*)lua_touserdata(L, 1); int argc=s->argc; char** argv=s->argv; const Proto* f; int i; if (!lua_checkstack(L,argc)) fatal("too many input files"); for (i=0; i<argc; i++) { const char* filename=IS("-") ? NULL : argv[i]; if (luaL_loadfile(L,filename)!=0) fatal(lua_tostring(L,-1)); } f=combine(L,argc); if (listing) luaU_print(f,listing>1); if (dumping) { FILE* D= (output==NULL) ? stdout : fopen(output,"wb"); if (D==NULL) cannot("open"); lua_lock(L); int result=luaU_dump_crosscompile(L,f,writer,D,stripping,target); lua_unlock(L); if (result==LUA_ERR_CC_INTOVERFLOW) fatal("value too big or small for target integer type"); if (result==LUA_ERR_CC_NOTINTEGER) fatal("target lua_Number is integral but fractional value found"); if (ferror(D)) cannot("write"); if (fclose(D)) cannot("close"); } return 0; }
static int pmain(lua_State* L) { struct Smain* s = (struct Smain*)lua_touserdata(L, 1); int argc=s->argc; char** argv=s->argv; const Proto* f; int i; if (!lua_checkstack(L,argc)) fatal("too many input files"); for (i=0; i<argc; i++) { const char* filename=IS("-") ? NULL : argv[i]; if (luaL_loadfile(L,filename)!=0) fatal(lua_tostring(L,-1)); } f=combine(L,argc); if (listing) luaU_print(f,listing>1); if (dumping) { FILE* D= (output==NULL) ? stdout : fopen(output,"wb"); if (D==NULL) cannot("open"); lua_lock(L); luaU_dump(L,f,writer,D,stripping); lua_unlock(L); if (ferror(D)) cannot("write"); if (fclose(D)) cannot("close"); } return 0; }
int main(int argc, char* argv[]) { lua_State* L; Proto* f; int i=doargs(argc,argv); argc-=i; argv+=i; if (argc<=0) usage("no input files given",NULL); L=lua_open(); luaB_opentests(L); for (i=0; i<argc; i++) { const char* filename=IS("-") ? NULL : argv[i]; if (luaL_loadfile(L,filename)!=0) fatal(lua_tostring(L,-1)); } f=combine(L,argc); if (listing) luaU_print(f); if (dumping) { FILE* D=fopen(output,"wb"); if (D==NULL) cannot(output,"open","out"); if (stripping) strip(L,f); luaU_dump(L,f,writer,D); if (ferror(D)) cannot(output,"write","out"); fclose(D); } lua_close(L); return 0; }
void luaU_print(const Proto* f) { int i,n=f->sizep; PrintHeader(f); PrintCode(f); #ifdef DEBUG_PRINT PrintConstants(f); PrintLocals(f); PrintUpvalues(f); #endif for (i=0; i<n; i++) luaU_print(f->p[i]); }
void luaU_print(const Proto* f, int full) { int i,n=f->sizep; PrintHeader(f); PrintCode(f); if (full) { PrintConstants(f); PrintLocals(f); PrintUpvalues(f); } for (i=0; i<n; i++) luaU_print(f->p[i],full); }
static int pmain(lua_State* L) { struct Smain* s = (struct Smain*)lua_touserdata(L, 1); int argc=s->argc; char** argv=s->argv; const Proto* f; int i; if (!lua_checkstack(L,argc)) fatal("too many input files"); if (execute) { if (luaL_loadfile(L,execute)!=0) fatal(lua_tostring(L,-1)); luaL_openlibs(L); lua_pushstring(L, execute); if (lua_pcall(L, 1, 1, 0)) fatal(lua_tostring(L,-1)); if (!lua_isfunction(L, -1)) { lua_pop(L,1); if(argc == 0) return 0; execute = NULL; } } for (i=0; i<argc; i++) { const char* filename=IS("-") ? NULL : argv[i]; if (luaL_loadfile(L,filename)!=0) fatal(lua_tostring(L,-1)); } f=combine(L,argc + (execute ? 1: 0), lookup); if (listing) luaU_print(f,listing>1); if (dumping) { int result; FILE* D= (output==NULL) ? stdout : fopen(output,"wb"); if (D==NULL) cannot("open"); lua_lock(L); if (flash) { result=dumpToFlashImage(L,f,writer, D, stripping, address, maxSize); } else { result=luaU_dump_crosscompile(L,f,writer,D,stripping,target); } lua_unlock(L); if (result==LUA_ERR_CC_INTOVERFLOW) fatal("value too big or small for target integer type"); if (result==LUA_ERR_CC_NOTINTEGER) fatal("target lua_Number is integral but fractional value found"); if (ferror(D)) cannot("write"); if (fclose(D)) cannot("close"); } return 0; }
int lua_dumpSourceCode(lua_State* L, const char *sourceCode, const char* outputPath) { if (luaL_loadstring(L, sourceCode) != LUA_OK) { fatal(lua_tostring(L,-1)); } const Proto* f = combine(L, 1); if (listing) { luaU_print(f,listing>1); } if (dumping) { FILE* D = fopen(outputPath, "wb"); if (D==NULL) { printf(" error to open file!\n"); } lua_lock(L); luaU_dump(L,f,writer,D,stripping); lua_unlock(L); if (ferror(D)) { printf("error in write!\n"); } if (fclose(D)) { printf("error in close!\n"); } } return 0; }
static int pmain(LuaThread* L) { int argc=(int)lua_tointeger(L,1); char** argv=(char**)lua_touserdata(L,2); const LuaProto* f; int i; if (!lua_checkstack(L,argc)) fatal("too many input files"); for (i=0; i<argc; i++) { const char* filename=IS("-") ? NULL : argv[i]; if (luaL_loadfile(L,filename)!=LUA_OK) fatal(lua_tostring(L,-1)); } f=combine(L,argc); if (listing) luaU_print(f,listing>1); if (dumping) { FILE* D= (output==NULL) ? stdout : fopen(output,"wb"); if (D==NULL) cannot("open"); luaU_dump(L,f,writer,D,stripping); if (ferror(D)) cannot("write"); if (fclose(D)) cannot("close"); } return 0; }
static int pmain(lua_State* L) { struct Smain* s = (struct Smain*)lua_touserdata(L, 1); int argc=s->argc; char** argv=s->argv; Proto* f; int scripts=0; int i; if (!lua_checkstack(L,argc)) fatal("too many input files"); lua_gc(L, LUA_GCSTOP, 0); /* stop collector during initialization */ luaL_openlibs(L); /* open libraries */ lua_gc(L, LUA_GCRESTART, 0); /* compile each script from command line into a Lua function. */ for (i=0; i<argc; i++) { const char* filename=IS("-") ? NULL : argv[i]; if(IS("-L")) break; if (luaL_loadfile(L,filename)!=0) fatal(lua_tostring(L,-1)); scripts++; } /* compile each preload library from the command line into a Lua function. */ for (i=0; i<preloads; i++) { char* filename=preload_libs[i]; char* p; /* try loading library as if it is a normal file. */ if (luaL_loadfile(L,filename)!=0) { /* try pre-loading library with 'require' module loading system. */ lua_getglobal(L, "require"); lua_pushstring(L, filename); lua_pushboolean(L, 1); lua_call(L, 2, 1); if (lua_iscfunction(L, -1)) { /* make sure it is not a C-Function. */ lua_pop(L, 1); lua_pushfstring(L, "\nCan't preload C module: '%s'\n", filename); lua_concat(L, 2); /* accumulate with error from luaL_findfile */ fatal(lua_tostring(L,-1)); } if (!lua_isfunction(L, -1)) { /* did we get an error? */ lua_pushliteral(L, "\n"); lua_concat(L, 3); /* accumulate with error from luaL_findfile */ fatal(lua_tostring(L,-1)); } else { lua_remove(L, -2); /* remove error from luaL_findfile. */ } } else { /* convert filename into package name. */ p= filename + strlen(filename); for(;p >= filename; p--) { if(p[0] == '.') { /* Remove file extension. */ p[0] = '\0'; continue; } if(p[0] == '/') { /* Remove file path. */ preload_libs[i] = p+1; break; } } } } /* generate a new Lua function to combine all of the compiled scripts. */ f=combine(L, scripts); if (listing) luaU_print(f,listing>1); if (c_code && !parse_only) { FILE* D= (output==NULL) ? stdout : fopen(output,"wb"); if (D==NULL) cannot("open"); lua_lock(L); slua_dumper_dump(D, output, L, f, stripping); lua_unlock(L); if (ferror(D)) cannot("write"); if (fclose(D)) cannot("close"); } if (dumping && !parse_only) { FILE* D= (output==NULL) ? stdout : fopen(output,"wb"); if (D==NULL) cannot("open"); lua_lock(L); luaU_dump(L,f,writer,D,stripping); lua_unlock(L); if (ferror(D)) cannot("write"); if (fclose(D)) cannot("close"); } return 0; }