summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam Wilgus <me.theuser@yahoo.com>2018-11-08 11:32:45 -0500
committerWilliam Wilgus <me.theuser@yahoo.com>2018-11-11 19:42:30 -0500
commitb69faf0bcc5ddca1d88b1a7ab47bcbbc6dbb9af1 (patch)
tree191277cab3ef773238c1e91dafaaea04ddca1949
parentde6618a2713ef26f888762cbe6539cc65a393c7c (diff)
downloadrockbox-b69faf0bcc5ddca1d88b1a7ab47bcbbc6dbb9af1.tar.gz
rockbox-b69faf0bcc5ddca1d88b1a7ab47bcbbc6dbb9af1.zip
lua update to 5.1.5
Modify Rocklua towards upstream 5.1.5 Clean up some of the Rocklua implementation Change-Id: Iac722e827899cf84f5ca004ef7ae7ddce5f7fbbe
-rw-r--r--apps/plugins/lua/lauxlib.c7
-rw-r--r--apps/plugins/lua/lauxlib.h4
-rw-r--r--apps/plugins/lua/lbaselib.c47
-rw-r--r--apps/plugins/lua/lcode.c16
-rw-r--r--apps/plugins/lua/ldo.c3
-rw-r--r--apps/plugins/lua/lgc.c3
-rw-r--r--apps/plugins/lua/liolib.c73
-rw-r--r--apps/plugins/lua/llex.c6
-rw-r--r--apps/plugins/lua/lmathlib.c19
-rw-r--r--apps/plugins/lua/loadlib.c12
-rw-r--r--apps/plugins/lua/lparser.c10
-rw-r--r--apps/plugins/lua/lstrlib.c8
-rw-r--r--apps/plugins/lua/lua.h8
-rw-r--r--apps/plugins/lua/lvm.c12
-rw-r--r--apps/plugins/lua/rocklibc.h1
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,
199 return luaL_opt(L, luaL_checkinteger, narg, def); 199 return luaL_opt(L, luaL_checkinteger, narg, def);
200} 200}
201 201
202 202/* ROCKLUA ADDED */
203LUALIB_API int luaL_checkboolean (lua_State *L, int narg) { 203LUALIB_API int luaL_checkboolean (lua_State *L, int narg) {
204 int b = lua_toboolean(L, narg); 204 int b = lua_toboolean(L, narg);
205 if( b == 0 && !lua_isboolean(L, narg)) 205 if( b == 0 && !lua_isboolean(L, narg))
@@ -207,7 +207,7 @@ LUALIB_API int luaL_checkboolean (lua_State *L, int narg) {
207 return b; 207 return b;
208} 208}
209 209
210 210/* ROCKLUA ADDED */
211LUALIB_API int luaL_optboolean (lua_State *L, int narg, int def) { 211LUALIB_API int luaL_optboolean (lua_State *L, int narg, int def) {
212 return luaL_opt(L, luaL_checkboolean, narg, def); 212 return luaL_opt(L, luaL_checkboolean, narg, def);
213} 213}
@@ -538,7 +538,7 @@ typedef struct LoadF {
538 char buff[LUAL_BUFFERSIZE]; 538 char buff[LUAL_BUFFERSIZE];
539} LoadF; 539} LoadF;
540 540
541static const char *getF(lua_State *L, void *ud, size_t *size) { 541static const char *getF (lua_State *L, void *ud, size_t *size) {
542 LoadF *lf = (LoadF *)ud; 542 LoadF *lf = (LoadF *)ud;
543 (void)L; 543 (void)L;
544 if (lf->extraline) { 544 if (lf->extraline) {
@@ -547,7 +547,6 @@ static const char *getF(lua_State *L, void *ud, size_t *size) {
547 return "\n"; 547 return "\n";
548 } 548 }
549 *size = rb->read(lf->f, lf->buff, LUAL_BUFFERSIZE); 549 *size = rb->read(lf->f, lf->buff, LUAL_BUFFERSIZE);
550 if (*size <= 0) return NULL;
551 return (*size > 0) ? lf->buff : NULL; 550 return (*size > 0) ? lf->buff : NULL;
552} 551}
553 552
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 @@
1/* 1/*
2** $Id$ 2** $Id: lauxlib.h,v 1.88.1.1 2007/12/27 13:02:25 roberto Exp $
3** Auxiliary functions for building Lua libraries 3** Auxiliary functions for building Lua libraries
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -58,7 +58,7 @@ LUALIB_API lua_Integer (luaL_checkinteger) (lua_State *L, int numArg);
58LUALIB_API lua_Integer (luaL_optinteger) (lua_State *L, int nArg, 58LUALIB_API lua_Integer (luaL_optinteger) (lua_State *L, int nArg,
59 lua_Integer def); 59 lua_Integer def);
60 60
61LUALIB_API int (luaL_checkboolean) (lua_State *L, int numArg); 61LUALIB_API int (luaL_checkboolean) (lua_State *L, int nArg);
62LUALIB_API int (luaL_optboolean) (lua_State *L, int nArg, 62LUALIB_API int (luaL_optboolean) (lua_State *L, int nArg,
63 int def); 63 int def);
64 64
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) {
225} 225}
226 226
227 227
228/** $Id: lbaselib.c,v 1.276.1.1 2013/04/12 18:48:47 roberto Exp $ */
229static int pairsmeta (lua_State *L, const char *method, int iszero,
230 lua_CFunction iter) {
231 if (!luaL_getmetafield(L, 1, method)) { /* no metamethod? */
232 luaL_checktype(L, 1, LUA_TTABLE); /* argument must be a table */
233 lua_pushcfunction(L, iter); /* will return generator, */
234 lua_pushvalue(L, 1); /* state, */
235 if (iszero) lua_pushinteger(L, 0); /* and initial value */
236 else lua_pushnil(L);
237 }
238 else {
239 lua_pushvalue(L, 1); /* argument 'self' to metamethod */
240 lua_call(L, 1, 3); /* get 3 values from metamethod */
241 }
242 return 3;
243}
244
245
228static int luaB_next (lua_State *L) { 246static int luaB_next (lua_State *L) {
229 luaL_checktype(L, 1, LUA_TTABLE); 247 luaL_checktype(L, 1, LUA_TTABLE);
230 lua_settop(L, 2); /* create a 2nd argument if there isn't one */ 248 lua_settop(L, 2); /* create a 2nd argument if there isn't one */
@@ -238,11 +256,8 @@ static int luaB_next (lua_State *L) {
238 256
239 257
240static int luaB_pairs (lua_State *L) { 258static int luaB_pairs (lua_State *L) {
241 luaL_checktype(L, 1, LUA_TTABLE); 259 /* pairs function from lua 5.2 */
242 lua_pushvalue(L, lua_upvalueindex(1)); /* return generator, */ 260 return pairsmeta(L, "__pairs", 0, luaB_next);
243 lua_pushvalue(L, 1); /* state, */
244 lua_pushnil(L); /* and initial value */
245 return 3;
246} 261}
247 262
248 263
@@ -252,16 +267,13 @@ static int ipairsaux (lua_State *L) {
252 i++; /* next value */ 267 i++; /* next value */
253 lua_pushinteger(L, i); 268 lua_pushinteger(L, i);
254 lua_rawgeti(L, 1, i); 269 lua_rawgeti(L, 1, i);
255 return (lua_isnil(L, -1)) ? 0 : 2; 270 return (lua_isnil(L, -1)) ? 1 : 2;
256} 271}
257 272
258 273
259static int luaB_ipairs (lua_State *L) { 274static int luaB_ipairs (lua_State *L) {
260 luaL_checktype(L, 1, LUA_TTABLE); 275 return pairsmeta(L, "__ipairs", 1, ipairsaux);
261 lua_pushvalue(L, lua_upvalueindex(1)); /* return generator, */ 276 /* ipairs function from lua 5.2 */
262 lua_pushvalue(L, 1); /* state, */
263 lua_pushinteger(L, 0); /* and initial value */
264 return 3;
265} 277}
266 278
267 279
@@ -454,10 +466,12 @@ static const luaL_Reg base_funcs[] = {
454 {"gcinfo", luaB_gcinfo}, 466 {"gcinfo", luaB_gcinfo},
455 {"getfenv", luaB_getfenv}, 467 {"getfenv", luaB_getfenv},
456 {"getmetatable", luaB_getmetatable}, 468 {"getmetatable", luaB_getmetatable},
469 {"ipairs", luaB_ipairs},
457 {"loadfile", luaB_loadfile}, 470 {"loadfile", luaB_loadfile},
458 {"load", luaB_load}, 471 {"load", luaB_load},
459 {"loadstring", luaB_loadstring}, 472 {"loadstring", luaB_loadstring},
460 {"next", luaB_next}, 473 {"next", luaB_next},
474 {"pairs", luaB_pairs},
461 {"pcall", luaB_pcall}, 475 {"pcall", luaB_pcall},
462#if 0 476#if 0
463 {"print", luaB_print}, 477 {"print", luaB_print},
@@ -619,14 +633,6 @@ static const luaL_Reg co_funcs[] = {
619/* }====================================================== */ 633/* }====================================================== */
620 634
621 635
622static void auxopen (lua_State *L, const char *name,
623 lua_CFunction f, lua_CFunction u) {
624 lua_pushcfunction(L, u);
625 lua_pushcclosure(L, f, 1);
626 lua_setfield(L, -2, name);
627}
628
629
630static void base_open (lua_State *L) { 636static void base_open (lua_State *L) {
631 /* set global _G */ 637 /* set global _G */
632 lua_pushvalue(L, LUA_GLOBALSINDEX); 638 lua_pushvalue(L, LUA_GLOBALSINDEX);
@@ -635,9 +641,6 @@ static void base_open (lua_State *L) {
635 luaL_register(L, "_G", base_funcs); 641 luaL_register(L, "_G", base_funcs);
636 lua_pushliteral(L, LUA_VERSION); 642 lua_pushliteral(L, LUA_VERSION);
637 lua_setglobal(L, "_VERSION"); /* set global _VERSION */ 643 lua_setglobal(L, "_VERSION"); /* set global _VERSION */
638 /* `ipairs' and `pairs' need auxliliary functions as upvalues */
639 auxopen(L, "ipairs", luaB_ipairs, ipairsaux);
640 auxopen(L, "pairs", luaB_pairs, luaB_next);
641 /* `newproxy' needs a weaktable as upvalue */ 644 /* `newproxy' needs a weaktable as upvalue */
642 lua_createtable(L, 0, 1); /* new table `w' */ 645 lua_createtable(L, 0, 1); /* new table `w' */
643 lua_pushvalue(L, -1); /* `w' will be its own metatable */ 646 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 @@
1/* 1/*
2** $Id: lcode.c,v 2.25.1.3 2007/12/28 15:32:23 roberto Exp $ 2** $Id: lcode.c,v 2.25.1.5 2011/01/31 14:53:16 roberto Exp $
3** Code generator for Lua 3** Code generator for Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -544,10 +544,6 @@ void luaK_goiftrue (FuncState *fs, expdesc *e) {
544 pc = NO_JUMP; /* always true; do nothing */ 544 pc = NO_JUMP; /* always true; do nothing */
545 break; 545 break;
546 } 546 }
547 case VFALSE: {
548 pc = luaK_jump(fs); /* always jump */
549 break;
550 }
551 case VJMP: { 547 case VJMP: {
552 invertjump(fs, e); 548 invertjump(fs, e);
553 pc = e->u.s.info; 549 pc = e->u.s.info;
@@ -572,10 +568,6 @@ static void luaK_goiffalse (FuncState *fs, expdesc *e) {
572 pc = NO_JUMP; /* always false; do nothing */ 568 pc = NO_JUMP; /* always false; do nothing */
573 break; 569 break;
574 } 570 }
575 case VTRUE: {
576 pc = luaK_jump(fs); /* always jump */
577 break;
578 }
579 case VJMP: { 571 case VJMP: {
580 pc = e->u.s.info; 572 pc = e->u.s.info;
581 break; 573 break;
@@ -641,10 +633,10 @@ static int constfolding (OpCode op, expdesc *e1, expdesc *e2) {
641 case OP_ADD: r = luai_numadd(v1, v2); break; 633 case OP_ADD: r = luai_numadd(v1, v2); break;
642 case OP_SUB: r = luai_numsub(v1, v2); break; 634 case OP_SUB: r = luai_numsub(v1, v2); break;
643 case OP_MUL: r = luai_nummul(v1, v2); break; 635 case OP_MUL: r = luai_nummul(v1, v2); break;
644 case OP_DIV: 636 case OP_DIV: /* ROCKLUA BUGFIX */
645 if (v2 == 0) return -1; /* do not attempt to divide by 0 */ 637 if (v2 == 0) return -1; /* do not attempt to divide by 0 */
646 r = luai_numdiv(v1, v2); break; 638 r = luai_numdiv(v1, v2); break;
647 case OP_MOD: 639 case OP_MOD: /* ROCKLUA BUGFIX */
648 if (v2 == 0) return -1; /* do not attempt to divide by 0 */ 640 if (v2 == 0) return -1; /* do not attempt to divide by 0 */
649 r = luai_nummod(v1, v2); break; 641 r = luai_nummod(v1, v2); break;
650 case OP_POW: r = luai_numpow(v1, v2); break; 642 case OP_POW: r = luai_numpow(v1, v2); break;
@@ -659,7 +651,7 @@ static int constfolding (OpCode op, expdesc *e1, expdesc *e2) {
659 651
660 652
661static void codearith (FuncState *fs, OpCode op, expdesc *e1, expdesc *e2) { 653static void codearith (FuncState *fs, OpCode op, expdesc *e1, expdesc *e2) {
662 int resf = constfolding(op, e1, e2); 654 int resf = constfolding(op, e1, e2); /* ROCKLUA BUGFIX */
663 if (resf > 0) 655 if (resf > 0)
664 return; 656 return;
665 else if (resf == 0) { 657 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 @@
1/* 1/*
2** $Id: ldo.c,v 2.38.1.3 2008/01/18 22:31:22 roberto Exp $ 2** $Id: ldo.c,v 2.38.1.4 2012/01/18 02:27:10 roberto Exp $
3** Stack and Call structure of Lua 3** Stack and Call structure of Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -217,6 +217,7 @@ static StkId adjust_varargs (lua_State *L, Proto *p, int actual) {
217 int nvar = actual - nfixargs; /* number of extra arguments */ 217 int nvar = actual - nfixargs; /* number of extra arguments */
218 lua_assert(p->is_vararg & VARARG_HASARG); 218 lua_assert(p->is_vararg & VARARG_HASARG);
219 luaC_checkGC(L); 219 luaC_checkGC(L);
220 luaD_checkstack(L, p->maxstacksize);
220 htab = luaH_new(L, nvar, 1); /* create `arg' table */ 221 htab = luaH_new(L, nvar, 1); /* create `arg' table */
221 for (i=0; i<nvar; i++) /* put extra arguments into `arg' table */ 222 for (i=0; i<nvar; i++) /* put extra arguments into `arg' table */
222 setobj2n(L, luaH_setnum(L, htab, i+1), L->top - nvar + i); 223 setobj2n(L, luaH_setnum(L, htab, i+1), L->top - 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 @@
1/* 1/*
2** $Id: lgc.c,v 2.38.1.1 2007/12/27 13:02:25 roberto Exp $ 2** $Id: lgc.c,v 2.38.1.2 2011/03/18 18:05:38 roberto Exp $
3** Garbage Collector 3** Garbage Collector
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -627,7 +627,6 @@ void luaC_step (lua_State *L) {
627 } 627 }
628 } 628 }
629 else { 629 else {
630 lua_assert(g->totalbytes >= g->estimate);
631 setthreshold(g); 630 setthreshold(g);
632 } 631 }
633} 632}
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) {
40 lua_pushfstring(L, "%s: %s", filename, strerror(en)); 40 lua_pushfstring(L, "%s: %s", filename, strerror(en));
41 else 41 else
42 lua_pushfstring(L, "%s", strerror(en)); 42 lua_pushfstring(L, "%s", strerror(en));
43 lua_pushinteger(L, 0); 43 lua_pushinteger(L, en);
44 return 3; 44 return 3;
45 } 45 }
46} 46}
@@ -51,6 +51,7 @@ static void fileerror (lua_State *L, int arg, const char *filename) {
51 luaL_argerror(L, arg, lua_tostring(L, -1)); 51 luaL_argerror(L, arg, lua_tostring(L, -1));
52} 52}
53 53
54#define tofilep(L) ((int*) luaL_checkudata(L, 1, LUA_FILEHANDLE))
54 55
55static int io_type (lua_State *L) { 56static int io_type (lua_State *L) {
56 void *ud; 57 void *ud;
@@ -68,7 +69,7 @@ static int io_type (lua_State *L) {
68 69
69 70
70static int* tofile (lua_State *L) { 71static int* tofile (lua_State *L) {
71 int *f = (int*) luaL_checkudata(L, 1, LUA_FILEHANDLE); 72 int *f = tofilep(L);
72 if (*f < 0) 73 if (*f < 0)
73 luaL_error(L, "attempt to use a closed file"); 74 luaL_error(L, "attempt to use a closed file");
74 return f; 75 return f;
@@ -115,20 +116,20 @@ static int io_close (lua_State *L) {
115 116
116 117
117static int io_gc (lua_State *L) { 118static int io_gc (lua_State *L) {
118 int f = *(int*) luaL_checkudata(L, 1, LUA_FILEHANDLE); 119 int *f = tofilep(L);
119 /* ignore closed files */ 120 /* ignore closed files */
120 if (f >= 0) 121 if (*f >= 0)
121 aux_close(L); 122 aux_close(L);
122 return 0; 123 return 0;
123} 124}
124 125
125 126
126static int io_tostring (lua_State *L) { 127static int io_tostring (lua_State *L) {
127 int f = *(int*) luaL_checkudata(L, 1, LUA_FILEHANDLE); 128 int *f = tofilep(L);
128 if (f < 0) 129 if (*f < 0)
129 lua_pushliteral(L, "file (closed)"); 130 lua_pushliteral(L, "file (closed)");
130 else 131 else
131 lua_pushfstring(L, "file (%d)", f); 132 lua_pushfstring(L, "file (%d)", *f);
132 return 1; 133 return 1;
133} 134}
134 135
@@ -137,28 +138,33 @@ static int io_open (lua_State *L) {
137 const char *filename = luaL_checkstring(L, 1); 138 const char *filename = luaL_checkstring(L, 1);
138 const char *mode = luaL_optstring(L, 2, "r"); 139 const char *mode = luaL_optstring(L, 2, "r");
139 int *pf = newfile(L); 140 int *pf = newfile(L);
140 int flags = 0; 141 int flags, wrmode;
141 if(*(mode+1) == '+') { 142
142 flags = O_RDWR; 143 switch(*mode) {
143 switch(*mode) { 144 case 'r':
144 case 'w': 145 flags = O_RDONLY;
145 flags |= O_TRUNC; break; 146 wrmode = 0;
146 case 'a': 147 break;
147 flags |= O_APPEND; break; 148 case 'w':
148 } 149 flags = O_WRONLY;
149 } 150 wrmode = O_CREAT | O_TRUNC;
150 else { 151 break;
151 switch(*mode) { 152 case 'a':
152 case 'r': 153 flags = O_WRONLY;
153 flags = O_RDONLY; break; 154 wrmode = O_CREAT | O_APPEND;
154 case 'w': 155 break;
155 flags = O_WRONLY | O_TRUNC; break; 156 default:
156 case 'a': 157 flags = 0;
157 flags = O_WRONLY | O_APPEND; break; 158 wrmode = 0;
158 } 159 return luaL_error(L, "invalid option " LUA_QL("%c") " to "
160 LUA_QL("open"), *mode);
159 } 161 }
160 if((*mode == 'w' || *mode == 'a') && !rb->file_exists(filename)) 162
161 flags |= O_CREAT; 163 if(*(mode+1) == '+')
164 flags = O_RDWR;
165
166 flags |= wrmode;
167
162 *pf = rb->open(filename, flags, 0666); 168 *pf = rb->open(filename, flags, 0666);
163 return (*pf < 0) ? pushresult(L, 0, filename) : 1; 169 return (*pf < 0) ? pushresult(L, 0, filename) : 1;
164} 170}
@@ -252,7 +258,10 @@ static int read_number (lua_State *L, int *f) {
252 lua_pushnumber(L, d); 258 lua_pushnumber(L, d);
253 return 1; 259 return 1;
254 } 260 }
255 else return 0; /* read fails */ 261 else {
262 lua_pushnil(L); /* "result" to be removed */
263 return 0; /* read fails */
264 }
256} 265}
257 266
258 267
@@ -412,14 +421,14 @@ static int f_write (lua_State *L) {
412static int f_seek (lua_State *L) { 421static int f_seek (lua_State *L) {
413 static const int mode[] = {SEEK_SET, SEEK_CUR, SEEK_END}; 422 static const int mode[] = {SEEK_SET, SEEK_CUR, SEEK_END};
414 static const char *const modenames[] = {"set", "cur", "end", NULL}; 423 static const char *const modenames[] = {"set", "cur", "end", NULL};
415 int f = *tofile(L); 424 int *f = tofile(L);
416 int op = luaL_checkoption(L, 2, "cur", modenames); 425 int op = luaL_checkoption(L, 2, "cur", modenames);
417 long offset = luaL_optlong(L, 3, 0); 426 long offset = luaL_optlong(L, 3, 0);
418 off_t size = rb->lseek(f, offset, mode[op]); 427 off_t size = rb->lseek(*f, offset, mode[op]);
419 if (size < 0 || size > MAX_INT) /* signed limit */ 428 if (size < 0 || size > MAX_INT) /* signed limit */
420 return pushresult(L, 0, NULL); /* error */ 429 return pushresult(L, 0, NULL); /* error */
421 else { 430 else {
422 lua_pushinteger(L, (LUA_INTEGER) size ); 431 lua_pushinteger(L, (LUA_INTEGER) size );
423 return 1; 432 return 1;
424 } 433 }
425} 434}
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 @@
1/* 1/*
2** $Id: llex.c,v 2.20.1.1 2007/12/27 13:02:25 roberto Exp $ 2** $Id: llex.c,v 2.20.1.2 2009/11/23 14:58:22 roberto Exp $
3** Lexical Analyzer 3** Lexical Analyzer
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -118,8 +118,10 @@ TString *luaX_newstring (LexState *ls, const char *str, size_t l) {
118 lua_State *L = ls->L; 118 lua_State *L = ls->L;
119 TString *ts = luaS_newlstr(L, str, l); 119 TString *ts = luaS_newlstr(L, str, l);
120 TValue *o = luaH_setstr(L, ls->fs->h, ts); /* entry for `str' */ 120 TValue *o = luaH_setstr(L, ls->fs->h, ts); /* entry for `str' */
121 if (ttisnil(o)) 121 if (ttisnil(o)) {
122 setbvalue(o, 1); /* make sure `str' will not be collected */ 122 setbvalue(o, 1); /* make sure `str' will not be collected */
123 luaC_checkGC(L);
124 }
123 return ts; 125 return ts;
124} 126}
125 127
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) {
82 lua_pushnumber(L, atan2(luaL_checknumber(L, 1), luaL_checknumber(L, 2))); 82 lua_pushnumber(L, atan2(luaL_checknumber(L, 1), luaL_checknumber(L, 2)));
83 return 1; 83 return 1;
84} 84}
85#endif
86 85
87static int math_ceil (lua_State *L) { 86static int math_ceil (lua_State *L) {
88 /* Doesn't change anything in fixed point arithmetic */ 87 lua_pushnumber(L, ceil(luaL_checknumber(L, 1)));
89 lua_pushnumber(L, luaL_checknumber(L, 1));
90 return 1; 88 return 1;
91} 89}
92 90
93static int math_floor (lua_State *L) { 91static int math_floor (lua_State *L) {
94 /* Doesn't change anything in fixed point arithmetic */ 92 lua_pushnumber(L, floor(luaL_checknumber(L, 1)));
95 lua_pushnumber(L, luaL_checknumber(L, 1));
96 return 1; 93 return 1;
97} 94}
95#endif
98 96
99static int math_fmod (lua_State *L) { 97static int math_fmod (lua_State *L) {
100 /* Was: lua_pushnumber(L, fmod(luaL_checknumber(L, 1), luaL_checknumber(L, 2))); */ 98 /* Was: lua_pushnumber(L, fmod(luaL_checknumber(L, 1), luaL_checknumber(L, 2))); */
@@ -220,6 +218,11 @@ static int math_randomseed (lua_State *L) {
220 return 0; 218 return 0;
221} 219}
222 220
221static int math_ident (lua_State *L) { /* ROCKLUA ADDED */
222 /* Ceil & floor Doesn't change anything in fixed point arithmetic */
223 lua_pushnumber(L, luaL_checknumber(L, 1));
224 return 1;
225}
223 226
224static const luaL_Reg mathlib[] = { 227static const luaL_Reg mathlib[] = {
225 {"abs", math_abs}, 228 {"abs", math_abs},
@@ -228,17 +231,15 @@ static const luaL_Reg mathlib[] = {
228 {"asin", math_asin}, 231 {"asin", math_asin},
229 {"atan2", math_atan2}, 232 {"atan2", math_atan2},
230 {"atan", math_atan}, 233 {"atan", math_atan},
231#endif
232 {"ceil", math_ceil}, 234 {"ceil", math_ceil},
233#if 0
234 {"cosh", math_cosh}, 235 {"cosh", math_cosh},
235 {"cos", math_cos}, 236 {"cos", math_cos},
236#endif 237#endif
237 {"deg", math_deg}, 238 {"deg", math_deg},
238#if 0 239#if 0
239 {"exp", math_exp}, 240 {"exp", math_exp},
240#endif
241 {"floor", math_floor}, 241 {"floor", math_floor},
242#endif
242 {"fmod", math_fmod}, 243 {"fmod", math_fmod},
243#if 0 244#if 0
244 {"frexp", math_frexp}, 245 {"frexp", math_frexp},
@@ -262,6 +263,8 @@ static const luaL_Reg mathlib[] = {
262 {"tanh", math_tanh}, 263 {"tanh", math_tanh},
263 {"tan", math_tan}, 264 {"tan", math_tan},
264#endif 265#endif
266 {"ceil", math_ident},
267 {"floor", math_ident},
265 {NULL, NULL} 268 {NULL, NULL}
266}; 269};
267 270
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 @@
1/* 1/*
2** $Id: loadlib.c,v 1.52.1.3 2008/08/06 13:29:28 roberto Exp $ 2** $Id: loadlib.c,v 1.52.1.4 2009/09/09 13:17:16 roberto Exp $
3** Dynamic library loader for Lua 3** Dynamic library loader for Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5** 5**
@@ -21,9 +21,9 @@
21#include "lauxlib.h" 21#include "lauxlib.h"
22#include "lualib.h" 22#include "lualib.h"
23#include "rocklib.h" 23#include "rocklib.h"
24#include "rocklibc.h"
24 25
25 26#define setprogdir(L) ((void)0) /* ROCKLUA ADDED */
26#define setprogdir(L) ((void)0)
27 27
28 28
29/* 29/*
@@ -54,7 +54,7 @@ static const char *pushnexttemplate (lua_State *L, const char *path) {
54 54
55static const char *findfile (lua_State *L, const char *name, 55static const char *findfile (lua_State *L, const char *name,
56 const char *pname) { 56 const char *pname) {
57 get_current_path(L, 2); 57 get_current_path(L, 2); /* ROCKLUA ADDED */
58 const char *current_path = lua_tostring(L, -1); 58 const char *current_path = lua_tostring(L, -1);
59 const char *path; 59 const char *path;
60 60
@@ -196,7 +196,7 @@ static void modinit (lua_State *L, const char *modname) {
196 lua_setfield(L, -2, "_M"); /* module._M = module */ 196 lua_setfield(L, -2, "_M"); /* module._M = module */
197 lua_pushstring(L, modname); 197 lua_pushstring(L, modname);
198 lua_setfield(L, -2, "_NAME"); 198 lua_setfield(L, -2, "_NAME");
199 dot = rb->strrchr(modname, '.'); /* look for last dot in module name */ 199 dot = strrchr(modname, '.'); /* look for last dot in module name */
200 if (dot == NULL) dot = modname; 200 if (dot == NULL) dot = modname;
201 else dot++; 201 else dot++;
202 /* set _PACKAGE as package name (full module name minus last part) */ 202 /* set _PACKAGE as package name (full module name minus last part) */
@@ -292,7 +292,7 @@ LUALIB_API int luaopen_package (lua_State *L) {
292 lua_pushvalue(L, -1); 292 lua_pushvalue(L, -1);
293 lua_replace(L, LUA_ENVIRONINDEX); 293 lua_replace(L, LUA_ENVIRONINDEX);
294 /* create `loaders' table */ 294 /* create `loaders' table */
295 lua_createtable(L, 0, sizeof(loaders)/sizeof(loaders[0]) - 1); 295 lua_createtable(L, sizeof(loaders)/sizeof(loaders[0]) - 1, 0);
296 /* fill it with pre-defined loaders */ 296 /* fill it with pre-defined loaders */
297 for (i=0; loaders[i] != NULL; i++) { 297 for (i=0; loaders[i] != NULL; i++) {
298 lua_pushcfunction(L, loaders[i]); 298 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 @@
1/* 1/*
2** $Id: lparser.c,v 2.42.1.3 2007/12/28 15:32:23 roberto Exp $ 2** $Id: lparser.c,v 2.42.1.4 2011/10/21 19:31:42 roberto Exp $
3** Lua Parser 3** Lua Parser
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -325,7 +325,7 @@ static void pushclosure (LexState *ls, FuncState *func, expdesc *v) {
325} 325}
326 326
327 327
328static void lparser_open_func (LexState *ls, FuncState *fs) { 328static void open_func (LexState *ls, FuncState *fs) {
329 lua_State *L = ls->L; 329 lua_State *L = ls->L;
330 Proto *f = luaF_newproto(L); 330 Proto *f = luaF_newproto(L);
331 fs->f = f; 331 fs->f = f;
@@ -374,9 +374,9 @@ static void close_func (LexState *ls) {
374 lua_assert(luaG_checkcode(f)); 374 lua_assert(luaG_checkcode(f));
375 lua_assert(fs->bl == NULL); 375 lua_assert(fs->bl == NULL);
376 ls->fs = fs->prev; 376 ls->fs = fs->prev;
377 L->top -= 2; /* remove table and prototype from the stack */
378 /* last token read was anchored in defunct function; must reanchor it */ 377 /* last token read was anchored in defunct function; must reanchor it */
379 if (fs) anchor_token(ls); 378 if (fs) anchor_token(ls);
379 L->top -= 2; /* remove table and prototype from the stack */
380} 380}
381 381
382 382
@@ -385,7 +385,7 @@ Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, const char *name) {
385 struct FuncState funcstate; 385 struct FuncState funcstate;
386 lexstate.buff = buff; 386 lexstate.buff = buff;
387 luaX_setinput(L, &lexstate, z, luaS_new(L, name)); 387 luaX_setinput(L, &lexstate, z, luaS_new(L, name));
388 lparser_open_func(&lexstate, &funcstate); 388 open_func(&lexstate, &funcstate);
389 funcstate.f->is_vararg = VARARG_ISVARARG; /* main func. is always vararg */ 389 funcstate.f->is_vararg = VARARG_ISVARARG; /* main func. is always vararg */
390 luaX_next(&lexstate); /* read first token */ 390 luaX_next(&lexstate); /* read first token */
391 chunk(&lexstate); 391 chunk(&lexstate);
@@ -576,7 +576,7 @@ static void parlist (LexState *ls) {
576static void body (LexState *ls, expdesc *e, int needself, int line) { 576static void body (LexState *ls, expdesc *e, int needself, int line) {
577 /* body -> `(' parlist `)' chunk END */ 577 /* body -> `(' parlist `)' chunk END */
578 FuncState new_fs; 578 FuncState new_fs;
579 lparser_open_func(ls, &new_fs); 579 open_func(ls, &new_fs);
580 new_fs.f->linedefined = line; 580 new_fs.f->linedefined = line;
581 checknext(ls, '('); 581 checknext(ls, '(');
582 if (needself) { 582 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 @@
1/* 1/*
2** $Id: lstrlib.c,v 1.132.1.4 2008/07/11 17:27:21 roberto Exp $ 2** $Id: lstrlib.c,v 1.132.1.5 2010/05/14 15:34:19 roberto Exp $
3** Standard library for string operations and pattern-matching 3** Standard library for string operations and pattern-matching
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -754,6 +754,7 @@ static void addintlen (char *form) {
754 754
755 755
756static int str_format (lua_State *L) { 756static int str_format (lua_State *L) {
757 int top = lua_gettop(L);
757 int arg = 1; 758 int arg = 1;
758 size_t sfl; 759 size_t sfl;
759 const char *strfrmt = luaL_checklstring(L, arg, &sfl); 760 const char *strfrmt = luaL_checklstring(L, arg, &sfl);
@@ -768,7 +769,8 @@ static int str_format (lua_State *L) {
768 else { /* format item */ 769 else { /* format item */
769 char form[MAX_FORMAT]; /* to store the format (`%...') */ 770 char form[MAX_FORMAT]; /* to store the format (`%...') */
770 char buff[MAX_ITEM]; /* to store the formatted item */ 771 char buff[MAX_ITEM]; /* to store the formatted item */
771 arg++; 772 if (++arg > top)
773 luaL_argerror(L, arg, "no value");
772 strfrmt = scanformat(L, strfrmt, form); 774 strfrmt = scanformat(L, strfrmt, form);
773 switch (*strfrmt++) { 775 switch (*strfrmt++) {
774 case 'c': { 776 case 'c': {
@@ -785,11 +787,13 @@ static int str_format (lua_State *L) {
785 snprintf(buff, MAX_ITEM, form, (unsigned LUA_INTFRM_T)luaL_checknumber(L, arg)); 787 snprintf(buff, MAX_ITEM, form, (unsigned LUA_INTFRM_T)luaL_checknumber(L, arg));
786 break; 788 break;
787 } 789 }
790#if 0 /* ROCKLUA NO FLOATING POINT */
788 case 'e': case 'E': case 'f': 791 case 'e': case 'E': case 'f':
789 case 'g': case 'G': { 792 case 'g': case 'G': {
790 snprintf(buff, MAX_ITEM, form, (double)luaL_checknumber(L, arg)); 793 snprintf(buff, MAX_ITEM, form, (double)luaL_checknumber(L, arg));
791 break; 794 break;
792 } 795 }
796#endif
793 case 'q': { 797 case 'q': {
794 addquoted(L, &b, arg); 798 addquoted(L, &b, arg);
795 continue; /* skip the 'addsize' at the end */ 799 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 @@
1/* 1/*
2** $Id$ 2** $Id: lua.h,v 1.218.1.7 2012/01/13 20:36:20 roberto Exp $
3** Lua - An Extensible Extension Language 3** Lua - An Extensible Extension Language
4** Lua.org, PUC-Rio, Brazil (http://www.lua.org) 4** Lua.org, PUC-Rio, Brazil (http://www.lua.org)
5** See Copyright Notice at the end of this file 5** See Copyright Notice at the end of this file
@@ -17,9 +17,9 @@
17 17
18 18
19#define LUA_VERSION "Lua 5.1" 19#define LUA_VERSION "Lua 5.1"
20#define LUA_RELEASE "Lua 5.1.4" 20#define LUA_RELEASE "Lua 5.1.5"
21#define LUA_VERSION_NUM 501 21#define LUA_VERSION_NUM 501
22#define LUA_COPYRIGHT "Copyright (C) 1994-2008 Lua.org, PUC-Rio" 22#define LUA_COPYRIGHT "Copyright (C) 1994-2012 Lua.org, PUC-Rio"
23#define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo & W. Celes" 23#define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo & W. Celes"
24 24
25 25
@@ -362,7 +362,7 @@ struct lua_Debug {
362 362
363 363
364/****************************************************************************** 364/******************************************************************************
365* Copyright (C) 1994-2008 Lua.org, PUC-Rio. All rights reserved. 365* Copyright (C) 1994-2012 Lua.org, PUC-Rio. All rights reserved.
366* 366*
367* Permission is hereby granted, free of charge, to any person obtaining 367* Permission is hereby granted, free of charge, to any person obtaining
368* a copy of this software and associated documentation files (the 368* 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 @@
1/* 1/*
2** $Id: lvm.c,v 2.63.1.3 2007/12/28 15:32:23 roberto Exp $ 2** $Id: lvm.c,v 2.63.1.5 2011/08/17 20:43:11 roberto Exp $
3** Lua virtual machine 3** Lua virtual machine
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -133,6 +133,7 @@ void luaV_gettable (lua_State *L, const TValue *t, TValue *key, StkId val) {
133 133
134void luaV_settable (lua_State *L, const TValue *t, TValue *key, StkId val) { 134void luaV_settable (lua_State *L, const TValue *t, TValue *key, StkId val) {
135 int loop; 135 int loop;
136 TValue temp;
136 for (loop = 0; loop < MAXTAGLOOP; loop++) { 137 for (loop = 0; loop < MAXTAGLOOP; loop++) {
137 const TValue *tm; 138 const TValue *tm;
138 if (ttistable(t)) { /* `t' is a table? */ 139 if (ttistable(t)) { /* `t' is a table? */
@@ -141,6 +142,7 @@ void luaV_settable (lua_State *L, const TValue *t, TValue *key, StkId val) {
141 if (!ttisnil(oldval) || /* result is no nil? */ 142 if (!ttisnil(oldval) || /* result is no nil? */
142 (tm = fasttm(L, h->metatable, TM_NEWINDEX)) == NULL) { /* or no TM? */ 143 (tm = fasttm(L, h->metatable, TM_NEWINDEX)) == NULL) { /* or no TM? */
143 setobj2t(L, oldval, val); 144 setobj2t(L, oldval, val);
145 h->flags = 0;
144 luaC_barriert(L, h, val); 146 luaC_barriert(L, h, val);
145 return; 147 return;
146 } 148 }
@@ -152,7 +154,9 @@ void luaV_settable (lua_State *L, const TValue *t, TValue *key, StkId val) {
152 callTM(L, tm, t, key, val); 154 callTM(L, tm, t, key, val);
153 return; 155 return;
154 } 156 }
155 t = tm; /* else repeat with `tm' */ 157 /* else repeat with `tm' */
158 setobj(L, &temp, tm); /* avoid pointing inside table (may rehash) */
159 t = &temp;
156 } 160 }
157 luaG_runerror(L, "loop in settable"); 161 luaG_runerror(L, "loop in settable");
158} 162}
@@ -480,6 +484,7 @@ void luaV_execute (lua_State *L, int nexeccalls) {
480 continue; 484 continue;
481 } 485 }
482 case OP_DIV: { 486 case OP_DIV: {
487 /* ROCKLUA INTEGER BUGFIX */
483 TValue *rb = RKB(i); 488 TValue *rb = RKB(i);
484 TValue *rc = RKC(i); 489 TValue *rc = RKC(i);
485 if (ttisnumber(rb) && ttisnumber(rc)) { 490 if (ttisnumber(rb) && ttisnumber(rc)) {
@@ -495,6 +500,7 @@ void luaV_execute (lua_State *L, int nexeccalls) {
495 continue; 500 continue;
496 } 501 }
497 case OP_MOD: { 502 case OP_MOD: {
503 /* ROCKLUA INTEGER BUGFIX */
498 TValue *rb = RKB(i); 504 TValue *rb = RKB(i);
499 TValue *rc = RKC(i); 505 TValue *rc = RKC(i);
500 if (ttisnumber(rb) && ttisnumber(rc)) { 506 if (ttisnumber(rb) && ttisnumber(rc)) {
@@ -508,7 +514,7 @@ void luaV_execute (lua_State *L, int nexeccalls) {
508 Protect(Arith(L, ra, rb, rc, TM_MOD)); 514 Protect(Arith(L, ra, rb, rc, TM_MOD));
509 515
510 continue; 516 continue;
511 } 517 }
512 case OP_POW: { 518 case OP_POW: {
513 arith_op(luai_numpow, TM_POW); 519 arith_op(luai_numpow, TM_POW);
514 continue; 520 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;
42/* Simple substitutions */ 42/* Simple substitutions */
43#define memcmp rb->memcmp 43#define memcmp rb->memcmp
44#define strlen rb->strlen 44#define strlen rb->strlen
45#define strrchr rb->strrchr
45 46
46#endif /* _ROCKLIBC_H_ */ 47#endif /* _ROCKLIBC_H_ */
47 48