** Try to compile line on the stack as 'return ;'; on return, stack ** has either compiled chunk or original line (if compilation failed). */
| 526 | ** has either compiled chunk or original line (if compilation failed). |
| 527 | */ |
| 528 | static int addreturn (lua_State *L) { |
| 529 | const char *line = lua_tostring(L, -1); /* original line */ |
| 530 | const char *retline = lua_pushfstring(L, "return %s;", line); |
| 531 | int status = luaL_loadbuffer(L, retline, strlen(retline), "=stdin"); |
| 532 | if (status == LUA_OK) { |
| 533 | lua_remove(L, -2); /* remove modified line */ |
| 534 | if (line[0] != '\0') /* non empty? */ |
| 535 | lua_saveline(L, line); /* keep history */ |
| 536 | } |
| 537 | else |
| 538 | lua_pop(L, 2); /* pop result from 'luaL_loadbuffer' and modified line */ |
| 539 | return status; |
| 540 | } |
| 541 | |
| 542 | |
| 543 | /* |
no test coverage detected