29 #define luaU_print PrintFunction 31 #define PROGNAME "luac" 32 #define OUTPUT PROGNAME ".out" 42 static void fatal(
const char* message)
54 static void usage(
const char* message)
61 "usage: %s [options] [filenames]\n" 62 "Available options are:\n" 63 " -l list (use -l -l for full listing)\n" 64 " -o name output to file 'name' (default is \"%s\")\n" 66 " -s strip debug information\n" 67 " -v show version information\n" 68 " -- stop handling options\n" 69 " - stop handling options and process stdin\n" 74 #define IS(s) (strcmp(argv[i],s)==0) 76 static int doargs(
int argc,
char* argv[])
80 if (argv[0]!=NULL && *argv[0]!=0)
progname=argv[0];
81 for (i=1; i<argc; i++)
99 usage(
"'-o' needs argument");
119 if (version==argc-1) exit(EXIT_SUCCESS);
124 #define FUNCTION "(function()end)();" 141 #define toproto(L,i) getproto(s2v(L->top+(i))) 166 return (fwrite(p,size,1,(FILE*)u)!=1) && (size!=0);
177 for (i=0; i<argc; i++)
179 const char* filename=
IS(
"-") ? NULL : argv[i];
187 if (D==NULL)
cannot(
"open");
191 if (ferror(D))
cannot(
"write");
192 if (fclose(D))
cannot(
"close");
197 int main(
int argc,
char* argv[])
202 if (argc<=0)
usage(
"no input files given");
204 if (L==NULL)
fatal(
"cannot create state: not enough memory");
217 #define UPVALNAME(x) ((f->upvalues[x].name) ? getstr(f->upvalues[x].name) : "-") 218 #define VOID(p) ((const void*)(p)) 219 #define eventname(i) (getstr(tmname[i])) 228 int c=(int)(
unsigned char)s[i];
259 if (isprint(c))
printf(
"%c",c);
else printf(
"\\%03d",c);
314 if (buff[strspn(buff,
"-0123456789")]==
'\0')
printf(
".0");
330 #define COMMENT "\t; " 331 #define EXTRAARG GETARG_Ax(code[pc+1]) 332 #define EXTRAARGC (EXTRAARG*(MAXARG_C+1)) 333 #define ISK (isk ? "k" : "") 339 for (pc=0; pc<n; pc++)
354 if (line>0)
printf(
"[%d]\t",line);
else printf(
"[-]\t");
439 printf(
"%d %d %d",a,b,sc);
482 printf(
"%d %d %d",a,b,sc);
485 printf(
"%d %d %d",a,b,sc);
528 printf(
"%d %d %d %d",a,sb,c,isk);
533 printf(
"%d %d %d %d",a,b,c,isk);
563 printf(
"%d %d %d",a,b,isk);
566 printf(
"%d %d %d",a,b,isk);
569 printf(
"%d %d %d",a,b,isk);
572 printf(
"%d %d %d",a,b,isk);
576 printf(
"%d %d %d",a,sb,isk);
579 printf(
"%d %d %d",a,sb,isk);
582 printf(
"%d %d %d",a,sb,isk);
585 printf(
"%d %d %d",a,sb,isk);
588 printf(
"%d %d %d",a,sb,isk);
594 printf(
"%d %d %d",a,b,isk);
666 #define SS(x) ((x==1)?"":"s") 667 #define S(x) (int)(x),SS(x) 672 if (*s==
'@' || *s==
'=')
678 printf(
"\n%s <%s:%d,%d> (%d instruction%s at %p)\n",
682 printf(
"%d%s param%s, %d slot%s, %d upvalue%s, ",
685 printf(
"%d local%s, %d constant%s, %d function%s\n",
705 printf(
"\t%d\t%s\t%d\t%d\n",
712 printf(
"\t%d\t%s\t%d\t%d\n",
static int pmain(lua_State *L)
#define lua_pushcfunction(L, f)
int main(int argc, char *argv[])
static const char * progname
int luaU_dump(lua_State *L, const Proto *f, lua_Writer w, void *data, int strip)
static const Proto * combine(lua_State *L, int n)
auto printf(const S &fmt, const T &... args) -> int
LUA_API void * lua_touserdata(lua_State *L, int idx)
static int writer(lua_State *L, const void *p, size_t size, void *u)
#define lua_tointeger(L, i)
auto sprintf(const S &fmt, const T &... args) -> std::basic_string< Char >
static void PrintHeader(const Proto *f)
static void cannot(const char *what)
#define luaL_loadfile(L, f)
#define lua_pcall(L, n, r, f)
static void PrintType(const Proto *f, int i)
auto fprintf(std::FILE *f, const S &fmt, const T &... args) -> int
static void PrintCode(const Proto *f)
LUA_API void lua_close(lua_State *L)
static const char * reader(lua_State *L, void *ud, size_t *size)
static void PrintDebug(const Proto *f)
void version(int *major_, int *minor_, int *patch_)
#define lua_tostring(L, i)
static void PrintString(const TString *ts)
LUA_API int lua_load(lua_State *L, lua_Reader reader, void *data, const char *chunkname, const char *mode)
LUA_API void lua_pushinteger(lua_State *L, lua_Integer n)
LUA_API void lua_pushlightuserdata(lua_State *L, void *p)
static void PrintFunction(const Proto *f, int full)
LUALIB_API lua_State * luaL_newstate(void)
static int doargs(int argc, char *argv[])
span_constexpr std::size_t size(span< T, Extent > const &spn)
static void fatal(const char *message)
static const char * output
static const char *const opnames[]
static void PrintConstant(const Proto *f, int i)
LUA_API int lua_checkstack(lua_State *L, int n)
int luaG_getfuncline(const Proto *f, int pc)
static void usage(const char *message)