diff options
Diffstat (limited to 'lundump.c')
-rw-r--r-- | lundump.c | 69 |
1 files changed, 34 insertions, 35 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lundump.c,v 1.36 2001/07/19 14:34:06 lhf Exp lhf $ | 2 | ** $Id: lundump.c,v 1.43 2001/07/24 21:57:19 roberto Exp $ |
3 | ** load pre-compiled Lua chunks | 3 | ** load pre-compiled Lua chunks |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -7,7 +7,6 @@ | |||
7 | #include <stdio.h> | 7 | #include <stdio.h> |
8 | #include <string.h> | 8 | #include <string.h> |
9 | 9 | ||
10 | #define LUA_PRIVATE | ||
11 | #include "lua.h" | 10 | #include "lua.h" |
12 | 11 | ||
13 | #include "ldebug.h" | 12 | #include "ldebug.h" |
@@ -20,15 +19,15 @@ | |||
20 | #define LoadByte ezgetc | 19 | #define LoadByte ezgetc |
21 | #define LoadShort (short) LoadInt | 20 | #define LoadShort (short) LoadInt |
22 | 21 | ||
23 | static const l_char* ZNAME (ZIO* Z) | 22 | static const char* ZNAME (ZIO* Z) |
24 | { | 23 | { |
25 | const l_char* s=zname(Z); | 24 | const char* s=zname(Z); |
26 | return (*s==l_c('@')) ? s+1 : s; | 25 | return (*s=='@') ? s+1 : s; |
27 | } | 26 | } |
28 | 27 | ||
29 | static void unexpectedEOZ (lua_State* L, ZIO* Z) | 28 | static void unexpectedEOZ (lua_State* L, ZIO* Z) |
30 | { | 29 | { |
31 | luaO_verror(L,l_s("unexpected end of file in `%.99s'"),ZNAME(Z)); | 30 | luaO_verror(L,"unexpected end of file in `%.99s'",ZNAME(Z)); |
32 | } | 31 | } |
33 | 32 | ||
34 | static int ezgetc (lua_State* L, ZIO* Z) | 33 | static int ezgetc (lua_State* L, ZIO* Z) |
@@ -48,9 +47,9 @@ static void LoadBlock (lua_State* L, void* b, size_t size, ZIO* Z, int swap) | |||
48 | { | 47 | { |
49 | if (swap) | 48 | if (swap) |
50 | { | 49 | { |
51 | l_char *p=(l_char*) b+size-1; | 50 | char *p=(char*) b+size-1; |
52 | int n=size; | 51 | int n=size; |
53 | while (n--) *p--=(l_char)ezgetc(L,Z); | 52 | while (n--) *p--=(char)ezgetc(L,Z); |
54 | } | 53 | } |
55 | else | 54 | else |
56 | ezread(L,Z,b,size); | 55 | ezread(L,Z,b,size); |
@@ -60,12 +59,12 @@ static void LoadVector (lua_State* L, void* b, int m, size_t size, ZIO* Z, int s | |||
60 | { | 59 | { |
61 | if (swap) | 60 | if (swap) |
62 | { | 61 | { |
63 | l_char *q=(l_char*) b; | 62 | char *q=(char*) b; |
64 | while (m--) | 63 | while (m--) |
65 | { | 64 | { |
66 | l_char *p=q+size-1; | 65 | char *p=q+size-1; |
67 | int n=size; | 66 | int n=size; |
68 | while (n--) *p--=(l_char)ezgetc(L,Z); | 67 | while (n--) *p--=(char)ezgetc(L,Z); |
69 | q+=size; | 68 | q+=size; |
70 | } | 69 | } |
71 | } | 70 | } |
@@ -101,7 +100,7 @@ static TString* LoadString (lua_State* L, ZIO* Z, int swap) | |||
101 | return NULL; | 100 | return NULL; |
102 | else | 101 | else |
103 | { | 102 | { |
104 | l_char* s=luaO_openspace(L,size,l_char); | 103 | char* s=luaO_openspace(L,size,char); |
105 | LoadBlock(L,s,size,Z,0); | 104 | LoadBlock(L,s,size,Z,0); |
106 | return luaS_newlstr(L,s,size-1); /* remove trailing '\0' */ | 105 | return luaS_newlstr(L,s,size-1); /* remove trailing '\0' */ |
107 | } | 106 | } |
@@ -159,7 +158,7 @@ static void LoadConstants (lua_State* L, Proto* f, ZIO* Z, int swap) | |||
159 | tsvalue(o)=LoadString(L,Z,swap); | 158 | tsvalue(o)=LoadString(L,Z,swap); |
160 | break; | 159 | break; |
161 | default: | 160 | default: |
162 | luaO_verror(L,l_s("bad constant type (%d) in `%.99s'"),ttype(o),ZNAME(Z)); | 161 | luaO_verror(L,"bad constant type (%d) in `%.99s'",ttype(o),ZNAME(Z)); |
163 | break; | 162 | break; |
164 | } | 163 | } |
165 | } | 164 | } |
@@ -183,25 +182,25 @@ static Proto* LoadFunction (lua_State* L, TString* p, ZIO* Z, int swap) | |||
183 | LoadConstants(L,f,Z,swap); | 182 | LoadConstants(L,f,Z,swap); |
184 | LoadCode(L,f,Z,swap); | 183 | LoadCode(L,f,Z,swap); |
185 | #ifndef TRUST_BINARIES | 184 | #ifndef TRUST_BINARIES |
186 | if (!luaG_checkcode(f)) luaO_verror(L,l_s("bad code in `%.99s'"),ZNAME(Z)); | 185 | if (!luaG_checkcode(f)) luaO_verror(L,"bad code in `%.99s'",ZNAME(Z)); |
187 | #endif | 186 | #endif |
188 | return f; | 187 | return f; |
189 | } | 188 | } |
190 | 189 | ||
191 | static void LoadSignature (lua_State* L, ZIO* Z) | 190 | static void LoadSignature (lua_State* L, ZIO* Z) |
192 | { | 191 | { |
193 | const l_char* s=l_s(LUA_SIGNATURE); | 192 | const char* s=LUA_SIGNATURE; |
194 | while (*s!=0 && ezgetc(L,Z)==*s) | 193 | while (*s!=0 && ezgetc(L,Z)==*s) |
195 | ++s; | 194 | ++s; |
196 | if (*s!=0) luaO_verror(L,l_s("bad signature in `%.99s'"),ZNAME(Z)); | 195 | if (*s!=0) luaO_verror(L,"bad signature in `%.99s'",ZNAME(Z)); |
197 | } | 196 | } |
198 | 197 | ||
199 | static void TestSize (lua_State* L, int s, const l_char* what, ZIO* Z) | 198 | static void TestSize (lua_State* L, int s, const char* what, ZIO* Z) |
200 | { | 199 | { |
201 | int r=LoadByte(L,Z); | 200 | int r=LoadByte(L,Z); |
202 | if (r!=s) | 201 | if (r!=s) |
203 | luaO_verror(L,l_s("virtual machine mismatch in `%.99s':\n") | 202 | luaO_verror(L,"virtual machine mismatch in `%.99s':\n" |
204 | l_s(" size of %.20s is %d but read %d"),ZNAME(Z),what,s,r); | 203 | " size of %.20s is %d but read %d",ZNAME(Z),what,s,r); |
205 | } | 204 | } |
206 | 205 | ||
207 | #define TESTSIZE(s,w) TestSize(L,s,w,Z) | 206 | #define TESTSIZE(s,w) TestSize(L,s,w,Z) |
@@ -214,26 +213,26 @@ static int LoadHeader (lua_State* L, ZIO* Z) | |||
214 | LoadSignature(L,Z); | 213 | LoadSignature(L,Z); |
215 | version=LoadByte(L,Z); | 214 | version=LoadByte(L,Z); |
216 | if (version>VERSION) | 215 | if (version>VERSION) |
217 | luaO_verror(L,l_s("`%.99s' too new:\n") | 216 | luaO_verror(L,"`%.99s' too new:\n" |
218 | l_s(" read version %d.%d; expected at most %d.%d"), | 217 | " read version %d.%d; expected at most %d.%d", |
219 | ZNAME(Z),V(version),V(VERSION)); | 218 | ZNAME(Z),V(version),V(VERSION)); |
220 | if (version<VERSION0) /* check last major change */ | 219 | if (version<VERSION0) /* check last major change */ |
221 | luaO_verror(L,l_s("`%.99s' too old:\n") | 220 | luaO_verror(L,"`%.99s' too old:\n" |
222 | l_s(" read version %d.%d; expected at least %d.%d"), | 221 | " read version %d.%d; expected at least %d.%d", |
223 | ZNAME(Z),V(version),V(VERSION)); | 222 | ZNAME(Z),V(version),V(VERSION)); |
224 | swap=(luaU_endianness()!=LoadByte(L,Z)); /* need to swap bytes? */ | 223 | swap=(luaU_endianness()!=LoadByte(L,Z)); /* need to swap bytes? */ |
225 | TESTSIZE(sizeof(int),l_s("int")); | 224 | TESTSIZE(sizeof(int),"int"); |
226 | TESTSIZE(sizeof(size_t), l_s("size_t")); | 225 | TESTSIZE(sizeof(size_t), "size_t"); |
227 | TESTSIZE(sizeof(Instruction), l_s("size_t")); | 226 | TESTSIZE(sizeof(Instruction), "size_t"); |
228 | TESTSIZE(SIZE_OP, l_s("OP")); | 227 | TESTSIZE(SIZE_OP, "OP"); |
229 | TESTSIZE(SIZE_A, l_s("A")); | 228 | TESTSIZE(SIZE_A, "A"); |
230 | TESTSIZE(SIZE_B, l_s("B")); | 229 | TESTSIZE(SIZE_B, "B"); |
231 | TESTSIZE(SIZE_C, l_s("C")); | 230 | TESTSIZE(SIZE_C, "C"); |
232 | TESTSIZE(sizeof(lua_Number), l_s("number")); | 231 | TESTSIZE(sizeof(lua_Number), "number"); |
233 | x=LoadNumber(L,Z,swap); | 232 | x=LoadNumber(L,Z,swap); |
234 | if ((long)x!=(long)tx) /* disregard errors in last bits of fraction */ | 233 | if ((long)x!=(long)tx) /* disregard errors in last bits of fraction */ |
235 | luaO_verror(L,l_s("unknown number format in `%.99s':\n") | 234 | luaO_verror(L,"unknown number format in `%.99s':\n" |
236 | l_s(" read ") l_s(LUA_NUMBER_FMT) l_s("; expected ") l_s(LUA_NUMBER_FMT), | 235 | " read " LUA_NUMBER_FMT "; expected " LUA_NUMBER_FMT, |
237 | ZNAME(Z),x,tx); | 236 | ZNAME(Z),x,tx); |
238 | return swap; | 237 | return swap; |
239 | } | 238 | } |
@@ -250,7 +249,7 @@ Proto* luaU_undump (lua_State* L, ZIO* Z) | |||
250 | { | 249 | { |
251 | Proto* f=LoadChunk(L,Z); | 250 | Proto* f=LoadChunk(L,Z); |
252 | if (zgetc(Z)!=EOZ) | 251 | if (zgetc(Z)!=EOZ) |
253 | luaO_verror(L,l_s("`%.99s' apparently contains more than one chunk"),ZNAME(Z)); | 252 | luaO_verror(L,"`%.99s' apparently contains more than one chunk",ZNAME(Z)); |
254 | return f; | 253 | return f; |
255 | } | 254 | } |
256 | 255 | ||
@@ -260,5 +259,5 @@ Proto* luaU_undump (lua_State* L, ZIO* Z) | |||
260 | int luaU_endianness (void) | 259 | int luaU_endianness (void) |
261 | { | 260 | { |
262 | int x=1; | 261 | int x=1; |
263 | return *(l_char*)&x; | 262 | return *(char*)&x; |
264 | } | 263 | } |