20 #if !defined(LUA_PROMPT)
21 #define LUA_PROMPT "> "
22 #define LUA_PROMPT2 ">> "
25 #if !defined(LUA_PROGNAME)
26 #define LUA_PROGNAME "lua"
29 #if !defined(LUA_MAXINPUT)
30 #define LUA_MAXINPUT 512
33 #if !defined(LUA_INIT)
34 #define LUA_INIT "LUA_INIT"
37 #define LUA_INITVERSION \
38 LUA_INIT "_" LUA_VERSION_MAJOR "_" LUA_VERSION_MINOR
45 #if defined(LUA_USE_ISATTY)
47 #define lua_stdin_is_tty() isatty(0)
48 #elif defined(LUA_WIN)
51 #define lua_stdin_is_tty() _isatty(_fileno(stdin))
53 #define lua_stdin_is_tty() 1
63 #if defined(LUA_USE_READLINE)
66 #include <readline/readline.h>
67 #include <readline/history.h>
68 #define lua_readline(L,b,p) ((void)L, ((b)=readline(p)) != NULL)
69 #define lua_saveline(L,idx) \
70 if (lua_rawlen(L,idx) > 0) \
71 add_history(lua_tostring(L, idx));
72 #define lua_freeline(L,b) ((void)L, free(b))
74 #elif !defined(lua_readline)
76 #define lua_readline(L,b,p) \
77 ((void)L, fputs(p, stdout), fflush(stdout), \
78 fgets(b, LUA_MAXINPUT, stdin) != NULL)
79 #define lua_saveline(L,idx) { (void)L; (void)idx; }
80 #define lua_freeline(L,b) { (void)L; (void)b; }
109 if (badoption[1] ==
'e' || badoption[1] ==
'l')
114 "usage: %s [options] [script [args]]\n"
115 "Available options are:\n"
116 " -e stat execute string " LUA_QL(
"stat")
"\n"
117 " -i enter interactive mode after executing " LUA_QL(
"script")
"\n"
118 " -l name require library " LUA_QL(
"name")
"\n"
119 " -v show version information\n"
120 " -E ignore environment variables\n"
121 " -- stop handling options\n"
122 " - stop handling options and execute stdin\n"
137 if (msg == NULL) msg =
"(error object is not a string)";
152 if (msg == NULL) msg =
"(error object is not a string)";
179 signal(SIGINT, SIG_DFL);
195 while (argv[argc]) argc++;
196 narg = argc - (n + 1);
198 for (i=n+1; i < argc; i++)
201 for (i=0; i < argc; i++) {
243 #define EOFMARK "<eof>"
244 #define marklen (sizeof(EOFMARK)/sizeof(char) - 1)
269 if (l > 0 && b[l-1] ==
'\n')
271 if (firstline && b[0] ==
'=')
306 while ((status =
loadline(L)) != -1) {
315 "error calling " LUA_QL(
"print")
" (%s)",
328 int narg =
getargs(L, argv, n);
331 if (strcmp(fname,
"-") == 0 && strcmp(argv[n-1],
"--") != 0)
344 #define noextrachars(x) {if ((x)[2] != '\0') return -1;}
358 for (i = 1; argv[
i] != NULL; i++) {
359 if (argv[i][0] !=
'-')
361 switch (argv[i][1]) {
364 return (argv[i+1] != NULL ? i+1 : 0);
380 if (argv[i][2] ==
'\0') {
382 if (argv[i] == NULL || argv[i][0] ==
'-')
396 for (i = 1; i <
n; i++) {
398 switch (argv[i][1]) {
400 const char *chunk = argv[
i] + 2;
401 if (*chunk ==
'\0') chunk = argv[++
i];
408 const char *filename = argv[
i] + 2;
409 if (*filename ==
'\0') filename = argv[++
i];
424 const char *
init = getenv(name + 1);
427 init = getenv(name + 1);
429 if (init == NULL)
return LUA_OK;
430 else if (init[0] ==
'@')
443 if (argv[0] && argv[0][0])
progname = argv[0];
462 if (!
runargs(L, argv, (script > 0) ? script : argc))
return 0;
467 else if (script == 0 && !args[
has_e] && !args[has_v]) {
479 int main (
int argc,
char **argv) {
483 l_message(argv[0],
"cannot create state: not enough memory");
494 return (result && status ==
LUA_OK) ? EXIT_SUCCESS : EXIT_FAILURE;
LUALIB_API void luaL_openlibs(lua_State *L)
static void l_message(const char *pname, const char *msg)
#define lua_isnoneornil(L, n)
LUA_API void lua_pushlightuserdata(lua_State *L, void *p)
LUA_API void lua_createtable(lua_State *L, int narray, int nrec)
#define lua_pushcfunction(L, f)
static void print_usage(const char *badoption)
static int handle_script(lua_State *L, char **argv, int n)
GLvoid **typedef void(GLAPIENTRY *PFNGLGETVERTEXATTRIBDVPROC)(GLuint
LUALIB_API lua_State * luaL_newstate(void)
static lua_State * globalL
LUA_API void lua_settop(lua_State *L, int idx)
LUA_API int lua_type(lua_State *L, int idx)
static int runargs(lua_State *L, char **argv, int n)
static void lstop(lua_State *L, lua_Debug *ar)
LUA_API void lua_pushboolean(lua_State *L, int b)
static int docall(lua_State *L, int narg, int nres)
LUA_API void lua_getglobal(lua_State *L, const char *var)
static int report(lua_State *L, int status)
LUA_API int lua_gettop(lua_State *L)
static int dofile(lua_State *L, const char *name)
#define lua_tointeger(L, i)
static int dolibrary(lua_State *L, const char *name)
LUALIB_API void luaL_checkstack(lua_State *L, int space, const char *msg)
#define lua_freeline(L, b)
#define lua_saveline(L, idx)
#define luaL_loadbuffer(L, s, sz, n)
#define luaL_loadfile(L, f)
GLdouble GLdouble GLdouble b
LUA_API int lua_gc(lua_State *L, int what, int data)
#define lua_stdin_is_tty()
static const char * get_prompt(lua_State *L, int firstline)
#define lua_pcall(L, n, r, f)
LUA_API void lua_setglobal(lua_State *L, const char *var)
static int loadline(lua_State *L)
LUA_API int lua_toboolean(lua_State *L, int idx)
LUA_API int lua_sethook(lua_State *L, lua_Hook func, int mask, int count)
LUA_API void lua_close(lua_State *L)
static int pushline(lua_State *L, int firstline)
static int getargs(lua_State *L, char **argv, int n)
LUA_API void lua_remove(lua_State *L, int idx)
LUA_API const char * lua_tolstring(lua_State *L, int idx, size_t *len)
int main(int argc, char **argv)
LUALIB_API int luaL_callmeta(lua_State *L, int obj, const char *event)
typedef int(WINAPI *PFNWGLRELEASEPBUFFERDCARBPROC)(HPBUFFERARB hPbuffer
LUALIB_API void luaL_traceback(lua_State *L, lua_State *L1, const char *msg, int level)
void init()
Initializes the gui subsystems.
#define lua_pushliteral(L, s)
LUA_API void * lua_touserdata(lua_State *L, int idx)
#define luaL_checkversion(L)
#define lua_readline(L, b, p)
static int traceback(lua_State *L)
static void dotty(lua_State *L)
#define lua_tostring(L, i)
static void msg(const char *act, debug_info &i, const char *to="", const char *result="")
LUA_API void lua_rawseti(lua_State *L, int idx, int n)
LUA_API void lua_insert(lua_State *L, int idx)
LUALIB_API int luaL_error(lua_State *L, const char *fmt,...)
#define luai_writestringerror(s, p)
GLuint const GLchar * name
static int pmain(lua_State *L)
#define LUA_REGISTRYINDEX
LUA_API void lua_concat(lua_State *L, int n)
static void finalreport(lua_State *L, int status)
static int collectargs(char **argv, int *args)
LUA_API const char * lua_pushfstring(lua_State *L, const char *fmt,...)
static int incomplete(lua_State *L, int status)
static void laction(int i)
LUA_API void lua_pushinteger(lua_State *L, lua_Integer n)
static int handle_luainit(lua_State *L)
LUA_API const char * lua_pushstring(lua_State *L, const char *s)
LUA_API void lua_setfield(lua_State *L, int idx, const char *k)
static void print_version(void)
static int dostring(lua_State *L, const char *s, const char *name)
static const char * progname