26#define luaU_print PrintFunction
28#define PROGNAME "luac"
29#define OUTPUT PROGNAME ".out"
38static void fatal(
const char* message)
40 fprintf(stderr,
"%s: %s\n",
progname,message);
46 fprintf(stderr,
"%s: cannot %s %s: %s\n",
progname,what,
output,strerror(errno));
50static void usage(
const char* message)
53 fprintf(stderr,
"%s: unrecognized option '%s'\n",
progname,message);
55 fprintf(stderr,
"%s: %s\n",
progname,message);
57 "usage: %s [options] [filenames]\n"
58 "Available options are:\n"
59 " -l list (use -l -l for full listing)\n"
60 " -o name output to file 'name' (default is \"%s\")\n"
62 " -s strip debug information\n"
63 " -v show version information\n"
64 " -- stop handling options\n"
65 " - stop handling options and process stdin\n"
70#define IS(s) (strcmp(argv[i],s)==0)
72static int doargs(
int argc,
char* argv[])
77 for (i=1; i<argc; i++)
84 if (version) ++version;
95 usage(
"'-o' needs argument");
115 if (version==argc-1) exit(EXIT_SUCCESS);
120#define FUNCTION "(function()end)();"
137#define toproto(L,i) getproto(L->top+(i))
162 return (
fwrite(p,size,1,(FILE*)u)!=1) && (size!=0);
172 for (i=0; i<argc; i++)
174 const char* filename=
IS(
"-") ?
NULL : argv[i];
186 if (ferror(D))
cannot(
"write");
187 if (fclose(D))
cannot(
"close");
192int main(
int argc,
char* argv[])
197 if (argc<=0)
usage(
"no input files given");
199 if (L==
NULL)
fatal(
"cannot create state: not enough memory");
224#define VOID(p) ((const void*)(p))
233 int c=(int)(
unsigned char)
s[i];
236 case '"':
printf(
"\\\"");
break;
237 case '\\':
printf(
"\\\\");
break;
238 case '\a':
printf(
"\\a");
break;
239 case '\b':
printf(
"\\b");
break;
240 case '\f':
printf(
"\\f");
break;
241 case '\n':
printf(
"\\n");
break;
242 case '\r':
printf(
"\\r");
break;
243 case '\t':
printf(
"\\t");
break;
244 case '\v':
printf(
"\\v");
break;
245 default:
if (isprint(c))
270 if (buff[strspn(buff,
"-0123456789")]==
'\0')
printf(
".0");
285#define UPVALNAME(x) ((f->upvalues[x].name) ? getstr(f->upvalues[x].name) : "-")
286#define MYK(x) (-1-(x))
292 for (pc=0; pc<n; pc++)
304 if (line>0)
printf(
"[%d]\t",line);
else printf(
"[-]\t");
375 printf(
"\t; to %d",sbx+pc+2);
381 if (c==0)
printf(
"\t; %d",(
int)code[++pc]);
else printf(
"\t; %d",c);
393#define SS(x) ((x==1)?"":"s")
394#define S(x) (int)(x),SS(x)
399 if (*
s==
'@' || *
s==
'=')
405 printf(
"\n%s <%s:%d,%d> (%d instruction%s at %p)\n",
409 printf(
"%d%s param%s, %d slot%s, %d upvalue%s, ",
412 printf(
"%d local%s, %d constant%s, %d function%s\n",
431 printf(
"\t%d\t%s\t%d\t%d\n",
438 printf(
"\t%d\t%s\t%d\t%d\n",
LUA_API int lua_load(lua_State *L, lua_Reader reader, void *data, const char *chunkname)
LUA_API void lua_pushlightuserdata(lua_State *L, void *p)
LUA_API void * lua_touserdata(lua_State *L, int idx)
LUA_API int lua_checkstack(lua_State *L, int size)
LUA_API void lua_pushinteger(lua_State *L, lua_Integer n)
LUALIB_API lua_State * luaL_newstate(void)
int luaU_dump(lua_State *L, const Proto *f, lua_Writer w, void *data, int strip)
const char *const luaP_opnames[NUM_OPCODES+1]
LUA_API void lua_close(lua_State *L)
#define lua_pushcfunction(L, f)
#define lua_tostring(L, i)
#define luaL_loadfile(L, f)
#define getfuncline(f, pc)
#define lua_tointeger(L, i)
#define lua_pcall(L, n, r, f)
static void PrintDebug(const Proto *f)
static int doargs(int argc, char *argv[])
static const char * output
static const Proto * combine(lua_State *L, int n)
static void PrintString(const TString *ts)
static const char * reader(lua_State *L, void *ud, size_t *size)
static void fatal(const char *message)
static void PrintConstant(const Proto *f, int i)
static void usage(const char *message)
static int writer(lua_State *L, const void *p, size_t size, void *u)
static int pmain(lua_State *L)
static void PrintHeader(const Proto *f)
static void PrintCode(const Proto *f)
static void cannot(const char *what)
static const char * progname
CURL_EXTERN CURLMcode curl_socket_t s