22 #define luaU_print PrintFunction
24 #define PROGNAME "luac"
25 #define OUTPUT PROGNAME ".out"
36 fprintf(stderr,
"%s: %s\n",
progname,message);
42 fprintf(stderr,
"%s: cannot %s %s: %s\n",
progname,what,
output,strerror(errno));
49 fprintf(stderr,
"%s: unrecognized option " LUA_QS "\n",
progname,message);
51 fprintf(stderr,
"%s: %s\n",
progname,message);
53 "usage: %s [options] [filenames]\n"
54 "Available options are:\n"
55 " -l list (use -l -l for full listing)\n"
56 " -o name output to file " LUA_QL(
"name")
" (default is \"%s\")\n"
58 " -s strip debug information\n"
59 " -v show version information\n"
60 " -- stop handling options\n"
61 " - stop handling options and process stdin\n"
66 #define IS(s) (strcmp(argv[i],s)==0)
68 static int doargs(
int argc,
char* argv[])
72 if (argv[0]!=NULL && *argv[0]!=0)
progname=argv[0];
73 for (i=1; i<argc; i++)
111 if (version==argc-1) exit(EXIT_SUCCESS);
116 #define FUNCTION "(function()end)();"
133 #define toproto(L,i) getproto(L->top+(i))
158 return (fwrite(p,size,1,(FILE*)u)!=1) && (size!=0);
168 for (i=0; i<argc; i++)
170 const char* filename=
IS(
"-") ? NULL : argv[
i];
178 if (D==NULL)
cannot(
"open");
182 if (ferror(D))
cannot(
"write");
183 if (fclose(D))
cannot(
"close");
188 int main(
int argc,
char* argv[])
193 if (argc<=0)
usage(
"no input files given");
195 if (L==NULL)
fatal(
"cannot create state: not enough memory");
219 #define VOID(p) ((const void*)(p))
228 int c=(
int)(
unsigned char)s[
i];
231 case '"': printf(
"\\\"");
break;
232 case '\\': printf(
"\\\\");
break;
233 case '\a': printf(
"\\a");
break;
234 case '\b': printf(
"\\b");
break;
235 case '\f': printf(
"\\f");
break;
236 case '\n': printf(
"\\n");
break;
237 case '\r': printf(
"\\r");
break;
238 case '\t': printf(
"\\t");
break;
239 case '\v': printf(
"\\v");
break;
240 default:
if (isprint(c))
258 printf(
bvalue(o) ?
"true" :
"false");
267 printf(
"? type=%d",
ttype(o));
272 #define UPVALNAME(x) ((f->upvalues[x].name) ? getstr(f->upvalues[x].name) : "-")
273 #define MYK(x) (-1-(x))
279 for (pc=0; pc<
n; pc++)
290 printf(
"\t%d\t",pc+1);
291 if (line>0) printf(
"[%d]\t",line);
else printf(
"[-]\t");
306 printf(
"%d %d",a,sbx);
309 printf(
"%d",
MYK(ax));
355 printf(
"\t; to %d",sbx+pc+2);
358 printf(
"\t; %p",
VOID(f->
p[bx]));
361 if (c==0) printf(
"\t; %d",(
int)code[++pc]);
else printf(
"\t; %d",c);
373 #define SS(x) ((x==1)?"":"s")
374 #define S(x) (int)(x),SS(x)
379 if (*s==
'@' || *s==
'=')
385 printf(
"\n%s <%s:%d,%d> (%d instruction%s at %p)\n",
389 printf(
"%d%s param%s, %d slot%s, %d upvalue%s, ",
392 printf(
"%d local%s, %d constant%s, %d function%s\n",
400 printf(
"constants (%d) for %p:\n",n,
VOID(f));
403 printf(
"\t%d\t",i+1);
408 printf(
"locals (%d) for %p:\n",n,
VOID(f));
411 printf(
"\t%d\t%s\t%d\t%d\n",
415 printf(
"upvalues (%d) for %p:\n",n,
VOID(f));
418 printf(
"\t%d\t%s\t%d\t%d\n",
static void usage(const char *message)
LUA_API void lua_pushlightuserdata(lua_State *L, void *p)
#define lua_pushcfunction(L, f)
static void PrintCode(const Proto *f)
static void PrintHeader(const Proto *f)
LUALIB_API lua_State * luaL_newstate(void)
static void fatal(const char *message)
int luaU_dump(lua_State *L, const Proto *f, lua_Writer w, void *data, int strip)
static void PrintDebug(const Proto *f)
#define getfuncline(f, pc)
#define lua_tointeger(L, i)
const char * what() const
#define luaL_loadfile(L, f)
GLdouble GLdouble GLdouble b
#define lua_pcall(L, n, r, f)
static int writer(lua_State *L, const void *p, size_t size, void *u)
static void PrintFunction(const Proto *f, int full)
GLboolean GLboolean GLboolean GLboolean a
LUA_API void lua_close(lua_State *L)
int main(int argc, char *argv[])
typedef int(WINAPI *PFNWGLRELEASEPBUFFERDCARBPROC)(HPBUFFERARB hPbuffer
LUAI_DDEF const char *const luaP_opnames[NUM_OPCODES+1]
LUA_API void * lua_touserdata(lua_State *L, int idx)
static const char * output
static const char * progname
LUA_API int lua_load(lua_State *L, lua_Reader reader, void *data, const char *chunkname, const char *mode)
#define lua_tostring(L, i)
static const Proto * combine(lua_State *L, int n)
static const char * reader(lua_State *L, void *ud, size_t *size)
static void cannot(const char *what)
static int doargs(int argc, char *argv[])
static void PrintString(const TString *ts)
LUA_API int lua_checkstack(lua_State *L, int size)
GLsizei GLenum GLuint GLuint GLsizei char * message
static int pmain(lua_State *L)
static void PrintConstant(const Proto *f, int i)
LUA_API void lua_pushinteger(lua_State *L, lua_Integer n)
const std::string version