summaryrefslogtreecommitdiff
path: root/apps/plugins/lua/ldump.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/ldump.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/ldump.c')
-rw-r--r--apps/plugins/lua/ldump.c43
1 files changed, 26 insertions, 17 deletions
diff --git a/apps/plugins/lua/ldump.c b/apps/plugins/lua/ldump.c
index c9d3d4870f..61fa2cd892 100644
--- a/apps/plugins/lua/ldump.c
+++ b/apps/plugins/lua/ldump.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldump.c,v 2.8.1.1 2007/12/27 13:02:25 roberto Exp $ 2** $Id: ldump.c,v 2.17.1.1 2013/04/12 18:48:47 roberto Exp $
3** save precompiled Lua chunks 3** save precompiled Lua chunks
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -24,7 +24,7 @@ typedef struct {
24} DumpState; 24} DumpState;
25 25
26#define DumpMem(b,n,size,D) DumpBlock(b,(n)*(size),D) 26#define DumpMem(b,n,size,D) DumpBlock(b,(n)*(size),D)
27#define DumpVar(x,D) DumpMem(&x,1,sizeof(x),D) 27#define DumpVar(x,D) DumpMem(&x,1,sizeof(x),D)
28 28
29static void DumpBlock(const void* b, size_t size, DumpState* D) 29static void DumpBlock(const void* b, size_t size, DumpState* D)
30{ 30{
@@ -60,7 +60,7 @@ static void DumpVector(const void* b, int n, size_t size, DumpState* D)
60 60
61static void DumpString(const TString* s, DumpState* D) 61static void DumpString(const TString* s, DumpState* D)
62{ 62{
63 if (s==NULL || getstr(s)==NULL) 63 if (s==NULL)
64 { 64 {
65 size_t size=0; 65 size_t size=0;
66 DumpVar(size,D); 66 DumpVar(size,D);
@@ -69,13 +69,13 @@ static void DumpString(const TString* s, DumpState* D)
69 { 69 {
70 size_t size=s->tsv.len+1; /* include trailing '\0' */ 70 size_t size=s->tsv.len+1; /* include trailing '\0' */
71 DumpVar(size,D); 71 DumpVar(size,D);
72 DumpBlock(getstr(s),size,D); 72 DumpBlock(getstr(s),size*sizeof(char),D);
73 } 73 }
74} 74}
75 75
76#define DumpCode(f,D) DumpVector(f->code,f->sizecode,sizeof(Instruction),D) 76#define DumpCode(f,D) DumpVector(f->code,f->sizecode,sizeof(Instruction),D)
77 77
78static void DumpFunction(const Proto* f, const TString* p, DumpState* D); 78static void DumpFunction(const Proto* f, DumpState* D);
79 79
80static void DumpConstants(const Proto* f, DumpState* D) 80static void DumpConstants(const Proto* f, DumpState* D)
81{ 81{
@@ -84,8 +84,8 @@ static void DumpConstants(const Proto* f, DumpState* D)
84 for (i=0; i<n; i++) 84 for (i=0; i<n; i++)
85 { 85 {
86 const TValue* o=&f->k[i]; 86 const TValue* o=&f->k[i];
87 DumpChar(ttype(o),D); 87 DumpChar(ttypenv(o),D);
88 switch (ttype(o)) 88 switch (ttypenv(o))
89 { 89 {
90 case LUA_TNIL: 90 case LUA_TNIL:
91 break; 91 break;
@@ -98,19 +98,29 @@ static void DumpConstants(const Proto* f, DumpState* D)
98 case LUA_TSTRING: 98 case LUA_TSTRING:
99 DumpString(rawtsvalue(o),D); 99 DumpString(rawtsvalue(o),D);
100 break; 100 break;
101 default: 101 default: lua_assert(0);
102 lua_assert(0); /* cannot happen */
103 break;
104 } 102 }
105 } 103 }
106 n=f->sizep; 104 n=f->sizep;
107 DumpInt(n,D); 105 DumpInt(n,D);
108 for (i=0; i<n; i++) DumpFunction(f->p[i],f->source,D); 106 for (i=0; i<n; i++) DumpFunction(f->p[i],D);
107}
108
109static void DumpUpvalues(const Proto* f, DumpState* D)
110{
111 int i,n=f->sizeupvalues;
112 DumpInt(n,D);
113 for (i=0; i<n; i++)
114 {
115 DumpChar(f->upvalues[i].instack,D);
116 DumpChar(f->upvalues[i].idx,D);
117 }
109} 118}
110 119
111static void DumpDebug(const Proto* f, DumpState* D) 120static void DumpDebug(const Proto* f, DumpState* D)
112{ 121{
113 int i,n; 122 int i,n;
123 DumpString((D->strip) ? NULL : f->source,D);
114 n= (D->strip) ? 0 : f->sizelineinfo; 124 n= (D->strip) ? 0 : f->sizelineinfo;
115 DumpVector(f->lineinfo,n,sizeof(int),D); 125 DumpVector(f->lineinfo,n,sizeof(int),D);
116 n= (D->strip) ? 0 : f->sizelocvars; 126 n= (D->strip) ? 0 : f->sizelocvars;
@@ -123,26 +133,25 @@ static void DumpDebug(const Proto* f, DumpState* D)
123 } 133 }
124 n= (D->strip) ? 0 : f->sizeupvalues; 134 n= (D->strip) ? 0 : f->sizeupvalues;
125 DumpInt(n,D); 135 DumpInt(n,D);
126 for (i=0; i<n; i++) DumpString(f->upvalues[i],D); 136 for (i=0; i<n; i++) DumpString(f->upvalues[i].name,D);
127} 137}
128 138
129static void DumpFunction(const Proto* f, const TString* p, DumpState* D) 139static void DumpFunction(const Proto* f, DumpState* D)
130{ 140{
131 DumpString((f->source==p || D->strip) ? NULL : f->source,D);
132 DumpInt(f->linedefined,D); 141 DumpInt(f->linedefined,D);
133 DumpInt(f->lastlinedefined,D); 142 DumpInt(f->lastlinedefined,D);
134 DumpChar(f->nups,D);
135 DumpChar(f->numparams,D); 143 DumpChar(f->numparams,D);
136 DumpChar(f->is_vararg,D); 144 DumpChar(f->is_vararg,D);
137 DumpChar(f->maxstacksize,D); 145 DumpChar(f->maxstacksize,D);
138 DumpCode(f,D); 146 DumpCode(f,D);
139 DumpConstants(f,D); 147 DumpConstants(f,D);
148 DumpUpvalues(f,D);
140 DumpDebug(f,D); 149 DumpDebug(f,D);
141} 150}
142 151
143static void DumpHeader(DumpState* D) 152static void DumpHeader(DumpState* D)
144{ 153{
145 char h[LUAC_HEADERSIZE]; 154 lu_byte h[LUAC_HEADERSIZE];
146 luaU_header(h); 155 luaU_header(h);
147 DumpBlock(h,LUAC_HEADERSIZE,D); 156 DumpBlock(h,LUAC_HEADERSIZE,D);
148} 157}
@@ -159,6 +168,6 @@ int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip
159 D.strip=strip; 168 D.strip=strip;
160 D.status=0; 169 D.status=0;
161 DumpHeader(&D); 170 DumpHeader(&D);
162 DumpFunction(f,NULL,&D); 171 DumpFunction(f,&D);
163 return D.status; 172 return D.status;
164} 173}