Go to the documentation of this file.
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"
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);
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];
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;
static void print_version(void)
static int incomplete(lua_State *L, int status)
LUALIB_API int luaL_callmeta(lua_State *L, int obj, const char *event)
#define lua_pushliteral(L, s)
#define lua_pcall(L, n, r, f)
static int handle_script(lua_State *L, char **argv)
auto first(const T &value, const Tail &...) -> const T &
static int msghandler(lua_State *L)
static int multiline(lua_State *L)
static void l_print(lua_State *L)
LUA_API void lua_setglobal(lua_State *L, const char *name)
#define lua_tostring(L, i)
#define lua_saveline(L, line)
LUA_API void lua_pushinteger(lua_State *L, lua_Integer n)
#define lua_remove(L, idx)
static const char * get_prompt(lua_State *L, int firstline)
#define luaL_typename(L, i)
const LUA_API char * lua_pushfstring(lua_State *L, const char *fmt,...)
LUA_API void lua_concat(lua_State *L, int n)
static int loadline(lua_State *L)
static int collectargs(char **argv, int *first)
#define luaL_loadbuffer(L, s, sz, n)
static void createargtable(lua_State *L, char **argv, int argc, int script)
LUA_API int lua_type(lua_State *L, int idx)
#define luaL_loadfile(L, f)
const LUA_API char * lua_pushstring(lua_State *L, const char *s)
#define lua_stdin_is_tty()
static void print_usage(const char *badoption)
#define lua_writestring(s, l)
#define lua_insert(L, idx)
#define lua_tointeger(L, i)
LUA_API void lua_setfield(lua_State *L, int idx, const char *k)
void lua_warning(lua_State *L, const char *msg, int tocont)
#define luaL_checkversion(L)
LUALIB_API void luaL_openlibs(lua_State *L)
LUA_API void lua_sethook(lua_State *L, lua_Hook func, int mask, int count)
static int dochunk(lua_State *L, int status)
static int dostring(lua_State *L, const char *s, const char *name)
static lua_State * globalL
LUA_API int lua_rawgeti(lua_State *L, int idx, lua_Integer n)
#define lua_readline(L, b, p)
#define LUA_REGISTRYINDEX
LUA_API void * lua_touserdata(lua_State *L, int idx)
static int handle_luainit(lua_State *L)
static void doREPL(lua_State *L)
LUA_API int lua_gettop(lua_State *L)
static const char * progname
LUA_API void lua_settop(lua_State *L, int idx)
LUA_API void lua_pushboolean(lua_State *L, int b)
LUALIB_API lua_Integer luaL_len(lua_State *L, int idx)
LUA_API void lua_close(lua_State *L)
#define lua_pushcfunction(L, f)
static int dolibrary(lua_State *L, const char *name)
static void l_message(const char *pname, const char *msg)
const LUA_API char * lua_pushlstring(lua_State *L, const char *s, size_t len)
static int docall(lua_State *L, int narg, int nres)
LUA_API void lua_rawseti(lua_State *L, int idx, lua_Integer n)
static int pmain(lua_State *L)
static int pushargs(lua_State *L)
LUA_API int lua_getglobal(lua_State *L, const char *name)
LUALIB_API void luaL_checkstack(lua_State *L, int space, const char *msg)
LUALIB_API void luaL_traceback(lua_State *L, lua_State *L1, const char *msg, int level)
LUALIB_API int luaL_error(lua_State *L, const char *fmt,...)
#define lua_freeline(L, b)
#define lua_writestringerror(s, p)
static int report(lua_State *L, int status)
static void lstop(lua_State *L, lua_Debug *ar)
void init(const M_string &remappings)
const LUA_API char * lua_tolstring(lua_State *L, int idx, size_t *len)
LUA_API int lua_toboolean(lua_State *L, int idx)
int main(int argc, char **argv)
LUALIB_API lua_State * luaL_newstate(void)
static int addreturn(lua_State *L)
static int runargs(lua_State *L, char **argv, int n)
static int pushline(lua_State *L, int firstline)
static void laction(int 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 lua_initreadline(L)
LUA_API void lua_createtable(lua_State *L, int narray, int nrec)
LUA_API int lua_gc(lua_State *L, int what,...)
static int dofile(lua_State *L, const char *name)
LUA_API void lua_pushlightuserdata(lua_State *L, void *p)
const LUALIB_API char * luaL_tolstring(lua_State *L, int idx, size_t *len)
#define LUA_INITVARVERSION
plotjuggler
Author(s): Davide Faconti
autogenerated on Mon Nov 11 2024 03:23:45