23#define luaU_print PrintFunction
25#define PROGNAME "luac"
26#define OUTPUT PROGNAME ".out"
35static void fatal(
const char* message)
37 fprintf(stderr,
"%s: %s\n",
progname,message);
43 fprintf(stderr,
"%s: cannot %s %s: %s\n",
progname,what,
output,strerror(errno));
47static void usage(
const char* message)
50 fprintf(stderr,
"%s: unrecognized option " LUA_QS "\n",
progname,message);
52 fprintf(stderr,
"%s: %s\n",
progname,message);
54 "usage: %s [options] [filenames]\n"
55 "Available options are:\n"
56 " -l list (use -l -l for full listing)\n"
57 " -o name output to file " LUA_QL(
"name")
" (default is \"%s\")\n"
59 " -s strip debug information\n"
60 " -v show version information\n"
61 " -- stop handling options\n"
62 " - stop handling options and process stdin\n"
67#define IS(s) (strcmp(argv[i],s)==0)
69static int doargs(
int argc,
char* argv[])
74 for (i=1; i<argc; i++)
81 if (version) ++version;
112 if (version==argc-1) exit(EXIT_SUCCESS);
117#define FUNCTION "(function()end)();"
134#define toproto(L,i) getproto(L->top+(i))
159 return (
fwrite(p,size,1,(FILE*)u)!=1) && (size!=0);
169 for (i=0; i<argc; i++)
171 const char* filename=
IS(
"-") ?
NULL : argv[i];
183 if (ferror(D))
cannot(
"write");
184 if (fclose(D))
cannot(
"close");
189int main(
int argc,
char* argv[])
194 if (argc<=0)
usage(
"no input files given");
196 if (L==
NULL)
fatal(
"cannot create state: not enough memory");
221#define VOID(p) ((const void*)(p))
230 int c=(int)(
unsigned char)
s[i];
233 case '"':
printf(
"\\\"");
break;
234 case '\\':
printf(
"\\\\");
break;
235 case '\a':
printf(
"\\a");
break;
236 case '\b':
printf(
"\\b");
break;
237 case '\f':
printf(
"\\f");
break;
238 case '\n':
printf(
"\\n");
break;
239 case '\r':
printf(
"\\r");
break;
240 case '\t':
printf(
"\\t");
break;
241 case '\v':
printf(
"\\v");
break;
242 default:
if (isprint(c))
274#define UPVALNAME(x) ((f->upvalues[x].name) ? getstr(f->upvalues[x].name) : "-")
275#define MYK(x) (-1-(x))
281 for (pc=0; pc<n; pc++)
293 if (line>0)
printf(
"[%d]\t",line);
else printf(
"[-]\t");
357 printf(
"\t; to %d",sbx+pc+2);
363 if (c==0)
printf(
"\t; %d",(
int)code[++pc]);
else printf(
"\t; %d",c);
375#define SS(x) ((x==1)?"":"s")
376#define S(x) (int)(x),SS(x)
381 if (*
s==
'@' || *
s==
'=')
387 printf(
"\n%s <%s:%d,%d> (%d instruction%s at %p)\n",
391 printf(
"%d%s param%s, %d slot%s, %d upvalue%s, ",
394 printf(
"%d local%s, %d constant%s, %d function%s\n",
413 printf(
"\t%d\t%s\t%d\t%d\n",
420 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