aboutsummaryrefslogtreecommitdiff
path: root/lua.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2015-08-14 16:11:20 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2015-08-14 16:11:20 -0300
commited19fe766cf833e80236a6aaec63137744f60562 (patch)
treecc5084f14ac8287fac5abe66374c6a8b918b0865 /lua.c
parent8f25d08637749316fd30d96ad874f1400088abee (diff)
downloadlua-ed19fe766cf833e80236a6aaec63137744f60562.tar.gz
lua-ed19fe766cf833e80236a6aaec63137744f60562.tar.bz2
lua-ed19fe766cf833e80236a6aaec63137744f60562.zip
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)
Diffstat (limited to 'lua.c')
-rw-r--r--lua.c20
1 files changed, 8 insertions, 12 deletions
diff --git a/lua.c b/lua.c
index 00feb138..898c6869 100644
--- a/lua.c
+++ b/lua.c
@@ -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*/
330static int addreturn (lua_State *L) { 330static 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