** Try to compile line on the stack as 'return ;'; on return, stack ** has either compiled chunk or original line (if compilation failed). */
| 373 | ** has either compiled chunk or original line (if compilation failed). |
| 374 | */ |
| 375 | static int addreturn(lua_State *L) { |
| 376 | const char *line = lua_tostring(L, -1); /* original line */ |
| 377 | const char *retline = lua_pushfstring(L, "return %s;", line); |
| 378 | int status = luaL_loadbuffer(L, retline, strlen(retline), "=stdin"); |
| 379 | if (status == LUA_OK) { |
| 380 | lua_remove(L, -2); /* remove modified line */ |
| 381 | if (line[0] != '\0') /* non empty? */ |
| 382 | lua_saveline(L, line); /* keep history */ |
| 383 | } |
| 384 | else |
| 385 | lua_pop(L, 2); /* pop result from 'luaL_loadbuffer' and modified line */ |
| 386 | return status; |
| 387 | } |
| 388 | |
| 389 | |
| 390 | /* |
no test coverage detected