diff options
Diffstat (limited to 'lua.c')
-rw-r--r-- | lua.c | 20 |
1 files changed, 8 insertions, 12 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lua.c,v 1.224 2015/03/10 14:15:06 roberto Exp roberto $ | 2 | ** $Id: lua.c,v 1.225 2015/03/30 15:42:59 roberto Exp roberto $ |
3 | ** Lua stand-alone interpreter | 3 | ** Lua stand-alone interpreter |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -324,24 +324,20 @@ static int pushline (lua_State *L, int firstline) { | |||
324 | 324 | ||
325 | 325 | ||
326 | /* | 326 | /* |
327 | ** Try to compile line on the stack as 'return <line>'; on return, stack | 327 | ** Try to compile line on the stack as 'return <line>;'; on return, stack |
328 | ** has either compiled chunk or original line (if compilation failed). | 328 | ** has either compiled chunk or original line (if compilation failed). |
329 | */ | 329 | */ |
330 | static int addreturn (lua_State *L) { | 330 | static int addreturn (lua_State *L) { |
331 | int status; | 331 | const char *line = lua_tostring(L, -1); /* original line */ |
332 | size_t len; const char *line; | 332 | const char *retline = lua_pushfstring(L, "return %s;", line); |
333 | lua_pushliteral(L, "return "); | 333 | int status = luaL_loadbuffer(L, retline, strlen(retline), "=stdin"); |
334 | lua_pushvalue(L, -2); /* duplicate line */ | 334 | if (status == LUA_OK) { |
335 | lua_concat(L, 2); /* new line is "return ..." */ | 335 | lua_remove(L, -2); /* remove modified line */ |
336 | line = lua_tolstring(L, -1, &len); | ||
337 | if ((status = luaL_loadbuffer(L, line, len, "=stdin")) == LUA_OK) { | ||
338 | lua_remove(L, -3); /* remove original line */ | ||
339 | line += sizeof("return")/sizeof(char); /* remove 'return' for history */ | ||
340 | if (line[0] != '\0') /* non empty? */ | 336 | if (line[0] != '\0') /* non empty? */ |
341 | lua_saveline(L, line); /* keep history */ | 337 | lua_saveline(L, line); /* keep history */ |
342 | } | 338 | } |
343 | else | 339 | else |
344 | lua_pop(L, 2); /* remove result from 'luaL_loadbuffer' and new line */ | 340 | lua_pop(L, 2); /* pop result from 'luaL_loadbuffer' and modified line */ |
345 | return status; | 341 | return status; |
346 | } | 342 | } |
347 | 343 | ||