** Try to compile line on the stack as 'return ;'; on return, stack ** has either compiled chunk or original line (if compilation failed). */
| 477 | ** has either compiled chunk or original line (if compilation failed). |
| 478 | */ |
| 479 | static int addreturn (lua_State *L) { |
| 480 | const char *line = lua_tostring(L, -1); /* original line */ |
| 481 | const char *retline = lua_pushfstring(L, "return %s;", line); |
| 482 | int status = luaL_loadbuffer(L, retline, strlen(retline), "=stdin"); |
| 483 | if (status == LUA_OK) { |
| 484 | lua_remove(L, -2); /* remove modified line */ |
| 485 | if (line[0] != '\0') /* non empty? */ |
| 486 | lua_saveline(L, line); /* keep history */ |
| 487 | } |
| 488 | else |
| 489 | lua_pop(L, 2); /* pop result from 'luaL_loadbuffer' and modified line */ |
| 490 | return status; |
| 491 | } |
| 492 | |
| 493 | |
| 494 | /* |
no test coverage detected