diff options
author | Alex Auvolat <alex@adnab.me> | 2016-07-16 18:07:24 +0200 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2016-07-16 18:07:24 +0200 |
commit | bb2dd23f315bafa7b0b64845c2fe25d7a0893b10 (patch) | |
tree | 51657cd1ad8b6f1d5941604e75c251a246809034 /src/bin | |
parent | 3d6a857b9186ef6304ea6cf04627c2b787169f29 (diff) | |
download | kogata-bb2dd23f315bafa7b0b64845c2fe25d7a0893b10.tar.gz kogata-bb2dd23f315bafa7b0b64845c2fe25d7a0893b10.zip |
Got Lua running \o/
Diffstat (limited to 'src/bin')
-rw-r--r-- | src/bin/lua/lua.c | 63 |
1 files changed, 34 insertions, 29 deletions
diff --git a/src/bin/lua/lua.c b/src/bin/lua/lua.c index 545d23d..8f64451 100644 --- a/src/bin/lua/lua.c +++ b/src/bin/lua/lua.c @@ -4,6 +4,11 @@ ** See Copyright Notice in lua.h */ +// {{ Customization for Kogata +#define LUA_USE_READLINE 1 +// Other customization includes: removing static qualifiers +// }} + #define lua_c #include "lprefix.h" @@ -98,15 +103,15 @@ -static lua_State *globalL = NULL; +lua_State *globalL = NULL; -static const char *progname = LUA_PROGNAME; +const char *progname = LUA_PROGNAME; /* ** Hook set by signal function to stop the interpreter. */ -static void lstop (lua_State *L, lua_Debug *ar) { +void lstop (lua_State *L, lua_Debug *ar) { (void)ar; /* unused arg. */ lua_sethook(L, NULL, 0, 0); /* reset hook */ luaL_error(L, "interrupted!"); @@ -119,13 +124,13 @@ static void lstop (lua_State *L, lua_Debug *ar) { ** this function only sets a hook that, when called, will stop the ** interpreter. */ -static void laction (int i) { +void laction (int i) { signal(i, SIG_DFL); /* if another SIGINT happens, terminate process */ lua_sethook(globalL, lstop, LUA_MASKCALL | LUA_MASKRET | LUA_MASKCOUNT, 1); } -static void print_usage (const char *badoption) { +void print_usage (const char *badoption) { lua_writestringerror("%s: ", progname); if (badoption[1] == 'e' || badoption[1] == 'l') lua_writestringerror("'%s' needs argument\n", badoption); @@ -150,7 +155,7 @@ static void print_usage (const char *badoption) { ** Prints an error message, adding the program name in front of it ** (if present) */ -static void l_message (const char *pname, const char *msg) { +void l_message (const char *pname, const char *msg) { if (pname) lua_writestringerror("%s: ", pname); lua_writestringerror("%s\n", msg); } @@ -161,7 +166,7 @@ static void l_message (const char *pname, const char *msg) { ** message on the top of the stack. It assumes that the error object ** is a string, as it was either generated by Lua or by 'msghandler'. */ -static int report (lua_State *L, int status) { +int report (lua_State *L, int status) { if (status != LUA_OK) { const char *msg = lua_tostring(L, -1); l_message(progname, msg); @@ -174,7 +179,7 @@ static int report (lua_State *L, int status) { /* ** Message handler used to run all chunks */ -static int msghandler (lua_State *L) { +int msghandler (lua_State *L) { const char *msg = lua_tostring(L, 1); if (msg == NULL) { /* is error object not a string? */ if (luaL_callmeta(L, 1, "__tostring") && /* does it have a metamethod */ @@ -193,7 +198,7 @@ static int msghandler (lua_State *L) { ** Interface to 'lua_pcall', which sets appropriate message function ** and C-signal handler. Used to run all chunks. */ -static int docall (lua_State *L, int narg, int nres) { +int docall (lua_State *L, int narg, int nres) { int status; int base = lua_gettop(L) - narg; /* function index */ lua_pushcfunction(L, msghandler); /* push message handler */ @@ -207,7 +212,7 @@ static int docall (lua_State *L, int narg, int nres) { } -static void print_version (void) { +void print_version (void) { lua_writestring(LUA_COPYRIGHT, strlen(LUA_COPYRIGHT)); lua_writeline(); } @@ -221,7 +226,7 @@ static void print_version (void) { ** other arguments (before the script name) go to negative indices. ** If there is no script name, assume interpreter's name as base. */ -static void createargtable (lua_State *L, char **argv, int argc, int script) { +void createargtable (lua_State *L, char **argv, int argc, int script) { int i, narg; if (script == argc) script = 0; /* no script name? */ narg = argc - (script + 1); /* number of positive indices */ @@ -234,18 +239,18 @@ static void createargtable (lua_State *L, char **argv, int argc, int script) { } -static int dochunk (lua_State *L, int status) { +int dochunk (lua_State *L, int status) { if (status == LUA_OK) status = docall(L, 0, 0); return report(L, status); } -static int dofile (lua_State *L, const char *name) { +int dofile (lua_State *L, const char *name) { return dochunk(L, luaL_loadfile(L, name)); } -static int dostring (lua_State *L, const char *s, const char *name) { +int dostring (lua_State *L, const char *s, const char *name) { return dochunk(L, luaL_loadbuffer(L, s, strlen(s), name)); } @@ -254,7 +259,7 @@ static int dostring (lua_State *L, const char *s, const char *name) { ** Calls 'require(name)' and stores the result in a global variable ** with the given name. */ -static int dolibrary (lua_State *L, const char *name) { +int dolibrary (lua_State *L, const char *name) { int status; lua_getglobal(L, "require"); lua_pushstring(L, name); @@ -268,7 +273,7 @@ static int dolibrary (lua_State *L, const char *name) { /* ** Returns the string to be used as a prompt by the interpreter. */ -static const char *get_prompt (lua_State *L, int firstline) { +const char *get_prompt (lua_State *L, int firstline) { const char *p; lua_getglobal(L, firstline ? "_PROMPT" : "_PROMPT2"); p = lua_tostring(L, -1); @@ -286,7 +291,7 @@ static const char *get_prompt (lua_State *L, int firstline) { ** message at the top of the stack ends with the above mark for ** incomplete statements. */ -static int incomplete (lua_State *L, int status) { +int incomplete (lua_State *L, int status) { if (status == LUA_ERRSYNTAX) { size_t lmsg; const char *msg = lua_tolstring(L, -1, &lmsg); @@ -302,7 +307,7 @@ static int incomplete (lua_State *L, int status) { /* ** Prompt the user, read a line, and push it into the Lua stack. */ -static int pushline (lua_State *L, int firstline) { +int pushline (lua_State *L, int firstline) { char buffer[LUA_MAXINPUT]; char *b = buffer; size_t l; @@ -327,7 +332,7 @@ static int pushline (lua_State *L, int firstline) { ** Try to compile line on the stack as 'return <line>;'; on return, stack ** has either compiled chunk or original line (if compilation failed). */ -static int addreturn (lua_State *L) { +int addreturn (lua_State *L) { const char *line = lua_tostring(L, -1); /* original line */ const char *retline = lua_pushfstring(L, "return %s;", line); int status = luaL_loadbuffer(L, retline, strlen(retline), "=stdin"); @@ -345,7 +350,7 @@ static int addreturn (lua_State *L) { /* ** Read multiple lines until a complete Lua statement */ -static int multiline (lua_State *L) { +int multiline (lua_State *L) { for (;;) { /* repeat until gets a complete statement */ size_t len; const char *line = lua_tolstring(L, 1, &len); /* get what it has */ @@ -367,7 +372,7 @@ static int multiline (lua_State *L) { ** the final status of load/call with the resulting function (if any) ** in the top of the stack. */ -static int loadline (lua_State *L) { +int loadline (lua_State *L) { int status; lua_settop(L, 0); if (!pushline(L, 1)) @@ -383,7 +388,7 @@ static int loadline (lua_State *L) { /* ** Prints (calling the Lua 'print' function) any values on the stack */ -static void l_print (lua_State *L) { +void l_print (lua_State *L) { int n = lua_gettop(L); if (n > 0) { /* any result to be printed? */ luaL_checkstack(L, LUA_MINSTACK, "too many results to print"); @@ -400,7 +405,7 @@ static void l_print (lua_State *L) { ** Do the REPL: repeatedly read (load) a line, evaluate (call) it, and ** print any results. */ -static void doREPL (lua_State *L) { +void doREPL (lua_State *L) { int status; const char *oldprogname = progname; progname = NULL; /* no 'progname' on errors in interactive mode */ @@ -419,7 +424,7 @@ static void doREPL (lua_State *L) { /* ** Push on the stack the contents of table 'arg' from 1 to #arg */ -static int pushargs (lua_State *L) { +int pushargs (lua_State *L) { int i, n; if (lua_getglobal(L, "arg") != LUA_TTABLE) luaL_error(L, "'arg' is not a table"); @@ -432,7 +437,7 @@ static int pushargs (lua_State *L) { } -static int handle_script (lua_State *L, char **argv) { +int handle_script (lua_State *L, char **argv) { int status; const char *fname = argv[0]; if (strcmp(fname, "-") == 0 && strcmp(argv[-1], "--") != 0) @@ -460,7 +465,7 @@ static int handle_script (lua_State *L, char **argv) { ** any invalid argument). 'first' returns the first not-handled argument ** (either the script name or a bad argument in case of error). */ -static int collectargs (char **argv, int *first) { +int collectargs (char **argv, int *first) { int args = 0; int i; for (i = 1; argv[i] != NULL; i++) { @@ -509,7 +514,7 @@ static int collectargs (char **argv, int *first) { ** Processes options 'e' and 'l', which involve running Lua code. ** Returns 0 if some code raises an error. */ -static int runargs (lua_State *L, char **argv, int n) { +int runargs (lua_State *L, char **argv, int n) { int i; for (i = 1; i < n; i++) { int option = argv[i][1]; @@ -529,7 +534,7 @@ static int runargs (lua_State *L, char **argv, int n) { } -static int handle_luainit (lua_State *L) { +int handle_luainit (lua_State *L) { const char *name = "=" LUA_INITVARVERSION; const char *init = getenv(name + 1); if (init == NULL) { @@ -548,7 +553,7 @@ static int handle_luainit (lua_State *L) { ** Main body of stand-alone interpreter (to be called in protected mode). ** Reads the options and handles them all. */ -static int pmain (lua_State *L) { +int pmain (lua_State *L) { int argc = (int)lua_tointeger(L, 1); char **argv = (char **)lua_touserdata(L, 2); int script; |