--- lua-5.1.5/src/Makefile
+++ lua-5.1.6/src/Makefile
@@ -48,7 +48,7 @@
 a:	$(ALL_A)
 
 $(LUA_A): $(CORE_O) $(LIB_O)
-	$(AR) $@ $(CORE_O) $(LIB_O)	# DLL needs all object files
+	$(AR) $@ $(CORE_O) $(LIB_O)
 	$(RANLIB) $@
 
 $(LUA_T): $(LUA_O) $(LUA_A)
--- lua-5.1.5/src/lauxlib.c
+++ lua-5.1.6/src/lauxlib.c
@@ -574,7 +574,7 @@
     lf.f = freopen(filename, "rb", lf.f);  /* reopen in binary mode */
     if (lf.f == NULL) return errfile(L, "reopen", fnameindex);
     /* skip eventual `#!...' */
-   while ((c = getc(lf.f)) != EOF && c != LUA_SIGNATURE[0]) ;
+    while ((c = getc(lf.f)) != EOF && c != LUA_SIGNATURE[0]) ;
     lf.extraline = 0;
   }
   ungetc(c, lf.f);
--- lua-5.1.5/src/ldo.c
+++ lua-5.1.6/src/ldo.c
@@ -274,7 +274,7 @@
     CallInfo *ci;
     StkId st, base;
     Proto *p = cl->p;
-    luaD_checkstack(L, p->maxstacksize);
+    luaD_checkstack(L, p->maxstacksize + p->numparams);
     func = restorestack(L, funcr);
     if (!p->is_vararg) {  /* no varargs? */
       base = func + 1;
--- lua-5.1.5/src/loslib.c
+++ lua-5.1.6/src/loslib.c
@@ -214,7 +214,15 @@
 
 
 static int os_exit (lua_State *L) {
-  exit(luaL_optint(L, 1, EXIT_SUCCESS));
+  int status;
+  if (lua_isboolean(L, 1))
+    status = (lua_toboolean(L, 1) ? EXIT_SUCCESS : EXIT_FAILURE);
+  else
+    status = luaL_optint(L, 1, EXIT_SUCCESS);
+  if (lua_toboolean(L, 2))
+    lua_close(L);
+  if (L) exit(status);  /* 'if' to avoid warnings for unreachable 'return' */
+  return 0;
 }
 
 static const luaL_Reg syslib[] = {
--- lua-5.1.5/src/ltablib.c
+++ lua-5.1.6/src/ltablib.c
@@ -137,7 +137,7 @@
   if (!lua_isstring(L, -1))
     luaL_error(L, "invalid value (%s) at index %d in table for "
                   LUA_QL("concat"), luaL_typename(L, -1), i);
-    luaL_addvalue(b);
+  luaL_addvalue(b);
 }
 
 
--- lua-5.1.5/src/lua.c
+++ lua-5.1.6/src/lua.c
@@ -193,22 +193,46 @@
 }
 
 
+static int addreturn (lua_State *L) {
+  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 == 0) {
+    lua_remove(L, -2);  /* remove modified line */
+    if (line[0] != '\0')  /* non empty? */
+      lua_saveline(L, 1);  /* keep history */
+  }
+  else
+    lua_pop(L, 2);  /* pop result from 'luaL_loadbuffer' and modified line */
+  return status;
+}
+
+
+static int multiline (lua_State *L) {
+  for (;;) {  /* repeat until gets a complete statement */
+    size_t len;
+    const char *line = lua_tolstring(L, 1, &len);  /* get what it has */
+    int status = luaL_loadbuffer(L, line, len, "=stdin");  /* try it */
+    if (!incomplete(L, status) || !pushline(L, 0)) {
+      lua_saveline(L, 1);  /* keep history */
+      return status;  /* cannot or should not try to add continuation line */
+    }
+    lua_pushliteral(L, "\n");  /* add newline... */
+    lua_insert(L, -2);  /* ...between the two lines */
+    lua_concat(L, 3);  /* join them */
+  }
+}
+
+
 static int loadline (lua_State *L) {
   int status;
   lua_settop(L, 0);
   if (!pushline(L, 1))
     return -1;  /* no input */
-  for (;;) {  /* repeat until gets a complete line */
-    status = luaL_loadbuffer(L, lua_tostring(L, 1), lua_strlen(L, 1), "=stdin");
-    if (!incomplete(L, status)) break;  /* cannot try to add lines? */
-    if (!pushline(L, 0))  /* no more input? */
-      return -1;
-    lua_pushliteral(L, "\n");  /* add a new line... */
-    lua_insert(L, -2);  /* ...between the two lines */
-    lua_concat(L, 3);  /* join them */
-  }
-  lua_saveline(L, 1);
-  lua_remove(L, 1);  /* remove line */
+  if ((status = addreturn(L)) != 0)  /* 'return ...' did not work? */
+    status = multiline(L);  /* try as command, maybe with continuation lines */
+  lua_remove(L, 1);  /* remove line from the stack */
+  lua_assert(lua_gettop(L) == 1);
   return status;
 }
 
--- lua-5.1.5/src/lua.h
+++ lua-5.1.6/src/lua.h
@@ -17,7 +17,7 @@
 
 
 #define LUA_VERSION	"Lua 5.1"
-#define LUA_RELEASE	"Lua 5.1.5"
+#define LUA_RELEASE	"Lua 5.1.6"
 #define LUA_VERSION_NUM	501
 #define LUA_COPYRIGHT	"Copyright (C) 1994-2012 Lua.org, PUC-Rio"
 #define LUA_AUTHORS 	"R. Ierusalimschy, L. H. de Figueiredo & W. Celes"
--- lua-5.1.5/src/luaconf.h
+++ lua-5.1.6/src/luaconf.h
@@ -95,13 +95,17 @@
 
 #else
 #define LUA_ROOT	"/usr/local/"
+#define LUA_ROOT2	"/usr/"
 #define LUA_LDIR	LUA_ROOT "share/lua/5.1/"
+#define LUA_LDIR2	LUA_ROOT2 "share/lua/5.1/"
 #define LUA_CDIR	LUA_ROOT "lib/lua/5.1/"
+#define LUA_CDIR2	LUA_ROOT2 "lib/lua/5.1/"
 #define LUA_PATH_DEFAULT  \
 		"./?.lua;"  LUA_LDIR"?.lua;"  LUA_LDIR"?/init.lua;" \
-		            LUA_CDIR"?.lua;"  LUA_CDIR"?/init.lua"
+		            LUA_CDIR"?.lua;"  LUA_CDIR"?/init.lua;" \
+		            LUA_LDIR2"?.lua;" LUA_LDIR2"?/init.lua"
 #define LUA_CPATH_DEFAULT \
-	"./?.so;"  LUA_CDIR"?.so;" LUA_CDIR"loadall.so"
+	"./?.so;"  LUA_CDIR"?.so;" LUA_CDIR2"?.so;" LUA_CDIR"loadall.so"
 #endif
 
 
@@ -161,7 +165,11 @@
 
 #else
 
+#ifdef __cplusplus
+#define LUA_API		extern "C"
+#else
 #define LUA_API		extern
+#endif
 
 #endif
 
--- lua-5.1.5/src/lzio.c
+++ lua-5.1.6/src/lzio.c
@@ -22,10 +22,14 @@
   size_t size;
   lua_State *L = z->L;
   const char *buff;
+  if (z->eoz) return EOZ;
   lua_unlock(L);
   buff = z->reader(L, z->data, &size);
   lua_lock(L);
-  if (buff == NULL || size == 0) return EOZ;
+  if (buff == NULL || size == 0) {
+    z->eoz = 1;  /* avoid calling reader function next time */
+    return EOZ;
+  }
   z->n = size - 1;
   z->p = buff;
   return char2int(*(z->p++));
@@ -51,6 +55,7 @@
   z->data = data;
   z->n = 0;
   z->p = NULL;
+  z->eoz = 0;
 }
 
 
--- lua-5.1.5/src/lzio.h
+++ lua-5.1.6/src/lzio.h
@@ -59,6 +59,7 @@
   lua_Reader reader;
   void* data;			/* additional data */
   lua_State *L;			/* Lua state (for reader) */
+  int eoz;			/* true if reader has no more data */
 };
 
 
