MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / pushline

Function pushline

lib/lua/src/lua.c:505–523  ·  view source on GitHub ↗

** Prompt the user, read a line, and push it into the Lua stack. */

Source from the content-addressed store, hash-verified

503** Prompt the user, read a line, and push it into the Lua stack.
504*/
505static int pushline (lua_State *L, int firstline) {
506 char buffer[LUA_MAXINPUT];
507 char *b = buffer;
508 size_t l;
509 const char *prmt = get_prompt(L, firstline);
510 int readstatus = lua_readline(L, b, prmt);
511 if (readstatus == 0)
512 return 0; /* no input (prompt will be popped by caller) */
513 lua_pop(L, 1); /* remove prompt */
514 l = strlen(b);
515 if (l > 0 && b[l-1] == '\n') /* line ends with newline? */
516 b[--l] = '\0'; /* remove it */
517 if (firstline && b[0] == '=') /* for compatibility with 5.2, ... */
518 lua_pushfstring(L, "return %s", b + 1); /* change '=' to 'return' */
519 else
520 lua_pushlstring(L, b, l);
521 lua_freeline(L, b);
522 return 1;
523}
524
525
526/*

Callers 2

multilineFunction · 0.85
loadlineFunction · 0.85

Calls 3

get_promptFunction · 0.85
lua_pushfstringFunction · 0.85
lua_pushlstringFunction · 0.85

Tested by

no test coverage detected