MCPcopy Create free account
hub / github.com/SakuraEngine/SakuraEngine / addreturn

Function addreturn

xrepo/packages/l/lua/port/lua/src/lua.c:511–523  ·  view source on GitHub ↗

** Try to compile line on the stack as 'return ;'; on return, stack ** has either compiled chunk or original line (if compilation failed). */

Source from the content-addressed store, hash-verified

509** has either compiled chunk or original line (if compilation failed).
510*/
511static int addreturn (lua_State *L) {
512 const char *line = lua_tostring(L, -1); /* original line */
513 const char *retline = lua_pushfstring(L, "return %s;", line);
514 int status = luaL_loadbuffer(L, retline, strlen(retline), "=stdin");
515 if (status == LUA_OK) {
516 lua_remove(L, -2); /* remove modified line */
517 if (line[0] != '\0') /* non empty? */
518 lua_saveline(L, line); /* keep history */
519 }
520 else
521 lua_pop(L, 2); /* pop result from 'luaL_loadbuffer' and modified line */
522 return status;
523}
524
525
526/*

Callers 1

loadlineFunction · 0.85

Calls 2

lua_pushfstringFunction · 0.85
lua_removeFunction · 0.85

Tested by

no test coverage detected