diff -crB lua-5.1.4_2/Makefile lua-5.1.4/Makefile
*** lua-5.1.4_2/Makefile	2008-08-12 02:40:48.000000000 +0200
--- lua-5.1.4/Makefile	2010-11-19 14:10:08.000000000 +0100
***************
*** 43,49 ****
  # What to install.
  TO_BIN= lua luac
  TO_INC= lua.h luaconf.h lualib.h lauxlib.h ../etc/lua.hpp
! TO_LIB= liblua.a
  TO_MAN= lua.1 luac.1
  
  # Lua version and release.
--- 43,49 ----
  # What to install.
  TO_BIN= lua luac
  TO_INC= lua.h luaconf.h lualib.h lauxlib.h ../etc/lua.hpp
! TO_LIB= liblua.$(R).dylib
  TO_MAN= lua.1 luac.1
  
  # Lua version and release.
***************
*** 64,69 ****
--- 64,70 ----
  	cd src && $(INSTALL_DATA) $(TO_INC) $(INSTALL_INC)
  	cd src && $(INSTALL_DATA) $(TO_LIB) $(INSTALL_LIB)
  	cd doc && $(INSTALL_DATA) $(TO_MAN) $(INSTALL_MAN)
+ 	sudo ln -s $(INSTALL_LIB)/$(TO_LIB) $(INSTALL_LIB)/liblua.dylib
  
  ranlib:
  	cd src && cd $(INSTALL_LIB) && $(RANLIB) $(TO_LIB)
diff -crB lua-5.1.4_2/src/Makefile lua-5.1.4/src/Makefile
*** lua-5.1.4_2/src/Makefile	2008-01-19 20:37:58.000000000 +0100
--- lua-5.1.4/src/Makefile	2010-11-19 14:10:29.000000000 +0100
***************
*** 14,28 ****
  RM= rm -f
  LIBS= -lm $(MYLIBS)
  
! MYCFLAGS=
! MYLDFLAGS=
  MYLIBS=
  
  # == END OF USER SETTINGS. NO NEED TO CHANGE ANYTHING BELOW THIS LINE =========
  
  PLATS= aix ansi bsd freebsd generic linux macosx mingw posix solaris
  
! LUA_A=	liblua.a
  CORE_O=	lapi.o lcode.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o lmem.o \
  	lobject.o lopcodes.o lparser.o lstate.o lstring.o ltable.o ltm.o  \
  	lundump.o lvm.o lzio.o
--- 14,31 ----
  RM= rm -f
  LIBS= -lm $(MYLIBS)
  
! MYCFLAGS="-fno-common -arch i386"
! MYLDFLAGS="-fno-common -arch i386"
  MYLIBS=
+ ac_add_options --with-macos-sdk=/Developer/SDKs/MacOSX10.5.sdk
+ 
+ R= 5.1.4
  
  # == END OF USER SETTINGS. NO NEED TO CHANGE ANYTHING BELOW THIS LINE =========
  
  PLATS= aix ansi bsd freebsd generic linux macosx mingw posix solaris
  
! LUA_A=	liblua.$(R).dylib
  CORE_O=	lapi.o lcode.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o lmem.o \
  	lobject.o lopcodes.o lparser.o lstate.o lstring.o ltable.o ltm.o  \
  	lundump.o lvm.o lzio.o
***************
*** 48,55 ****
  a:	$(ALL_A)
  
  $(LUA_A): $(CORE_O) $(LIB_O)
! 	$(AR) $@ $?
! 	$(RANLIB) $@
  
  $(LUA_T): $(LUA_O) $(LUA_A)
  	$(CC) -o $@ $(MYLDFLAGS) $(LUA_O) $(LUA_A) $(LIBS)
--- 51,59 ----
  a:	$(ALL_A)
  
  $(LUA_A): $(CORE_O) $(LIB_O)
! 	$(CC) -dynamiclib -arch i386 -install_name /usr/local/lib/liblua.dylib \
! 		-compatibility_version 5.1 -current_version $(R) \
! 		-o liblua.$(R).dylib $^
  
  $(LUA_T): $(LUA_O) $(LUA_A)
  	$(CC) -o $@ $(MYLDFLAGS) $(LUA_O) $(LUA_A) $(LIBS)
***************
*** 99,105 ****
  	$(MAKE) all MYCFLAGS=-DLUA_USE_LINUX MYLIBS="-Wl,-E -ldl -lreadline -lhistory -lncurses"
  
  macosx:
! 	$(MAKE) all MYCFLAGS=-DLUA_USE_LINUX MYLIBS="-lreadline"
  # use this on Mac OS X 10.3-
  #	$(MAKE) all MYCFLAGS=-DLUA_USE_MACOSX
  
--- 103,109 ----
  	$(MAKE) all MYCFLAGS=-DLUA_USE_LINUX MYLIBS="-Wl,-E -ldl -lreadline -lhistory -lncurses"
  
  macosx:
! 	$(MAKE) all MYCFLAGS="-fno-common -arch i386 -DLUA_USE_LINUX" MYLIBS="-arch i386 -lreadline"
  # use this on Mac OS X 10.3-
  #	$(MAKE) all MYCFLAGS=-DLUA_USE_MACOSX
  
diff -crB lua-5.1.4_2/src/lcode.c lua-5.1.4/src/lcode.c
*** lua-5.1.4_2/src/lcode.c	2007-12-28 16:32:23.000000000 +0100
--- lua-5.1.4/src/lcode.c	2010-11-19 14:10:08.000000000 +0100
***************
*** 1,5 ****
  /*
! ** $Id: lcode.c,v 2.25.1.3 2007/12/28 15:32:23 roberto Exp $
  ** Code generator for Lua
  ** See Copyright Notice in lua.h
  */
--- 1,5 ----
  /*
! ** $Id: lcode.c,v 2.25.1.4 2009/06/15 14:12:25 roberto Exp $
  ** Code generator for Lua
  ** See Copyright Notice in lua.h
  */
***************
*** 544,558 ****
        pc = NO_JUMP;  /* always true; do nothing */
        break;
      }
-     case VFALSE: {
-       pc = luaK_jump(fs);  /* always jump */
-       break;
-     }
      case VJMP: {
        invertjump(fs, e);
        pc = e->u.s.info;
        break;
      }
      default: {
        pc = jumponcond(fs, e, 0);
        break;
--- 544,561 ----
        pc = NO_JUMP;  /* always true; do nothing */
        break;
      }
      case VJMP: {
        invertjump(fs, e);
        pc = e->u.s.info;
        break;
      }
+     case VFALSE: {
+       if (!hasjumps(e)) {
+         pc = luaK_jump(fs);  /* always jump */
+         break;
+       }
+       /* else go through */
+     }
      default: {
        pc = jumponcond(fs, e, 0);
        break;
***************
*** 572,585 ****
        pc = NO_JUMP;  /* always false; do nothing */
        break;
      }
-     case VTRUE: {
-       pc = luaK_jump(fs);  /* always jump */
-       break;
-     }
      case VJMP: {
        pc = e->u.s.info;
        break;
      }
      default: {
        pc = jumponcond(fs, e, 1);
        break;
--- 575,591 ----
        pc = NO_JUMP;  /* always false; do nothing */
        break;
      }
      case VJMP: {
        pc = e->u.s.info;
        break;
      }
+     case VTRUE: {
+       if (!hasjumps(e)) {
+         pc = luaK_jump(fs);  /* always jump */
+         break;
+       }
+       /* else go through */
+     }
      default: {
        pc = jumponcond(fs, e, 1);
        break;
diff -crB lua-5.1.4_2/src/ldblib.c lua-5.1.4/src/ldblib.c
*** lua-5.1.4_2/src/ldblib.c	2008-01-21 14:11:21.000000000 +0100
--- lua-5.1.4/src/ldblib.c	2010-11-19 14:10:08.000000000 +0100
***************
*** 1,5 ****
  /*
! ** $Id: ldblib.c,v 1.104.1.3 2008/01/21 13:11:21 roberto Exp $
  ** Interface from Lua to its debug API
  ** See Copyright Notice in lua.h
  */
--- 1,5 ----
  /*
! ** $Id: ldblib.c,v 1.104.1.4 2009/08/04 18:50:18 roberto Exp $
  ** Interface from Lua to its debug API
  ** See Copyright Notice in lua.h
  */
***************
*** 45,50 ****
--- 45,51 ----
  
  
  static int db_getfenv (lua_State *L) {
+   luaL_checkany(L, 1);
    lua_getfenv(L, 1);
    return 1;
  }
diff -crB lua-5.1.4_2/src/liolib.c lua-5.1.4/src/liolib.c
*** lua-5.1.4_2/src/liolib.c	2008-01-18 18:47:43.000000000 +0100
--- lua-5.1.4/src/liolib.c	2010-11-19 14:10:08.000000000 +0100
***************
*** 1,5 ****
  /*
! ** $Id: liolib.c,v 2.73.1.3 2008/01/18 17:47:43 roberto Exp $
  ** Standard I/O (and system) library
  ** See Copyright Notice in lua.h
  */
--- 1,5 ----
  /*
! ** $Id: liolib.c,v 2.73.1.4 2010/05/14 15:33:51 roberto Exp $
  ** Standard I/O (and system) library
  ** See Copyright Notice in lua.h
  */
***************
*** 276,282 ****
      lua_pushnumber(L, d);
      return 1;
    }
!   else return 0;  /* read fails */
  }
  
  
--- 276,285 ----
      lua_pushnumber(L, d);
      return 1;
    }
!   else {
!     lua_pushnil(L);  /* "result" to be removed */
!     return 0;  /* read fails */
!   }
  }
  
  
diff -crB lua-5.1.4_2/src/llex.c lua-5.1.4/src/llex.c
*** lua-5.1.4_2/src/llex.c	2007-12-27 14:02:25.000000000 +0100
--- lua-5.1.4/src/llex.c	2010-11-19 14:10:08.000000000 +0100
***************
*** 1,5 ****
  /*
! ** $Id: llex.c,v 2.20.1.1 2007/12/27 13:02:25 roberto Exp $
  ** Lexical Analyzer
  ** See Copyright Notice in lua.h
  */
--- 1,5 ----
  /*
! ** $Id: llex.c,v 2.20.1.2 2009/11/23 14:58:22 roberto Exp $
  ** Lexical Analyzer
  ** See Copyright Notice in lua.h
  */
***************
*** 118,125 ****
    lua_State *L = ls->L;
    TString *ts = luaS_newlstr(L, str, l);
    TValue *o = luaH_setstr(L, ls->fs->h, ts);  /* entry for `str' */
!   if (ttisnil(o))
      setbvalue(o, 1);  /* make sure `str' will not be collected */
    return ts;
  }
  
--- 118,127 ----
    lua_State *L = ls->L;
    TString *ts = luaS_newlstr(L, str, l);
    TValue *o = luaH_setstr(L, ls->fs->h, ts);  /* entry for `str' */
!   if (ttisnil(o)) {
      setbvalue(o, 1);  /* make sure `str' will not be collected */
+     luaC_checkGC(L);
+   }
    return ts;
  }
  
diff -crB lua-5.1.4_2/src/loadlib.c lua-5.1.4/src/loadlib.c
*** lua-5.1.4_2/src/loadlib.c	2008-08-06 15:29:28.000000000 +0200
--- lua-5.1.4/src/loadlib.c	2010-11-19 14:10:08.000000000 +0100
***************
*** 1,5 ****
  /*
! ** $Id: loadlib.c,v 1.52.1.3 2008/08/06 13:29:28 roberto Exp $
  ** Dynamic library loader for Lua
  ** See Copyright Notice in lua.h
  **
--- 1,5 ----
  /*
! ** $Id: loadlib.c,v 1.52.1.4 2009/09/09 13:17:16 roberto Exp $
  ** Dynamic library loader for Lua
  ** See Copyright Notice in lua.h
  **
***************
*** 639,645 ****
    lua_pushvalue(L, -1);
    lua_replace(L, LUA_ENVIRONINDEX);
    /* create `loaders' table */
!   lua_createtable(L, 0, sizeof(loaders)/sizeof(loaders[0]) - 1);
    /* fill it with pre-defined loaders */
    for (i=0; loaders[i] != NULL; i++) {
      lua_pushcfunction(L, loaders[i]);
--- 639,645 ----
    lua_pushvalue(L, -1);
    lua_replace(L, LUA_ENVIRONINDEX);
    /* create `loaders' table */
!   lua_createtable(L, sizeof(loaders)/sizeof(loaders[0]) - 1, 0);
    /* fill it with pre-defined loaders */
    for (i=0; loaders[i] != NULL; i++) {
      lua_pushcfunction(L, loaders[i]);
diff -crB lua-5.1.4_2/src/lstrlib.c lua-5.1.4/src/lstrlib.c
*** lua-5.1.4_2/src/lstrlib.c	2008-07-11 19:27:21.000000000 +0200
--- lua-5.1.4/src/lstrlib.c	2010-11-19 14:10:08.000000000 +0100
***************
*** 1,5 ****
  /*
! ** $Id: lstrlib.c,v 1.132.1.4 2008/07/11 17:27:21 roberto Exp $
  ** Standard library for string operations and pattern-matching
  ** See Copyright Notice in lua.h
  */
--- 1,5 ----
  /*
! ** $Id: lstrlib.c,v 1.132.1.5 2010/05/14 15:34:19 roberto Exp $
  ** Standard library for string operations and pattern-matching
  ** See Copyright Notice in lua.h
  */
***************
*** 754,759 ****
--- 754,760 ----
  
  
  static int str_format (lua_State *L) {
+   int top = lua_gettop(L);
    int arg = 1;
    size_t sfl;
    const char *strfrmt = luaL_checklstring(L, arg, &sfl);
***************
*** 768,774 ****
      else { /* format item */
        char form[MAX_FORMAT];  /* to store the format (`%...') */
        char buff[MAX_ITEM];  /* to store the formatted item */
!       arg++;
        strfrmt = scanformat(L, strfrmt, form);
        switch (*strfrmt++) {
          case 'c': {
--- 769,776 ----
      else { /* format item */
        char form[MAX_FORMAT];  /* to store the format (`%...') */
        char buff[MAX_ITEM];  /* to store the formatted item */
!       if (++arg > top)
!         luaL_argerror(L, arg, "no value");
        strfrmt = scanformat(L, strfrmt, form);
        switch (*strfrmt++) {
          case 'c': {
diff -crB lua-5.1.4_2/src/lvm.c lua-5.1.4/src/lvm.c
*** lua-5.1.4_2/src/lvm.c	2007-12-28 16:32:23.000000000 +0100
--- lua-5.1.4/src/lvm.c	2010-11-19 14:10:08.000000000 +0100
***************
*** 1,5 ****
  /*
! ** $Id: lvm.c,v 2.63.1.3 2007/12/28 15:32:23 roberto Exp $
  ** Lua virtual machine
  ** See Copyright Notice in lua.h
  */
--- 1,5 ----
  /*
! ** $Id: lvm.c,v 2.63.1.4 2009/07/01 21:10:33 roberto Exp $
  ** Lua virtual machine
  ** See Copyright Notice in lua.h
  */
***************
*** 133,138 ****
--- 133,139 ----
  
  void luaV_settable (lua_State *L, const TValue *t, TValue *key, StkId val) {
    int loop;
+   TValue temp;
    for (loop = 0; loop < MAXTAGLOOP; loop++) {
      const TValue *tm;
      if (ttistable(t)) {  /* `t' is a table? */
***************
*** 152,158 ****
        callTM(L, tm, t, key, val);
        return;
      }
!     t = tm;  /* else repeat with `tm' */ 
    }
    luaG_runerror(L, "loop in settable");
  }
--- 153,161 ----
        callTM(L, tm, t, key, val);
        return;
      }
!     /* else repeat with `tm' */
!     setobj(L, &temp, tm);  /* avoid pointing inside table (may rehash) */
!     t = &temp;
    }
    luaG_runerror(L, "loop in settable");
  }
