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 65 if (badoption[1] ==
'e' || badoption[1] ==
'l')
70 "usage: %s [options] [script [args]]\n" 71 "Available options are:\n" 72 " -e stat execute string 'stat'\n" 73 " -i enter interactive mode after executing 'script'\n" 74 " -l name require library 'name' into global 'name'\n" 75 " -v show version information\n" 76 " -E ignore environment variables\n" 77 " -W turn warnings on\n" 78 " -- stop handling options\n" 79 " - stop handling options and execute stdin\n" 89 static void l_message (
const char *pname,
const char *msg) {
140 signal(SIGINT, SIG_DFL);
162 if (script == argc) script = 0;
163 narg = argc - (script + 1);
165 for (i = 0; i < argc; i++) {
213 for (i = 1; i <= n; i++)
222 const char *fname = argv[0];
223 if (strcmp(fname,
"-") == 0 && strcmp(argv[-1],
"--") != 0)
251 for (i = 1; argv[i] != NULL; i++) {
253 if (argv[i][0] !=
'-')
255 switch (argv[i][1]) {
257 if (argv[i][2] !=
'\0')
264 if (argv[i][2] !=
'\0')
269 if (argv[i][2] !=
'\0')
275 if (argv[i][2] !=
'\0')
282 if (argv[i][2] ==
'\0') {
284 if (argv[i] == NULL || argv[i][0] ==
'-')
304 for (i = 1; i < n; i++) {
305 int option = argv[i][1];
308 case 'e':
case 'l': {
310 const char *extra = argv[i] + 2;
311 if (*extra ==
'\0') extra = argv[++i];
313 status = (option ==
'e')
314 ?
dostring(L, extra,
"=(command line)")
316 if (status !=
LUA_OK)
return 0;
330 const char *init = getenv(name + 1);
333 init = getenv(name + 1);
335 if (init == NULL)
return LUA_OK;
336 else if (init[0] ==
'@')
349 #if !defined(LUA_PROMPT) 350 #define LUA_PROMPT "> " 351 #define LUA_PROMPT2 ">> " 354 #if !defined(LUA_MAXINPUT) 355 #define LUA_MAXINPUT 512 363 #if !defined(lua_stdin_is_tty) 365 #if defined(LUA_USE_POSIX) 368 #define lua_stdin_is_tty() isatty(0) 370 #elif defined(LUA_USE_WINDOWS) 375 #define lua_stdin_is_tty() _isatty(_fileno(stdin)) 380 #define lua_stdin_is_tty() 1 393 #if !defined(lua_readline) 395 #if defined(LUA_USE_READLINE) 397 #include <readline/readline.h> 398 #include <readline/history.h> 399 #define lua_initreadline(L) ((void)L, rl_readline_name="lua") 400 #define lua_readline(L,b,p) ((void)L, ((b)=readline(p)) != NULL) 401 #define lua_saveline(L,line) ((void)L, add_history(line)) 402 #define lua_freeline(L,b) ((void)L, free(b)) 406 #define lua_initreadline(L) ((void)L) 407 #define lua_readline(L,b,p) \ 408 ((void)L, fputs(p, stdout), fflush(stdout), \ 409 fgets(b, LUA_MAXINPUT, stdin) != NULL) 410 #define lua_saveline(L,line) { (void)L; (void)line; } 411 #define lua_freeline(L,b) { (void)L; (void)b; } 430 #define EOFMARK "<eof>" 431 #define marklen (sizeof(EOFMARK)/sizeof(char) - 1) 465 if (l > 0 && b[l-1] ==
'\n')
467 if (firstline && b[0] ==
'=')
558 while ((status =
loadline(L)) != -1) {
582 if (argv[0] && argv[0][0])
progname = argv[0];
596 if (!(args & has_E)) {
607 else if (script == argc && !(args & (
has_e | has_v))) {
619 int main (
int argc,
char **argv) {
623 l_message(argv[0],
"cannot create state: not enough memory");
633 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)
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 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)
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)