Browse Source

added ';' at the end of "expression lines" ("return exp;") so that

an extra ";" at the end is enough to stop Lua printing the result
("return exp;;" is not valid)
pull/9/head
Roberto Ierusalimschy 9 years ago
parent
commit
ed19fe766c
  1. 20
      lua.c

20
lua.c

@ -1,5 +1,5 @@
/* /*
** $Id: lua.c,v 1.224 2015/03/10 14:15:06 roberto Exp roberto $ ** $Id: lua.c,v 1.225 2015/03/30 15:42:59 roberto Exp roberto $
** Lua stand-alone interpreter ** Lua stand-alone interpreter
** See Copyright Notice in lua.h ** 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). ** has either compiled chunk or original line (if compilation failed).
*/ */
static int addreturn (lua_State *L) { static int addreturn (lua_State *L) {
int status; const char *line = lua_tostring(L, -1); /* original line */
size_t len; const char *line; const char *retline = lua_pushfstring(L, "return %s;", line);
lua_pushliteral(L, "return "); int status = luaL_loadbuffer(L, retline, strlen(retline), "=stdin");
lua_pushvalue(L, -2); /* duplicate line */ if (status == LUA_OK) {
lua_concat(L, 2); /* new line is "return ..." */ lua_remove(L, -2); /* remove modified line */
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 */
if (line[0] != '\0') /* non empty? */ if (line[0] != '\0') /* non empty? */
lua_saveline(L, line); /* keep history */ lua_saveline(L, line); /* keep history */
} }
else 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; return status;
} }

Loading…
Cancel
Save