From b69faf0bcc5ddca1d88b1a7ab47bcbbc6dbb9af1 Mon Sep 17 00:00:00 2001 From: William Wilgus Date: Thu, 8 Nov 2018 11:32:45 -0500 Subject: lua update to 5.1.5 Modify Rocklua towards upstream 5.1.5 Clean up some of the Rocklua implementation Change-Id: Iac722e827899cf84f5ca004ef7ae7ddce5f7fbbe --- apps/plugins/lua/lauxlib.c | 7 ++--- apps/plugins/lua/lauxlib.h | 4 +-- apps/plugins/lua/lbaselib.c | 47 +++++++++++++++-------------- apps/plugins/lua/lcode.c | 16 +++------- apps/plugins/lua/ldo.c | 3 +- apps/plugins/lua/lgc.c | 3 +- apps/plugins/lua/liolib.c | 73 +++++++++++++++++++++++++-------------------- apps/plugins/lua/llex.c | 6 ++-- apps/plugins/lua/lmathlib.c | 19 +++++++----- apps/plugins/lua/loadlib.c | 12 ++++---- apps/plugins/lua/lparser.c | 10 +++---- apps/plugins/lua/lstrlib.c | 8 +++-- apps/plugins/lua/lua.h | 8 ++--- apps/plugins/lua/lvm.c | 12 ++++++-- apps/plugins/lua/rocklibc.h | 1 + 15 files changed, 124 insertions(+), 105 deletions(-) diff --git a/apps/plugins/lua/lauxlib.c b/apps/plugins/lua/lauxlib.c index b8020b7475..9597f63c60 100644 --- a/apps/plugins/lua/lauxlib.c +++ b/apps/plugins/lua/lauxlib.c @@ -199,7 +199,7 @@ LUALIB_API lua_Integer luaL_optinteger (lua_State *L, int narg, return luaL_opt(L, luaL_checkinteger, narg, def); } - +/* ROCKLUA ADDED */ LUALIB_API int luaL_checkboolean (lua_State *L, int narg) { int b = lua_toboolean(L, narg); if( b == 0 && !lua_isboolean(L, narg)) @@ -207,7 +207,7 @@ LUALIB_API int luaL_checkboolean (lua_State *L, int narg) { return b; } - +/* ROCKLUA ADDED */ LUALIB_API int luaL_optboolean (lua_State *L, int narg, int def) { return luaL_opt(L, luaL_checkboolean, narg, def); } @@ -538,7 +538,7 @@ typedef struct LoadF { char buff[LUAL_BUFFERSIZE]; } LoadF; -static const char *getF(lua_State *L, void *ud, size_t *size) { +static const char *getF (lua_State *L, void *ud, size_t *size) { LoadF *lf = (LoadF *)ud; (void)L; if (lf->extraline) { @@ -547,7 +547,6 @@ static const char *getF(lua_State *L, void *ud, size_t *size) { return "\n"; } *size = rb->read(lf->f, lf->buff, LUAL_BUFFERSIZE); - if (*size <= 0) return NULL; return (*size > 0) ? lf->buff : NULL; } diff --git a/apps/plugins/lua/lauxlib.h b/apps/plugins/lua/lauxlib.h index a36de351fe..4b4f3be1db 100644 --- a/apps/plugins/lua/lauxlib.h +++ b/apps/plugins/lua/lauxlib.h @@ -1,5 +1,5 @@ /* -** $Id$ +** $Id: lauxlib.h,v 1.88.1.1 2007/12/27 13:02:25 roberto Exp $ ** Auxiliary functions for building Lua libraries ** See Copyright Notice in lua.h */ @@ -58,7 +58,7 @@ LUALIB_API lua_Integer (luaL_checkinteger) (lua_State *L, int numArg); LUALIB_API lua_Integer (luaL_optinteger) (lua_State *L, int nArg, lua_Integer def); -LUALIB_API int (luaL_checkboolean) (lua_State *L, int numArg); +LUALIB_API int (luaL_checkboolean) (lua_State *L, int nArg); LUALIB_API int (luaL_optboolean) (lua_State *L, int nArg, int def); diff --git a/apps/plugins/lua/lbaselib.c b/apps/plugins/lua/lbaselib.c index 008e3629fe..ad94984191 100644 --- a/apps/plugins/lua/lbaselib.c +++ b/apps/plugins/lua/lbaselib.c @@ -225,6 +225,24 @@ static int luaB_type (lua_State *L) { } +/** $Id: lbaselib.c,v 1.276.1.1 2013/04/12 18:48:47 roberto Exp $ */ +static int pairsmeta (lua_State *L, const char *method, int iszero, + lua_CFunction iter) { + if (!luaL_getmetafield(L, 1, method)) { /* no metamethod? */ + luaL_checktype(L, 1, LUA_TTABLE); /* argument must be a table */ + lua_pushcfunction(L, iter); /* will return generator, */ + lua_pushvalue(L, 1); /* state, */ + if (iszero) lua_pushinteger(L, 0); /* and initial value */ + else lua_pushnil(L); + } + else { + lua_pushvalue(L, 1); /* argument 'self' to metamethod */ + lua_call(L, 1, 3); /* get 3 values from metamethod */ + } + return 3; +} + + static int luaB_next (lua_State *L) { luaL_checktype(L, 1, LUA_TTABLE); lua_settop(L, 2); /* create a 2nd argument if there isn't one */ @@ -238,11 +256,8 @@ static int luaB_next (lua_State *L) { static int luaB_pairs (lua_State *L) { - luaL_checktype(L, 1, LUA_TTABLE); - lua_pushvalue(L, lua_upvalueindex(1)); /* return generator, */ - lua_pushvalue(L, 1); /* state, */ - lua_pushnil(L); /* and initial value */ - return 3; + /* pairs function from lua 5.2 */ + return pairsmeta(L, "__pairs", 0, luaB_next); } @@ -252,16 +267,13 @@ static int ipairsaux (lua_State *L) { i++; /* next value */ lua_pushinteger(L, i); lua_rawgeti(L, 1, i); - return (lua_isnil(L, -1)) ? 0 : 2; + return (lua_isnil(L, -1)) ? 1 : 2; } static int luaB_ipairs (lua_State *L) { - luaL_checktype(L, 1, LUA_TTABLE); - lua_pushvalue(L, lua_upvalueindex(1)); /* return generator, */ - lua_pushvalue(L, 1); /* state, */ - lua_pushinteger(L, 0); /* and initial value */ - return 3; + return pairsmeta(L, "__ipairs", 1, ipairsaux); + /* ipairs function from lua 5.2 */ } @@ -454,10 +466,12 @@ static const luaL_Reg base_funcs[] = { {"gcinfo", luaB_gcinfo}, {"getfenv", luaB_getfenv}, {"getmetatable", luaB_getmetatable}, + {"ipairs", luaB_ipairs}, {"loadfile", luaB_loadfile}, {"load", luaB_load}, {"loadstring", luaB_loadstring}, {"next", luaB_next}, + {"pairs", luaB_pairs}, {"pcall", luaB_pcall}, #if 0 {"print", luaB_print}, @@ -619,14 +633,6 @@ static const luaL_Reg co_funcs[] = { /* }====================================================== */ -static void auxopen (lua_State *L, const char *name, - lua_CFunction f, lua_CFunction u) { - lua_pushcfunction(L, u); - lua_pushcclosure(L, f, 1); - lua_setfield(L, -2, name); -} - - static void base_open (lua_State *L) { /* set global _G */ lua_pushvalue(L, LUA_GLOBALSINDEX); @@ -635,9 +641,6 @@ static void base_open (lua_State *L) { luaL_register(L, "_G", base_funcs); lua_pushliteral(L, LUA_VERSION); lua_setglobal(L, "_VERSION"); /* set global _VERSION */ - /* `ipairs' and `pairs' need auxliliary functions as upvalues */ - auxopen(L, "ipairs", luaB_ipairs, ipairsaux); - auxopen(L, "pairs", luaB_pairs, luaB_next); /* `newproxy' needs a weaktable as upvalue */ lua_createtable(L, 0, 1); /* new table `w' */ lua_pushvalue(L, -1); /* `w' will be its own metatable */ diff --git a/apps/plugins/lua/lcode.c b/apps/plugins/lua/lcode.c index cc26ac7521..07f9cbe4c4 100644 --- a/apps/plugins/lua/lcode.c +++ b/apps/plugins/lua/lcode.c @@ -1,5 +1,5 @@ /* -** $Id: lcode.c,v 2.25.1.3 2007/12/28 15:32:23 roberto Exp $ +** $Id: lcode.c,v 2.25.1.5 2011/01/31 14:53:16 roberto Exp $ ** Code generator for Lua ** See Copyright Notice in lua.h */ @@ -544,10 +544,6 @@ void luaK_goiftrue (FuncState *fs, expdesc *e) { 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; @@ -572,10 +568,6 @@ static void luaK_goiffalse (FuncState *fs, expdesc *e) { 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; @@ -641,10 +633,10 @@ static int constfolding (OpCode op, expdesc *e1, expdesc *e2) { case OP_ADD: r = luai_numadd(v1, v2); break; case OP_SUB: r = luai_numsub(v1, v2); break; case OP_MUL: r = luai_nummul(v1, v2); break; - case OP_DIV: + case OP_DIV: /* ROCKLUA BUGFIX */ if (v2 == 0) return -1; /* do not attempt to divide by 0 */ r = luai_numdiv(v1, v2); break; - case OP_MOD: + case OP_MOD: /* ROCKLUA BUGFIX */ if (v2 == 0) return -1; /* do not attempt to divide by 0 */ r = luai_nummod(v1, v2); break; case OP_POW: r = luai_numpow(v1, v2); break; @@ -659,7 +651,7 @@ static int constfolding (OpCode op, expdesc *e1, expdesc *e2) { static void codearith (FuncState *fs, OpCode op, expdesc *e1, expdesc *e2) { - int resf = constfolding(op, e1, e2); + int resf = constfolding(op, e1, e2); /* ROCKLUA BUGFIX */ if (resf > 0) return; else if (resf == 0) { diff --git a/apps/plugins/lua/ldo.c b/apps/plugins/lua/ldo.c index f303c744c7..43266de95e 100644 --- a/apps/plugins/lua/ldo.c +++ b/apps/plugins/lua/ldo.c @@ -1,5 +1,5 @@ /* -** $Id: ldo.c,v 2.38.1.3 2008/01/18 22:31:22 roberto Exp $ +** $Id: ldo.c,v 2.38.1.4 2012/01/18 02:27:10 roberto Exp $ ** Stack and Call structure of Lua ** See Copyright Notice in lua.h */ @@ -217,6 +217,7 @@ static StkId adjust_varargs (lua_State *L, Proto *p, int actual) { int nvar = actual - nfixargs; /* number of extra arguments */ lua_assert(p->is_vararg & VARARG_HASARG); luaC_checkGC(L); + luaD_checkstack(L, p->maxstacksize); htab = luaH_new(L, nvar, 1); /* create `arg' table */ for (i=0; itop - nvar + i); diff --git a/apps/plugins/lua/lgc.c b/apps/plugins/lua/lgc.c index d9e0b78294..e909c79a96 100644 --- a/apps/plugins/lua/lgc.c +++ b/apps/plugins/lua/lgc.c @@ -1,5 +1,5 @@ /* -** $Id: lgc.c,v 2.38.1.1 2007/12/27 13:02:25 roberto Exp $ +** $Id: lgc.c,v 2.38.1.2 2011/03/18 18:05:38 roberto Exp $ ** Garbage Collector ** See Copyright Notice in lua.h */ @@ -627,7 +627,6 @@ void luaC_step (lua_State *L) { } } else { - lua_assert(g->totalbytes >= g->estimate); setthreshold(g); } } diff --git a/apps/plugins/lua/liolib.c b/apps/plugins/lua/liolib.c index fb6765492b..81edb9a534 100644 --- a/apps/plugins/lua/liolib.c +++ b/apps/plugins/lua/liolib.c @@ -40,7 +40,7 @@ static int pushresult (lua_State *L, int i, const char *filename) { lua_pushfstring(L, "%s: %s", filename, strerror(en)); else lua_pushfstring(L, "%s", strerror(en)); - lua_pushinteger(L, 0); + lua_pushinteger(L, en); return 3; } } @@ -51,6 +51,7 @@ static void fileerror (lua_State *L, int arg, const char *filename) { luaL_argerror(L, arg, lua_tostring(L, -1)); } +#define tofilep(L) ((int*) luaL_checkudata(L, 1, LUA_FILEHANDLE)) static int io_type (lua_State *L) { void *ud; @@ -68,7 +69,7 @@ static int io_type (lua_State *L) { static int* tofile (lua_State *L) { - int *f = (int*) luaL_checkudata(L, 1, LUA_FILEHANDLE); + int *f = tofilep(L); if (*f < 0) luaL_error(L, "attempt to use a closed file"); return f; @@ -115,20 +116,20 @@ static int io_close (lua_State *L) { static int io_gc (lua_State *L) { - int f = *(int*) luaL_checkudata(L, 1, LUA_FILEHANDLE); + int *f = tofilep(L); /* ignore closed files */ - if (f >= 0) + if (*f >= 0) aux_close(L); return 0; } static int io_tostring (lua_State *L) { - int f = *(int*) luaL_checkudata(L, 1, LUA_FILEHANDLE); - if (f < 0) + int *f = tofilep(L); + if (*f < 0) lua_pushliteral(L, "file (closed)"); else - lua_pushfstring(L, "file (%d)", f); + lua_pushfstring(L, "file (%d)", *f); return 1; } @@ -137,28 +138,33 @@ static int io_open (lua_State *L) { const char *filename = luaL_checkstring(L, 1); const char *mode = luaL_optstring(L, 2, "r"); int *pf = newfile(L); - int flags = 0; - if(*(mode+1) == '+') { - flags = O_RDWR; - switch(*mode) { - case 'w': - flags |= O_TRUNC; break; - case 'a': - flags |= O_APPEND; break; - } - } - else { - switch(*mode) { - case 'r': - flags = O_RDONLY; break; - case 'w': - flags = O_WRONLY | O_TRUNC; break; - case 'a': - flags = O_WRONLY | O_APPEND; break; - } + int flags, wrmode; + + switch(*mode) { + case 'r': + flags = O_RDONLY; + wrmode = 0; + break; + case 'w': + flags = O_WRONLY; + wrmode = O_CREAT | O_TRUNC; + break; + case 'a': + flags = O_WRONLY; + wrmode = O_CREAT | O_APPEND; + break; + default: + flags = 0; + wrmode = 0; + return luaL_error(L, "invalid option " LUA_QL("%c") " to " + LUA_QL("open"), *mode); } - if((*mode == 'w' || *mode == 'a') && !rb->file_exists(filename)) - flags |= O_CREAT; + + if(*(mode+1) == '+') + flags = O_RDWR; + + flags |= wrmode; + *pf = rb->open(filename, flags, 0666); return (*pf < 0) ? pushresult(L, 0, filename) : 1; } @@ -252,7 +258,10 @@ static int read_number (lua_State *L, int *f) { lua_pushnumber(L, d); return 1; } - else return 0; /* read fails */ + else { + lua_pushnil(L); /* "result" to be removed */ + return 0; /* read fails */ + } } @@ -412,14 +421,14 @@ static int f_write (lua_State *L) { static int f_seek (lua_State *L) { static const int mode[] = {SEEK_SET, SEEK_CUR, SEEK_END}; static const char *const modenames[] = {"set", "cur", "end", NULL}; - int f = *tofile(L); + int *f = tofile(L); int op = luaL_checkoption(L, 2, "cur", modenames); long offset = luaL_optlong(L, 3, 0); - off_t size = rb->lseek(f, offset, mode[op]); + off_t size = rb->lseek(*f, offset, mode[op]); if (size < 0 || size > MAX_INT) /* signed limit */ return pushresult(L, 0, NULL); /* error */ else { - lua_pushinteger(L, (LUA_INTEGER) size ); + lua_pushinteger(L, (LUA_INTEGER) size ); return 1; } } diff --git a/apps/plugins/lua/llex.c b/apps/plugins/lua/llex.c index 85ac516be3..6f78d48983 100644 --- a/apps/plugins/lua/llex.c +++ b/apps/plugins/lua/llex.c @@ -1,5 +1,5 @@ /* -** $Id: llex.c,v 2.20.1.1 2007/12/27 13:02:25 roberto Exp $ +** $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,8 +118,10 @@ TString *luaX_newstring (LexState *ls, const char *str, size_t l) { 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)) + if (ttisnil(o)) { setbvalue(o, 1); /* make sure `str' will not be collected */ + luaC_checkGC(L); + } return ts; } diff --git a/apps/plugins/lua/lmathlib.c b/apps/plugins/lua/lmathlib.c index 99a104050c..56c79afced 100644 --- a/apps/plugins/lua/lmathlib.c +++ b/apps/plugins/lua/lmathlib.c @@ -82,19 +82,17 @@ static int math_atan2 (lua_State *L) { lua_pushnumber(L, atan2(luaL_checknumber(L, 1), luaL_checknumber(L, 2))); return 1; } -#endif static int math_ceil (lua_State *L) { - /* Doesn't change anything in fixed point arithmetic */ - lua_pushnumber(L, luaL_checknumber(L, 1)); + lua_pushnumber(L, ceil(luaL_checknumber(L, 1))); return 1; } static int math_floor (lua_State *L) { - /* Doesn't change anything in fixed point arithmetic */ - lua_pushnumber(L, luaL_checknumber(L, 1)); + lua_pushnumber(L, floor(luaL_checknumber(L, 1))); return 1; } +#endif static int math_fmod (lua_State *L) { /* Was: lua_pushnumber(L, fmod(luaL_checknumber(L, 1), luaL_checknumber(L, 2))); */ @@ -220,6 +218,11 @@ static int math_randomseed (lua_State *L) { return 0; } +static int math_ident (lua_State *L) { /* ROCKLUA ADDED */ + /* Ceil & floor Doesn't change anything in fixed point arithmetic */ + lua_pushnumber(L, luaL_checknumber(L, 1)); + return 1; +} static const luaL_Reg mathlib[] = { {"abs", math_abs}, @@ -228,17 +231,15 @@ static const luaL_Reg mathlib[] = { {"asin", math_asin}, {"atan2", math_atan2}, {"atan", math_atan}, -#endif {"ceil", math_ceil}, -#if 0 {"cosh", math_cosh}, {"cos", math_cos}, #endif {"deg", math_deg}, #if 0 {"exp", math_exp}, -#endif {"floor", math_floor}, +#endif {"fmod", math_fmod}, #if 0 {"frexp", math_frexp}, @@ -262,6 +263,8 @@ static const luaL_Reg mathlib[] = { {"tanh", math_tanh}, {"tan", math_tan}, #endif + {"ceil", math_ident}, + {"floor", math_ident}, {NULL, NULL} }; diff --git a/apps/plugins/lua/loadlib.c b/apps/plugins/lua/loadlib.c index 87873f133f..1e310beed1 100644 --- a/apps/plugins/lua/loadlib.c +++ b/apps/plugins/lua/loadlib.c @@ -1,5 +1,5 @@ /* -** $Id: loadlib.c,v 1.52.1.3 2008/08/06 13:29:28 roberto Exp $ +** $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 ** @@ -21,9 +21,9 @@ #include "lauxlib.h" #include "lualib.h" #include "rocklib.h" +#include "rocklibc.h" - -#define setprogdir(L) ((void)0) +#define setprogdir(L) ((void)0) /* ROCKLUA ADDED */ /* @@ -54,7 +54,7 @@ static const char *pushnexttemplate (lua_State *L, const char *path) { static const char *findfile (lua_State *L, const char *name, const char *pname) { - get_current_path(L, 2); + get_current_path(L, 2); /* ROCKLUA ADDED */ const char *current_path = lua_tostring(L, -1); const char *path; @@ -196,7 +196,7 @@ static void modinit (lua_State *L, const char *modname) { lua_setfield(L, -2, "_M"); /* module._M = module */ lua_pushstring(L, modname); lua_setfield(L, -2, "_NAME"); - dot = rb->strrchr(modname, '.'); /* look for last dot in module name */ + dot = strrchr(modname, '.'); /* look for last dot in module name */ if (dot == NULL) dot = modname; else dot++; /* set _PACKAGE as package name (full module name minus last part) */ @@ -292,7 +292,7 @@ LUALIB_API int luaopen_package (lua_State *L) { lua_pushvalue(L, -1); lua_replace(L, LUA_ENVIRONINDEX); /* create `loaders' table */ - lua_createtable(L, 0, sizeof(loaders)/sizeof(loaders[0]) - 1); + 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 --git a/apps/plugins/lua/lparser.c b/apps/plugins/lua/lparser.c index 800cdb1a3b..dda7488dca 100644 --- a/apps/plugins/lua/lparser.c +++ b/apps/plugins/lua/lparser.c @@ -1,5 +1,5 @@ /* -** $Id: lparser.c,v 2.42.1.3 2007/12/28 15:32:23 roberto Exp $ +** $Id: lparser.c,v 2.42.1.4 2011/10/21 19:31:42 roberto Exp $ ** Lua Parser ** See Copyright Notice in lua.h */ @@ -325,7 +325,7 @@ static void pushclosure (LexState *ls, FuncState *func, expdesc *v) { } -static void lparser_open_func (LexState *ls, FuncState *fs) { +static void open_func (LexState *ls, FuncState *fs) { lua_State *L = ls->L; Proto *f = luaF_newproto(L); fs->f = f; @@ -374,9 +374,9 @@ static void close_func (LexState *ls) { lua_assert(luaG_checkcode(f)); lua_assert(fs->bl == NULL); ls->fs = fs->prev; - L->top -= 2; /* remove table and prototype from the stack */ /* last token read was anchored in defunct function; must reanchor it */ if (fs) anchor_token(ls); + L->top -= 2; /* remove table and prototype from the stack */ } @@ -385,7 +385,7 @@ Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, const char *name) { struct FuncState funcstate; lexstate.buff = buff; luaX_setinput(L, &lexstate, z, luaS_new(L, name)); - lparser_open_func(&lexstate, &funcstate); + open_func(&lexstate, &funcstate); funcstate.f->is_vararg = VARARG_ISVARARG; /* main func. is always vararg */ luaX_next(&lexstate); /* read first token */ chunk(&lexstate); @@ -576,7 +576,7 @@ static void parlist (LexState *ls) { static void body (LexState *ls, expdesc *e, int needself, int line) { /* body -> `(' parlist `)' chunk END */ FuncState new_fs; - lparser_open_func(ls, &new_fs); + open_func(ls, &new_fs); new_fs.f->linedefined = line; checknext(ls, '('); if (needself) { diff --git a/apps/plugins/lua/lstrlib.c b/apps/plugins/lua/lstrlib.c index 3d6103692f..8b39314e93 100644 --- a/apps/plugins/lua/lstrlib.c +++ b/apps/plugins/lua/lstrlib.c @@ -1,5 +1,5 @@ /* -** $Id: lstrlib.c,v 1.132.1.4 2008/07/11 17:27:21 roberto Exp $ +** $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,6 +754,7 @@ static void addintlen (char *form) { 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,7 +769,8 @@ static int str_format (lua_State *L) { else { /* format item */ char form[MAX_FORMAT]; /* to store the format (`%...') */ char buff[MAX_ITEM]; /* to store the formatted item */ - arg++; + if (++arg > top) + luaL_argerror(L, arg, "no value"); strfrmt = scanformat(L, strfrmt, form); switch (*strfrmt++) { case 'c': { @@ -785,11 +787,13 @@ static int str_format (lua_State *L) { snprintf(buff, MAX_ITEM, form, (unsigned LUA_INTFRM_T)luaL_checknumber(L, arg)); break; } +#if 0 /* ROCKLUA NO FLOATING POINT */ case 'e': case 'E': case 'f': case 'g': case 'G': { snprintf(buff, MAX_ITEM, form, (double)luaL_checknumber(L, arg)); break; } +#endif case 'q': { addquoted(L, &b, arg); continue; /* skip the 'addsize' at the end */ diff --git a/apps/plugins/lua/lua.h b/apps/plugins/lua/lua.h index a0c57dc60b..a4b73e743e 100644 --- a/apps/plugins/lua/lua.h +++ b/apps/plugins/lua/lua.h @@ -1,5 +1,5 @@ /* -** $Id$ +** $Id: lua.h,v 1.218.1.7 2012/01/13 20:36:20 roberto Exp $ ** Lua - An Extensible Extension Language ** Lua.org, PUC-Rio, Brazil (http://www.lua.org) ** See Copyright Notice at the end of this file @@ -17,9 +17,9 @@ #define LUA_VERSION "Lua 5.1" -#define LUA_RELEASE "Lua 5.1.4" +#define LUA_RELEASE "Lua 5.1.5" #define LUA_VERSION_NUM 501 -#define LUA_COPYRIGHT "Copyright (C) 1994-2008 Lua.org, PUC-Rio" +#define LUA_COPYRIGHT "Copyright (C) 1994-2012 Lua.org, PUC-Rio" #define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo & W. Celes" @@ -362,7 +362,7 @@ struct lua_Debug { /****************************************************************************** -* Copyright (C) 1994-2008 Lua.org, PUC-Rio. All rights reserved. +* Copyright (C) 1994-2012 Lua.org, PUC-Rio. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/apps/plugins/lua/lvm.c b/apps/plugins/lua/lvm.c index acce53a858..35a931d7a1 100644 --- a/apps/plugins/lua/lvm.c +++ b/apps/plugins/lua/lvm.c @@ -1,5 +1,5 @@ /* -** $Id: lvm.c,v 2.63.1.3 2007/12/28 15:32:23 roberto Exp $ +** $Id: lvm.c,v 2.63.1.5 2011/08/17 20:43:11 roberto Exp $ ** Lua virtual machine ** See Copyright Notice in lua.h */ @@ -133,6 +133,7 @@ void luaV_gettable (lua_State *L, const TValue *t, TValue *key, StkId val) { 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? */ @@ -141,6 +142,7 @@ void luaV_settable (lua_State *L, const TValue *t, TValue *key, StkId val) { if (!ttisnil(oldval) || /* result is no nil? */ (tm = fasttm(L, h->metatable, TM_NEWINDEX)) == NULL) { /* or no TM? */ setobj2t(L, oldval, val); + h->flags = 0; luaC_barriert(L, h, val); return; } @@ -152,7 +154,9 @@ void luaV_settable (lua_State *L, const TValue *t, TValue *key, StkId val) { callTM(L, tm, t, key, val); return; } - t = tm; /* else repeat with `tm' */ + /* else repeat with `tm' */ + setobj(L, &temp, tm); /* avoid pointing inside table (may rehash) */ + t = &temp; } luaG_runerror(L, "loop in settable"); } @@ -480,6 +484,7 @@ void luaV_execute (lua_State *L, int nexeccalls) { continue; } case OP_DIV: { + /* ROCKLUA INTEGER BUGFIX */ TValue *rb = RKB(i); TValue *rc = RKC(i); if (ttisnumber(rb) && ttisnumber(rc)) { @@ -495,6 +500,7 @@ void luaV_execute (lua_State *L, int nexeccalls) { continue; } case OP_MOD: { + /* ROCKLUA INTEGER BUGFIX */ TValue *rb = RKB(i); TValue *rc = RKC(i); if (ttisnumber(rb) && ttisnumber(rc)) { @@ -508,7 +514,7 @@ void luaV_execute (lua_State *L, int nexeccalls) { Protect(Arith(L, ra, rb, rc, TM_MOD)); continue; - } + } case OP_POW: { arith_op(luai_numpow, TM_POW); continue; diff --git a/apps/plugins/lua/rocklibc.h b/apps/plugins/lua/rocklibc.h index fde50ae4f5..f119265e8e 100644 --- a/apps/plugins/lua/rocklibc.h +++ b/apps/plugins/lua/rocklibc.h @@ -42,6 +42,7 @@ extern int errno; /* Simple substitutions */ #define memcmp rb->memcmp #define strlen rb->strlen +#define strrchr rb->strrchr #endif /* _ROCKLIBC_H_ */ -- cgit v1.2.3