summaryrefslogtreecommitdiff
path: root/apps/plugins/lua/lfunc.c
diff options
context:
space:
mode:
authorRichard Quirk <richard.quirk@gmail.com>2014-03-19 19:31:31 +0100
committerMarcin Bukat <marcin.bukat@gmail.com>2014-04-02 20:31:54 +0200
commit36378988ad4059982742f05f5eb50580b456840a (patch)
treeee70be810d894566c5e351f21a1ebb79be742a85 /apps/plugins/lua/lfunc.c
parent020f16a1c7d5bc9a302671cef03f56ac735e20c5 (diff)
downloadrockbox-36378988ad4059982742f05f5eb50580b456840a.tar.gz
rockbox-36378988ad4059982742f05f5eb50580b456840a.zip
Update lua plugin to 5.2.3
Prior to this patch the Lua plugin used version 5.1.4. This change reduces the number of modifications in the Lua source using some new defines and because the upstream source is now more flexible. Unless otherwise stated, l*.[ch] files are taken unmodified from the upstream lua-5.2.3. fscanf.c: file descriptors in rockbox are just ints, they are hidden behind a void* now so liolib requires less modifications. fscanf is updated to use void* too. getc.c: this is a new file required for getc implementation in lauxlib.c lauxlib.c: LoadF replaced FILE* with int, the rockbox file descriptor int are cast to FILE* (actually void* due to typedef). getc uses the PREFIX version. stdin is not used, as per 5.1.4. lbaselib.c: now uses strspn in the number parsing. print uses DEBUGF now rather than being commented out. lbitlib.c: use the built-in version from 5.2.3 rather than Reuben Thomas's external library. Backwards compatible and adds some new bit operations. ldo.c: the LUAI_THROW/TRY defines are now in the core lua code, so have been removed from rockconf.h liolib.c: here the implementation has changed to use the LStream from the original source, and cast the FILE* pointers to int. This has reduced the number of modifications from the upstream version. llex.c: the only change from upstream is to remove the locale include. lmathlib.c: updated from the 5.2.3 version and re-applied the changes that were made vs 5.1.4 for random numbers and to remove unsupported float functions. loadlib.c: upstream version, with the 5.1.4 changes for missing functions. lobject.c: upstream version, with ctype.h added and sprintf changed to snprintf. loslib.c: upstream version with locale.h removed and 5.1.4 changes for unsupportable functions. lstrlib.c: sprintf changed to snprintf. ltable.c: upstream with the hashnum function from 5.1.4 to avoid frexp in luai_hashnum. luaconf.h: updated to 5.2.3 version, restored relevant parts from the original 5.1.4 configuration. The COMPAT defines that are no longer available are not included. lundump.c: VERSION macro conflicts with the core Rockbox equivalent. rocklib.c: luaL_reg is no longer available, replaced by luaL_Reg equivalent. Moved checkboolean/optboolean functions to this file and out of core lua files. luaL_getn is no longer available, replaced by luaL_rawlen. luaL_register is deprecated, use the newlib/setfuncs replacements. rli_init has to be called before setting up the newlib to avoid overwriting the rb table. rocklib_aux.pl: use rli_checkboolean from rocklib.c. rocklua.c: new default bits library used, update the library loading code with idiomatic 5.2 code. strcspn.c: no longer needed, but strspn.c is required for strspn in lbaselib.c Change-Id: I0c7945c755f79083afe98ec117e1e8cf13de2651 Reviewed-on: http://gerrit.rockbox.org/774 Tested: Richard Quirk <richard.quirk@gmail.com> Reviewed-by: Marcin Bukat <marcin.bukat@gmail.com>
Diffstat (limited to 'apps/plugins/lua/lfunc.c')
-rw-r--r--apps/plugins/lua/lfunc.c81
1 files changed, 34 insertions, 47 deletions
diff --git a/apps/plugins/lua/lfunc.c b/apps/plugins/lua/lfunc.c
index 813e88f583..e90e1520ce 100644
--- a/apps/plugins/lua/lfunc.c
+++ b/apps/plugins/lua/lfunc.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lfunc.c,v 2.12.1.2 2007/12/28 14:58:43 roberto Exp $ 2** $Id: lfunc.c,v 2.30.1.1 2013/04/12 18:48:47 roberto Exp $
3** Auxiliary functions to manipulate prototypes and closures 3** Auxiliary functions to manipulate prototypes and closures
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -20,30 +20,24 @@
20 20
21 21
22 22
23Closure *luaF_newCclosure (lua_State *L, int nelems, Table *e) { 23Closure *luaF_newCclosure (lua_State *L, int n) {
24 Closure *c = cast(Closure *, luaM_malloc(L, sizeCclosure(nelems))); 24 Closure *c = &luaC_newobj(L, LUA_TCCL, sizeCclosure(n), NULL, 0)->cl;
25 luaC_link(L, obj2gco(c), LUA_TFUNCTION); 25 c->c.nupvalues = cast_byte(n);
26 c->c.isC = 1;
27 c->c.env = e;
28 c->c.nupvalues = cast_byte(nelems);
29 return c; 26 return c;
30} 27}
31 28
32 29
33Closure *luaF_newLclosure (lua_State *L, int nelems, Table *e) { 30Closure *luaF_newLclosure (lua_State *L, int n) {
34 Closure *c = cast(Closure *, luaM_malloc(L, sizeLclosure(nelems))); 31 Closure *c = &luaC_newobj(L, LUA_TLCL, sizeLclosure(n), NULL, 0)->cl;
35 luaC_link(L, obj2gco(c), LUA_TFUNCTION); 32 c->l.p = NULL;
36 c->l.isC = 0; 33 c->l.nupvalues = cast_byte(n);
37 c->l.env = e; 34 while (n--) c->l.upvals[n] = NULL;
38 c->l.nupvalues = cast_byte(nelems);
39 while (nelems--) c->l.upvals[nelems] = NULL;
40 return c; 35 return c;
41} 36}
42 37
43 38
44UpVal *luaF_newupval (lua_State *L) { 39UpVal *luaF_newupval (lua_State *L) {
45 UpVal *uv = luaM_new(L, UpVal); 40 UpVal *uv = &luaC_newobj(L, LUA_TUPVAL, sizeof(UpVal), NULL, 0)->uv;
46 luaC_link(L, obj2gco(uv), LUA_TUPVAL);
47 uv->v = &uv->u.value; 41 uv->v = &uv->u.value;
48 setnilvalue(uv->v); 42 setnilvalue(uv->v);
49 return uv; 43 return uv;
@@ -55,21 +49,20 @@ UpVal *luaF_findupval (lua_State *L, StkId level) {
55 GCObject **pp = &L->openupval; 49 GCObject **pp = &L->openupval;
56 UpVal *p; 50 UpVal *p;
57 UpVal *uv; 51 UpVal *uv;
58 while (*pp != NULL && (p = ngcotouv(*pp))->v >= level) { 52 while (*pp != NULL && (p = gco2uv(*pp))->v >= level) {
53 GCObject *o = obj2gco(p);
59 lua_assert(p->v != &p->u.value); 54 lua_assert(p->v != &p->u.value);
55 lua_assert(!isold(o) || isold(obj2gco(L)));
60 if (p->v == level) { /* found a corresponding upvalue? */ 56 if (p->v == level) { /* found a corresponding upvalue? */
61 if (isdead(g, obj2gco(p))) /* is it dead? */ 57 if (isdead(g, o)) /* is it dead? */
62 changewhite(obj2gco(p)); /* ressurect it */ 58 changewhite(o); /* resurrect it */
63 return p; 59 return p;
64 } 60 }
65 pp = &p->next; 61 pp = &p->next;
66 } 62 }
67 uv = luaM_new(L, UpVal); /* not found: create a new one */ 63 /* not found: create a new one */
68 uv->tt = LUA_TUPVAL; 64 uv = &luaC_newobj(L, LUA_TUPVAL, sizeof(UpVal), pp, 0)->uv;
69 uv->marked = luaC_white(g);
70 uv->v = level; /* current value lives in the stack */ 65 uv->v = level; /* current value lives in the stack */
71 uv->next = *pp; /* chain it in the proper position */
72 *pp = obj2gco(uv);
73 uv->u.l.prev = &g->uvhead; /* double link it in `uvhead' list */ 66 uv->u.l.prev = &g->uvhead; /* double link it in `uvhead' list */
74 uv->u.l.next = g->uvhead.u.l.next; 67 uv->u.l.next = g->uvhead.u.l.next;
75 uv->u.l.next->u.l.prev = uv; 68 uv->u.l.next->u.l.prev = uv;
@@ -96,41 +89,42 @@ void luaF_freeupval (lua_State *L, UpVal *uv) {
96void luaF_close (lua_State *L, StkId level) { 89void luaF_close (lua_State *L, StkId level) {
97 UpVal *uv; 90 UpVal *uv;
98 global_State *g = G(L); 91 global_State *g = G(L);
99 while (L->openupval != NULL && (uv = ngcotouv(L->openupval))->v >= level) { 92 while (L->openupval != NULL && (uv = gco2uv(L->openupval))->v >= level) {
100 GCObject *o = obj2gco(uv); 93 GCObject *o = obj2gco(uv);
101 lua_assert(!isblack(o) && uv->v != &uv->u.value); 94 lua_assert(!isblack(o) && uv->v != &uv->u.value);
102 L->openupval = uv->next; /* remove from `open' list */ 95 L->openupval = uv->next; /* remove from `open' list */
103 if (isdead(g, o)) 96 if (isdead(g, o))
104 luaF_freeupval(L, uv); /* free upvalue */ 97 luaF_freeupval(L, uv); /* free upvalue */
105 else { 98 else {
106 unlinkupval(uv); 99 unlinkupval(uv); /* remove upvalue from 'uvhead' list */
107 setobj(L, &uv->u.value, uv->v); 100 setobj(L, &uv->u.value, uv->v); /* move value to upvalue slot */
108 uv->v = &uv->u.value; /* now current value lives here */ 101 uv->v = &uv->u.value; /* now current value lives here */
109 luaC_linkupval(L, uv); /* link upvalue into `gcroot' list */ 102 gch(o)->next = g->allgc; /* link upvalue into 'allgc' list */
103 g->allgc = o;
104 luaC_checkupvalcolor(g, uv);
110 } 105 }
111 } 106 }
112} 107}
113 108
114 109
115Proto *luaF_newproto (lua_State *L) { 110Proto *luaF_newproto (lua_State *L) {
116 Proto *f = luaM_new(L, Proto); 111 Proto *f = &luaC_newobj(L, LUA_TPROTO, sizeof(Proto), NULL, 0)->p;
117 luaC_link(L, obj2gco(f), LUA_TPROTO);
118 f->k = NULL; 112 f->k = NULL;
119 f->sizek = 0; 113 f->sizek = 0;
120 f->p = NULL; 114 f->p = NULL;
121 f->sizep = 0; 115 f->sizep = 0;
122 f->code = NULL; 116 f->code = NULL;
117 f->cache = NULL;
123 f->sizecode = 0; 118 f->sizecode = 0;
119 f->lineinfo = NULL;
124 f->sizelineinfo = 0; 120 f->sizelineinfo = 0;
125 f->sizeupvalues = 0;
126 f->nups = 0;
127 f->upvalues = NULL; 121 f->upvalues = NULL;
122 f->sizeupvalues = 0;
128 f->numparams = 0; 123 f->numparams = 0;
129 f->is_vararg = 0; 124 f->is_vararg = 0;
130 f->maxstacksize = 0; 125 f->maxstacksize = 0;
131 f->lineinfo = NULL;
132 f->sizelocvars = 0;
133 f->locvars = NULL; 126 f->locvars = NULL;
127 f->sizelocvars = 0;
134 f->linedefined = 0; 128 f->linedefined = 0;
135 f->lastlinedefined = 0; 129 f->lastlinedefined = 0;
136 f->source = NULL; 130 f->source = NULL;
@@ -139,23 +133,16 @@ Proto *luaF_newproto (lua_State *L) {
139 133
140 134
141void luaF_freeproto (lua_State *L, Proto *f) { 135void luaF_freeproto (lua_State *L, Proto *f) {
142 luaM_freearray(L, f->code, f->sizecode, Instruction); 136 luaM_freearray(L, f->code, f->sizecode);
143 luaM_freearray(L, f->p, f->sizep, Proto *); 137 luaM_freearray(L, f->p, f->sizep);
144 luaM_freearray(L, f->k, f->sizek, TValue); 138 luaM_freearray(L, f->k, f->sizek);
145 luaM_freearray(L, f->lineinfo, f->sizelineinfo, int); 139 luaM_freearray(L, f->lineinfo, f->sizelineinfo);
146 luaM_freearray(L, f->locvars, f->sizelocvars, struct LocVar); 140 luaM_freearray(L, f->locvars, f->sizelocvars);
147 luaM_freearray(L, f->upvalues, f->sizeupvalues, TString *); 141 luaM_freearray(L, f->upvalues, f->sizeupvalues);
148 luaM_free(L, f); 142 luaM_free(L, f);
149} 143}
150 144
151 145
152void luaF_freeclosure (lua_State *L, Closure *c) {
153 int size = (c->c.isC) ? sizeCclosure(c->c.nupvalues) :
154 sizeLclosure(c->l.nupvalues);
155 luaM_freemem(L, c, size);
156}
157
158
159/* 146/*
160** Look for n-th local variable at line `line' in function `func'. 147** Look for n-th local variable at line `line' in function `func'.
161** Returns NULL if not found. 148** Returns NULL if not found.