MCPcopy Create free account
hub / github.com/DFHack/dfhack / pushline

Function pushline

depends/lua/src/lua.c:307–325  ·  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

305** Prompt the user, read a line, and push it into the Lua stack.
306*/
307static int pushline (lua_State *L, int firstline) {
308 char buffer[LUA_MAXINPUT];
309 char *b = buffer;
310 size_t l;
311 const char *prmt = get_prompt(L, firstline);
312 int readstatus = lua_readline(L, b, prmt);
313 if (readstatus == 0)
314 return 0; /* no input (prompt will be popped by caller) */
315 lua_pop(L, 1); /* remove prompt */
316 l = strlen(b);
317 if (l > 0 && b[l-1] == '\n') /* line ends with newline? */
318 b[--l] = '\0'; /* remove it */
319 if (firstline && b[0] == '=') /* for compatibility with 5.2, ... */
320 lua_pushfstring(L, "return %s", b + 1); /* change '=' to 'return' */
321 else
322 lua_pushlstring(L, b, l);
323 lua_freeline(L, b);
324 return 1;
325}
326
327
328/*

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