MCPcopy Create free account
hub / github.com/Achain-Dev/Achain / pushline

Function pushline

src/Chain/libraries/glua/lrepl.cpp:350–368  ·  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

348** Prompt the user, read a line, and push it into the Lua stack.
349*/
350static int pushline(lua_State *L, int firstline) {
351 char buffer[LUA_MAXINPUT];
352 char *b = buffer;
353 size_t l;
354 const char *prmt = get_prompt(L, firstline);
355 int readstatus = lua_readline(L, b, prmt);
356 if (readstatus == 0 || lua_gettop(L) < 1)
357 return 0; /* no input (prompt will be popped by caller) */
358 lua_pop(L, 1); /* remove prompt */
359 l = strlen(b);
360 if (l > 0 && b[l - 1] == '\n') /* line ends with newline? */
361 b[--l] = '\0'; /* remove it */
362 if (firstline && b[0] == '=') /* for compatibility with 5.2, ... */
363 lua_pushfstring(L, "return %s", b + 1); /* change '=' to 'return' */
364 else
365 lua_pushlstring(L, b, l);
366 lua_freeline(L, b);
367 return 1;
368}
369
370
371/*

Callers 2

multilineFunction · 0.70
loadlineFunction · 0.70

Calls 4

lua_gettopFunction · 0.85
lua_pushfstringFunction · 0.85
lua_pushlstringFunction · 0.85
get_promptFunction · 0.70

Tested by

no test coverage detected