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