• Home
  • Raw
  • Download

Lines Matching refs:L

84 #define lua_readline(L,b,p)	((void)L, ((b)=readline(p)) != NULL)  argument
85 #define lua_saveline(L,line) ((void)L, add_history(line)) argument
86 #define lua_freeline(L,b) ((void)L, free(b)) argument
90 #define lua_readline(L,b,p) \ argument
91 ((void)L, fputs(p, stdout), fflush(stdout), /* show prompt */ \
93 #define lua_saveline(L,line) { (void)L; (void)line; } argument
94 #define lua_freeline(L,b) { (void)L; (void)b; } argument
111 static void lstop (lua_State *L, lua_Debug *ar) { in lstop() argument
113 lua_sethook(L, NULL, 0, 0); /* reset hook */ in lstop()
114 luaL_error(L, "interrupted!"); in lstop()
166 static int report (lua_State *L, int status) { in report() argument
168 const char *msg = lua_tostring(L, -1); in report()
170 lua_pop(L, 1); /* remove message */ in report()
179 static int msghandler (lua_State *L) { in msghandler() argument
180 const char *msg = lua_tostring(L, 1); in msghandler()
182 if (luaL_callmeta(L, 1, "__tostring") && /* does it have a metamethod */ in msghandler()
183 lua_type(L, -1) == LUA_TSTRING) /* that produces a string? */ in msghandler()
186 msg = lua_pushfstring(L, "(error object is a %s value)", in msghandler()
187 luaL_typename(L, 1)); in msghandler()
189 luaL_traceback(L, L, msg, 1); /* append a standard traceback */ in msghandler()
198 static int docall (lua_State *L, int narg, int nres) { in docall() argument
200 int base = lua_gettop(L) - narg; /* function index */ in docall()
201 lua_pushcfunction(L, msghandler); /* push message handler */ in docall()
202 lua_insert(L, base); /* put it under function and args */ in docall()
203 globalL = L; /* to be available to 'laction' */ in docall()
205 status = lua_pcall(L, narg, nres, base); in docall()
207 lua_remove(L, base); /* remove message handler from the stack */ in docall()
226 static void createargtable (lua_State *L, char **argv, int argc, int script) { in createargtable() argument
230 lua_createtable(L, narg, script + 1); in createargtable()
232 lua_pushstring(L, argv[i]); in createargtable()
233 lua_rawseti(L, -2, i - script); in createargtable()
235 lua_setglobal(L, "arg"); in createargtable()
239 static int dochunk (lua_State *L, int status) { in dochunk() argument
240 if (status == LUA_OK) status = docall(L, 0, 0); in dochunk()
241 return report(L, status); in dochunk()
245 static int dofile (lua_State *L, const char *name) { in dofile() argument
246 return dochunk(L, luaL_loadfile(L, name)); in dofile()
250 static int dostring (lua_State *L, const char *s, const char *name) { in dostring() argument
251 return dochunk(L, luaL_loadbuffer(L, s, strlen(s), name)); in dostring()
259 static int dolibrary (lua_State *L, const char *name) { in dolibrary() argument
261 lua_getglobal(L, "require"); in dolibrary()
262 lua_pushstring(L, name); in dolibrary()
263 status = docall(L, 1, 1); /* call 'require(name)' */ in dolibrary()
265 lua_setglobal(L, name); /* global[name] = require return */ in dolibrary()
266 return report(L, status); in dolibrary()
273 static const char *get_prompt (lua_State *L, int firstline) { in get_prompt() argument
275 lua_getglobal(L, firstline ? "_PROMPT" : "_PROMPT2"); in get_prompt()
276 p = lua_tostring(L, -1); in get_prompt()
291 static int incomplete (lua_State *L, int status) { in incomplete() argument
294 const char *msg = lua_tolstring(L, -1, &lmsg); in incomplete()
296 lua_pop(L, 1); in incomplete()
307 static int pushline (lua_State *L, int firstline) { in pushline() argument
311 const char *prmt = get_prompt(L, firstline); in pushline()
312 int readstatus = lua_readline(L, b, prmt); in pushline()
315 lua_pop(L, 1); /* remove prompt */ in pushline()
320 lua_pushfstring(L, "return %s", b + 1); /* change '=' to 'return' */ in pushline()
322 lua_pushlstring(L, b, l); in pushline()
323 lua_freeline(L, b); in pushline()
332 static int addreturn (lua_State *L) { in addreturn() argument
333 const char *line = lua_tostring(L, -1); /* original line */ in addreturn()
334 const char *retline = lua_pushfstring(L, "return %s;", line); in addreturn()
335 int status = luaL_loadbuffer(L, retline, strlen(retline), "=stdin"); in addreturn()
337 lua_remove(L, -2); /* remove modified line */ in addreturn()
339 lua_saveline(L, line); /* keep history */ in addreturn()
342 lua_pop(L, 2); /* pop result from 'luaL_loadbuffer' and modified line */ in addreturn()
350 static int multiline (lua_State *L) { in multiline() argument
353 const char *line = lua_tolstring(L, 1, &len); /* get what it has */ in multiline()
354 int status = luaL_loadbuffer(L, line, len, "=stdin"); /* try it */ in multiline()
355 if (!incomplete(L, status) || !pushline(L, 0)) { in multiline()
356 lua_saveline(L, line); /* keep history */ in multiline()
359 lua_pushliteral(L, "\n"); /* add newline... */ in multiline()
360 lua_insert(L, -2); /* ...between the two lines */ in multiline()
361 lua_concat(L, 3); /* join them */ in multiline()
372 static int loadline (lua_State *L) { in loadline() argument
374 lua_settop(L, 0); in loadline()
375 if (!pushline(L, 1)) in loadline()
377 if ((status = addreturn(L)) != LUA_OK) /* 'return ...' did not work? */ in loadline()
378 status = multiline(L); /* try as command, maybe with continuation lines */ in loadline()
379 lua_remove(L, 1); /* remove line from the stack */ in loadline()
380 lua_assert(lua_gettop(L) == 1); in loadline()
388 static void l_print (lua_State *L) { in l_print() argument
389 int n = lua_gettop(L); in l_print()
391 luaL_checkstack(L, LUA_MINSTACK, "too many results to print"); in l_print()
392 lua_getglobal(L, "print"); in l_print()
393 lua_insert(L, 1); in l_print()
394 if (lua_pcall(L, n, 0, 0) != LUA_OK) in l_print()
395 l_message(progname, lua_pushfstring(L, "error calling 'print' (%s)", in l_print()
396 lua_tostring(L, -1))); in l_print()
405 static void doREPL (lua_State *L) { in doREPL() argument
409 while ((status = loadline(L)) != -1) { in doREPL()
411 status = docall(L, 0, LUA_MULTRET); in doREPL()
412 if (status == LUA_OK) l_print(L); in doREPL()
413 else report(L, status); in doREPL()
415 lua_settop(L, 0); /* clear stack */ in doREPL()
424 static int pushargs (lua_State *L) { in pushargs() argument
426 if (lua_getglobal(L, "arg") != LUA_TTABLE) in pushargs()
427 luaL_error(L, "'arg' is not a table"); in pushargs()
428 n = (int)luaL_len(L, -1); in pushargs()
429 luaL_checkstack(L, n + 3, "too many arguments to script"); in pushargs()
431 lua_rawgeti(L, -i, i); in pushargs()
432 lua_remove(L, -i); /* remove table from the stack */ in pushargs()
437 static int handle_script (lua_State *L, char **argv) { in handle_script() argument
442 status = luaL_loadfile(L, fname); in handle_script()
444 int n = pushargs(L); /* push arguments to script */ in handle_script()
445 status = docall(L, n, LUA_MULTRET); in handle_script()
447 return report(L, status); in handle_script()
514 static int runargs (lua_State *L, char **argv, int n) { in runargs() argument
525 ? dostring(L, extra, "=(command line)") in runargs()
526 : dolibrary(L, extra); in runargs()
535 static int handle_luainit (lua_State *L) { in handle_luainit() argument
544 return dofile(L, init+1); in handle_luainit()
546 return dostring(L, init, name); in handle_luainit()
554 static int pmain (lua_State *L) { in pmain() argument
555 int argc = (int)lua_tointeger(L, 1); in pmain()
556 char **argv = (char **)lua_touserdata(L, 2); in pmain()
559 luaL_checkversion(L); /* check that interpreter has correct version */ in pmain()
568 lua_pushboolean(L, 1); /* signal for libraries to ignore env. vars. */ in pmain()
569 lua_setfield(L, LUA_REGISTRYINDEX, "LUA_NOENV"); in pmain()
571 luaL_openlibs(L); /* open standard libraries */ in pmain()
572 createargtable(L, argv, argc, script); /* create table 'arg' */ in pmain()
574 if (handle_luainit(L) != LUA_OK) /* run LUA_INIT */ in pmain()
577 if (!runargs(L, argv, script)) /* execute arguments -e and -l */ in pmain()
580 handle_script(L, argv + script) != LUA_OK) in pmain()
583 doREPL(L); /* do read-eval-print loop */ in pmain()
587 doREPL(L); /* do read-eval-print loop */ in pmain()
589 else dofile(L, NULL); /* executes stdin as a file */ in pmain()
591 lua_pushboolean(L, 1); /* signal no errors */ in pmain()
598 lua_State *L = luaL_newstate(); /* create state */ in main() local
599 if (L == NULL) { in main()
603 lua_pushcfunction(L, &pmain); /* to call 'pmain' in protected mode */ in main()
604 lua_pushinteger(L, argc); /* 1st argument */ in main()
605 lua_pushlightuserdata(L, argv); /* 2nd argument */ in main()
606 status = lua_pcall(L, 2, 1, 0); /* do the call */ in main()
607 result = lua_toboolean(L, -1); /* get result */ in main()
608 report(L, status); in main()
609 lua_close(L); in main()