summaryrefslogtreecommitdiff
path: root/src/lua.c
diff options
context:
space:
mode:
authorPeter Drahoš <drahosp@gmail.com>2015-12-16 00:14:02 +0100
committerPeter Drahoš <drahosp@gmail.com>2015-12-16 00:14:02 +0100
commitfcdc5efb13f0d6c03d2868b7476b73e63a291ed3 (patch)
tree5bd844d3ae48e03d1aac8ebef3dd6209549d246e /src/lua.c
parent94f9f6c6ed0fbc1b49ab4a896d6a587ce8815e36 (diff)
downloadlua-5.3.tar.gz
Updated to lua-5.3.25.3.2lua-5.3
Diffstat (limited to 'src/lua.c')
-rw-r--r--src/lua.c20
1 files changed, 8 insertions, 12 deletions
diff --git a/src/lua.c b/src/lua.c
index 7a47582..545d23d 100644
--- a/src/lua.c
+++ b/src/lua.c
@@ -1,5 +1,5 @@
/*
-** $Id: lua.c,v 1.225 2015/03/30 15:42:59 roberto Exp $
+** $Id: lua.c,v 1.226 2015/08/14 19:11:20 roberto Exp $
** Lua stand-alone interpreter
** See Copyright Notice in lua.h
*/
@@ -324,24 +324,20 @@ static int pushline (lua_State *L, int firstline) {
/*
-** Try to compile line on the stack as 'return <line>'; on return, stack
+** Try to compile line on the stack as 'return <line>;'; on return, stack
** has either compiled chunk or original line (if compilation failed).
*/
static int addreturn (lua_State *L) {
- int status;
- size_t len; const char *line;
- lua_pushliteral(L, "return ");
- lua_pushvalue(L, -2); /* duplicate line */
- lua_concat(L, 2); /* new line is "return ..." */
- line = lua_tolstring(L, -1, &len);
- if ((status = luaL_loadbuffer(L, line, len, "=stdin")) == LUA_OK) {
- lua_remove(L, -3); /* remove original line */
- line += sizeof("return")/sizeof(char); /* remove 'return' for history */
+ const char *line = lua_tostring(L, -1); /* original line */
+ const char *retline = lua_pushfstring(L, "return %s;", line);
+ int status = luaL_loadbuffer(L, retline, strlen(retline), "=stdin");
+ if (status == LUA_OK) {
+ lua_remove(L, -2); /* remove modified line */
if (line[0] != '\0') /* non empty? */
lua_saveline(L, line); /* keep history */
}
else
- lua_pop(L, 2); /* remove result from 'luaL_loadbuffer' and new line */
+ lua_pop(L, 2); /* pop result from 'luaL_loadbuffer' and modified line */
return status;
}