24 #if !defined(LUA_PROGNAME) 25 #define LUA_PROGNAME "lua" 28 #if !defined(LUA_INIT_VAR) 29 #define LUA_INIT_VAR "LUA_INIT" 32 #define LUA_INITVARVERSION LUA_INIT_VAR LUA_VERSUFFIX 40 #if defined(LUA_USE_POSIX) 45 static void setsignal (
int sig,
void (*handler)(
int)) {
47 sa.sa_handler = handler;
49 sigemptyset(&sa.sa_mask);
50 sigaction(sig, &sa, NULL);
55 #define setsignal signal 85 if (badoption[1] ==
'e' || badoption[1] ==
'l')
90 "usage: %s [options] [script [args]]\n" 91 "Available options are:\n" 92 " -e stat execute string 'stat'\n" 93 " -i enter interactive mode after executing 'script'\n" 94 " -l name require library 'name' into global 'name'\n" 95 " -v show version information\n" 96 " -E ignore environment variables\n" 97 " -W turn warnings on\n" 98 " -- stop handling options\n" 99 " - stop handling options and execute stdin\n" 182 if (script == argc) script = 0;
183 narg = argc - (script + 1);
185 for (i = 0; i < argc; i++) {
233 for (i = 1; i <= n; i++)
242 const char *fname = argv[0];
243 if (strcmp(fname,
"-") == 0 && strcmp(argv[-1],
"--") != 0)
271 for (i = 1; argv[i] != NULL; i++) {
273 if (argv[i][0] !=
'-')
275 switch (argv[i][1]) {
277 if (argv[i][2] !=
'\0')
284 if (argv[i][2] !=
'\0')
289 if (argv[i][2] !=
'\0')
295 if (argv[i][2] !=
'\0')
302 if (argv[i][2] ==
'\0') {
304 if (argv[i] == NULL || argv[i][0] ==
'-')
324 for (i = 1; i < n; i++) {
325 int option = argv[i][1];
328 case 'e':
case 'l': {
330 const char *extra = argv[i] + 2;
331 if (*extra ==
'\0') extra = argv[++i];
333 status = (option ==
'e')
334 ?
dostring(L, extra,
"=(command line)")
336 if (status !=
LUA_OK)
return 0;
350 const char *
init = getenv(name + 1);
353 init = getenv(name + 1);
355 if (init == NULL)
return LUA_OK;
356 else if (init[0] ==
'@')
369 #if !defined(LUA_PROMPT) 370 #define LUA_PROMPT "> " 371 #define LUA_PROMPT2 ">> " 374 #if !defined(LUA_MAXINPUT) 375 #define LUA_MAXINPUT 512 383 #if !defined(lua_stdin_is_tty) 385 #if defined(LUA_USE_POSIX) 388 #define lua_stdin_is_tty() isatty(0) 390 #elif defined(LUA_USE_WINDOWS) 395 #define lua_stdin_is_tty() _isatty(_fileno(stdin)) 400 #define lua_stdin_is_tty() 1 413 #if !defined(lua_readline) 415 #if defined(LUA_USE_READLINE) 417 #include <readline/readline.h> 418 #include <readline/history.h> 419 #define lua_initreadline(L) ((void)L, rl_readline_name="lua") 420 #define lua_readline(L,b,p) ((void)L, ((b)=readline(p)) != NULL) 421 #define lua_saveline(L,line) ((void)L, add_history(line)) 422 #define lua_freeline(L,b) ((void)L, free(b)) 426 #define lua_initreadline(L) ((void)L) 427 #define lua_readline(L,b,p) \ 428 ((void)L, fputs(p, stdout), fflush(stdout), \ 429 fgets(b, LUA_MAXINPUT, stdin) != NULL) 430 #define lua_saveline(L,line) { (void)L; (void)line; } 431 #define lua_freeline(L,b) { (void)L; (void)b; } 454 #define EOFMARK "<eof>" 455 #define marklen (sizeof(EOFMARK)/sizeof(char) - 1) 489 if (l > 0 && b[l-1] ==
'\n')
491 if (firstline && b[0] ==
'=')
582 while ((status =
loadline(L)) != -1) {
606 if (argv[0] && argv[0][0])
progname = argv[0];
620 if (!(args & has_E)) {
631 else if (script == argc && !(args & (
has_e | has_v))) {
643 int main (
int argc,
char **argv) {
647 l_message(argv[0],
"cannot create state: not enough memory");
657 return (result && status ==
LUA_OK) ? EXIT_SUCCESS : EXIT_FAILURE;
#define lua_pushcfunction(L, f)
static int incomplete(lua_State *L, int status)
static int dofile(lua_State *L, const char *name)
LUA_API int lua_rawgeti(lua_State *L, int idx, lua_Integer n)
static int runargs(lua_State *L, char **argv, int n)
static void lstop(lua_State *L, lua_Debug *ar)
LUA_API int lua_toboolean(lua_State *L, int idx)
LUA_API void * lua_touserdata(lua_State *L, int idx)
void init(const M_string &remappings)
LUALIB_API int luaL_callmeta(lua_State *L, int obj, const char *event)
LUA_API void lua_setfield(lua_State *L, int idx, const char *k)
#define lua_remove(L, idx)
#define lua_tointeger(L, i)
void script(lua_State *L, lua_Reader reader, void *data, const std::string &chunkname=detail::default_chunk_name(), load_mode mode=load_mode::any)
#define luaL_typename(L, i)
static int handle_script(lua_State *L, char **argv)
LUA_API const char * lua_pushstring(lua_State *L, const char *s)
#define lua_stdin_is_tty()
static int loadline(lua_State *L)
LUA_API void lua_sethook(lua_State *L, lua_Hook func, int mask, int count)
#define luaL_loadbuffer(L, s, sz, n)
#define luaL_loadfile(L, f)
static void print_version(void)
LUA_API void lua_settop(lua_State *L, int idx)
static const char * progname
static void l_message(const char *pname, const char *msg)
LUA_API void lua_setglobal(lua_State *L, const char *name)
LUA_API int lua_getglobal(lua_State *L, const char *name)
#define lua_pcall(L, n, r, f)
static int docall(lua_State *L, int narg, int nres)
LUALIB_API void luaL_openlibs(lua_State *L)
static int multiline(lua_State *L)
static void print_usage(const char *badoption)
static const char * get_prompt(lua_State *L, int firstline)
LUA_API void lua_pushboolean(lua_State *L, int b)
LUA_API void lua_rawseti(lua_State *L, int idx, lua_Integer n)
LUA_API void lua_close(lua_State *L)
static int dolibrary(lua_State *L, const char *name)
#define lua_writestring(s, l)
LUA_API int lua_gc(lua_State *L, int what,...)
static lua_State * globalL
static int pushline(lua_State *L, int firstline)
#define lua_pushliteral(L, s)
LUA_API const char * lua_tolstring(lua_State *L, int idx, size_t *len)
#define lua_initreadline(L)
LUALIB_API lua_Integer luaL_len(lua_State *L, int idx)
LUALIB_API void luaL_checkstack(lua_State *L, int space, const char *msg)
#define luaL_checkversion(L)
LUALIB_API const char * luaL_tolstring(lua_State *L, int idx, size_t *len)
LUALIB_API void luaL_traceback(lua_State *L, lua_State *L1, const char *msg, int level)
LUA_API void lua_concat(lua_State *L, int n)
#define LUA_INITVARVERSION
static void doREPL(lua_State *L)
static void laction(int i)
LUA_API int lua_type(lua_State *L, int idx)
LUA_API void lua_createtable(lua_State *L, int narray, int nrec)
const T & first(const T &value, const Tail &...)
static int pmain(lua_State *L)
#define lua_tostring(L, i)
static int handle_luainit(lua_State *L)
static int dochunk(lua_State *L, int status)
static int dostring(lua_State *L, const char *s, const char *name)
static int msghandler(lua_State *L)
LUALIB_API int luaL_error(lua_State *L, const char *fmt,...)
static void l_print(lua_State *L)
LUA_API void lua_pushinteger(lua_State *L, lua_Integer n)
#define LUA_REGISTRYINDEX
LUA_API void lua_pushlightuserdata(lua_State *L, void *p)
#define lua_saveline(L, line)
LUALIB_API lua_State * luaL_newstate(void)
static int pushargs(lua_State *L)
#define lua_writestringerror(s, p)
LUA_API const char * lua_pushfstring(lua_State *L, const char *fmt,...)
#define lua_insert(L, idx)
LUA_API const char * lua_pushlstring(lua_State *L, const char *s, size_t len)
#define lua_freeline(L, b)
void lua_warning(lua_State *L, const char *msg, int tocont)
#define lua_readline(L, b, p)
int main(int argc, char **argv)
static int collectargs(char **argv, int *first)
static void createargtable(lua_State *L, char **argv, int argc, int script)
static int addreturn(lua_State *L)
static int report(lua_State *L, int status)
LUA_API int lua_gettop(lua_State *L)