21#if !defined(LUA_PROMPT)
22#define LUA_PROMPT "> "
23#define LUA_PROMPT2 ">> "
26#if !defined(LUA_PROGNAME)
27#define LUA_PROGNAME "lua"
30#if !defined(LUA_MAXINPUT)
31#define LUA_MAXINPUT 512
35#define LUA_INIT "LUA_INIT"
38#define LUA_INITVERSION \
39 LUA_INIT "_" LUA_VERSION_MAJOR "_" LUA_VERSION_MINOR
46#if defined(LUA_USE_ISATTY)
48#define lua_stdin_is_tty() isatty(0)
52#define lua_stdin_is_tty() _isatty(_fileno(stdin))
54#define lua_stdin_is_tty() 1
64#if defined(LUA_USE_READLINE)
67#include <readline/readline.h>
68#include <readline/history.h>
69#define lua_readline(L,b,p) ((void)L, ((b)=readline(p)) != NULL)
70#define lua_saveline(L,idx) \
71 if (lua_rawlen(L,idx) > 0) \
72 add_history(lua_tostring(L, idx));
73#define lua_freeline(L,b) ((void)L, free(b))
75#elif !defined(lua_readline)
77#define lua_readline(L,b,p) \
78 ((void)L, fputs(p, stdout), fflush(stdout), \
79 fgets(b, LUA_MAXINPUT, stdin) != NULL)
80#define lua_saveline(L,idx) { (void)L; (void)idx; }
81#define lua_freeline(L,b) { (void)L; (void)b; }
110 if (badoption[1] ==
'e' || badoption[1] ==
'l')
115 "usage: %s [options] [script [args]]\n"
116 "Available options are:\n"
117 " -e stat execute string " LUA_QL(
"stat")
"\n"
118 " -i enter interactive mode after executing " LUA_QL(
"script")
"\n"
119 " -l name require library " LUA_QL(
"name")
"\n"
120 " -v show version information\n"
121 " -E ignore environment variables\n"
122 " -- stop handling options\n"
123 " - stop handling options and execute stdin\n"
129static void l_message (
const char *pname,
const char *msg) {
138 if (msg ==
NULL) msg =
"(error object is not a string)";
153 if (msg ==
NULL) msg =
"(error object is not a string)";
180 signal(SIGINT, SIG_DFL);
196 while (argv[argc]) argc++;
197 narg = argc - (n + 1);
199 for (i=n+1; i < argc; i++)
202 for (i=0; i < argc; i++) {
244#define EOFMARK "<eof>"
245#define marklen (sizeof(EOFMARK)/sizeof(char) - 1)
270 if (l > 0 && b[l-1] ==
'\n')
272 if (firstline && b[0] ==
'=')
307 while ((status =
loadline(L)) != -1) {
316 "error calling " LUA_QL(
"print")
" (%s)",
329 int narg =
getargs(L, argv, n);
332 if (strcmp(fname,
"-") == 0 && strcmp(argv[n-1],
"--") != 0)
345#define noextrachars(x) {if ((x)[2] != '\0') return -1;}
359 for (i = 1; argv[i] !=
NULL; i++) {
360 if (argv[i][0] !=
'-')
362 switch (argv[i][1]) {
365 return (argv[i+1] !=
NULL ? i+1 : 0);
381 if (argv[i][2] ==
'\0') {
383 if (argv[i] ==
NULL || argv[i][0] ==
'-')
397 for (i = 1; i < n; i++) {
399 switch (argv[i][1]) {
401 const char *
chunk = argv[i] + 2;
409 const char *filename = argv[i] + 2;
410 if (*filename ==
'\0') filename = argv[++i];
425 const char *init = getenv(
name + 1);
428 init = getenv(
name + 1);
431 else if (init[0] ==
'@')
444 if (argv[0] && argv[0][0])
progname = argv[0];
463 if (!
runargs(L, argv, (script > 0) ? script : argc))
return 0;
468 else if (script == 0 && !args[
has_e] && !args[
has_v]) {
480int main (
int argc,
char **argv) {
484 l_message(argv[0],
"cannot create state: not enough memory");
495 return (result && status ==
LUA_OK) ? EXIT_SUCCESS : EXIT_FAILURE;
LUA_API void lua_pushstring(lua_State *L, const char *s)
LUA_API void lua_concat(lua_State *L, int n)
LUA_API const char * lua_pushfstring(lua_State *L, const char *fmt,...)
LUA_API void lua_setfield(lua_State *L, int idx, const char *k)
LUA_API int lua_toboolean(lua_State *L, int idx)
LUA_API void lua_pushboolean(lua_State *L, int b)
LUA_API const char * lua_tolstring(lua_State *L, int idx, size_t *len)
LUA_API int lua_type(lua_State *L, int idx)
LUA_API void lua_createtable(lua_State *L, int narray, int nrec)
LUA_API void lua_pushlightuserdata(lua_State *L, void *p)
LUA_API void lua_rawseti(lua_State *L, int idx, int n)
LUA_API void * lua_touserdata(lua_State *L, int idx)
LUA_API void lua_settop(lua_State *L, int idx)
LUA_API void lua_pushinteger(lua_State *L, lua_Integer n)
LUA_API int lua_gc(lua_State *L, int what, int data)
LUA_API int lua_gettop(lua_State *L)
LUALIB_API void luaL_checkstack(lua_State *L, int space, const char *mes)
LUALIB_API int luaL_error(lua_State *L, const char *fmt,...)
LUALIB_API lua_State * luaL_newstate(void)
LUALIB_API int luaL_callmeta(lua_State *L, int obj, const char *event)
LUA_API int lua_sethook(lua_State *L, lua_Hook func, int mask, int count)
LUALIB_API void luaL_openlibs(lua_State *L)
static void chunk(LexState *ls)
LUA_API void lua_close(lua_State *L)
static void print_usage(void)
#define lua_pushcfunction(L, f)
#define LUA_REGISTRYINDEX
#define lua_pushliteral(L, s)
#define lua_setglobal(L, s)
#define lua_getglobal(L, s)
#define lua_tostring(L, i)
#define lua_isnoneornil(L, n)
LUALIB_API void luaL_traceback(lua_State *L, lua_State *L1, const char *msg, int level)
#define luaL_loadfile(L, f)
#define luaL_checkversion(L)
#define luaL_loadbuffer(L, s, sz, n)
static const char * get_prompt(lua_State *L, int firstline)
static int report(lua_State *L, int status)
static int getargs(lua_State *L, char **argv, int n)
static void print_version(void)
static int docall(lua_State *L, int narg, int nres)
#define lua_freeline(L, b)
static int handle_luainit(lua_State *L)
static void finalreport(lua_State *L, int status)
static void lstop(lua_State *L, lua_Debug *ar)
static int collectargs(char **argv, int *args)
static int pushline(lua_State *L, int firstline)
static int traceback(lua_State *L)
static int runargs(lua_State *L, char **argv, int n)
static int dofile(lua_State *L, const char *name)
static int pmain(lua_State *L)
#define lua_stdin_is_tty()
static void laction(int i)
static void l_message(const char *pname, const char *msg)
static int dolibrary(lua_State *L, const char *name)
static const char * progname
static int loadline(lua_State *L)
#define lua_saveline(L, idx)
static int dostring(lua_State *L, const char *s, const char *name)
static int handle_script(lua_State *L, char **argv, int n)
static void dotty(lua_State *L)
static lua_State * globalL
static int incomplete(lua_State *L, int status)
#define lua_readline(L, b, p)
#define lua_tointeger(L, i)
#define lua_pcall(L, n, r, f)
#define luai_writestringerror(s, p)
#define lua_insert(L, idx)
#define lua_remove(L, idx)
CURL_EXTERN CURLMcode curl_socket_t s