diff options
Diffstat (limited to 'lundump.c')
-rw-r--r-- | lundump.c | 20 |
1 files changed, 11 insertions, 9 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lundump.c,v 2.40 2014/06/19 18:27:20 roberto Exp roberto $ | 2 | ** $Id: lundump.c,v 2.41 2014/11/02 19:19:04 roberto Exp roberto $ |
3 | ** load precompiled Lua chunks | 3 | ** load precompiled Lua chunks |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -32,7 +32,6 @@ | |||
32 | typedef struct { | 32 | typedef struct { |
33 | lua_State *L; | 33 | lua_State *L; |
34 | ZIO *Z; | 34 | ZIO *Z; |
35 | Mbuffer *b; | ||
36 | const char *name; | 35 | const char *name; |
37 | } LoadState; | 36 | } LoadState; |
38 | 37 | ||
@@ -92,10 +91,15 @@ static TString *LoadString (LoadState *S) { | |||
92 | LoadVar(S, size); | 91 | LoadVar(S, size); |
93 | if (size == 0) | 92 | if (size == 0) |
94 | return NULL; | 93 | return NULL; |
95 | else { | 94 | else if (--size <= LUAI_MAXSHORTLEN) { /* short string? */ |
96 | char *s = luaZ_openspace(S->L, S->b, --size); | 95 | char buff[LUAI_MAXSHORTLEN]; |
97 | LoadVector(S, s, size); | 96 | LoadVector(S, buff, size); |
98 | return luaS_newlstr(S->L, s, size); | 97 | return luaS_newlstr(S->L, buff, size); |
98 | } | ||
99 | else { /* long string */ | ||
100 | TString *ts = luaS_createlngstrobj(S->L, size); | ||
101 | LoadVector(S, getaddrstr(ts), size); /* load directly in final place */ | ||
102 | return ts; | ||
99 | } | 103 | } |
100 | } | 104 | } |
101 | 105 | ||
@@ -251,8 +255,7 @@ static void checkHeader (LoadState *S) { | |||
251 | /* | 255 | /* |
252 | ** load precompiled chunk | 256 | ** load precompiled chunk |
253 | */ | 257 | */ |
254 | LClosure *luaU_undump(lua_State *L, ZIO *Z, Mbuffer *buff, | 258 | LClosure *luaU_undump(lua_State *L, ZIO *Z, const char *name) { |
255 | const char *name) { | ||
256 | LoadState S; | 259 | LoadState S; |
257 | LClosure *cl; | 260 | LClosure *cl; |
258 | if (*name == '@' || *name == '=') | 261 | if (*name == '@' || *name == '=') |
@@ -263,7 +266,6 @@ LClosure *luaU_undump(lua_State *L, ZIO *Z, Mbuffer *buff, | |||
263 | S.name = name; | 266 | S.name = name; |
264 | S.L = L; | 267 | S.L = L; |
265 | S.Z = Z; | 268 | S.Z = Z; |
266 | S.b = buff; | ||
267 | checkHeader(&S); | 269 | checkHeader(&S); |
268 | cl = luaF_newLclosure(L, LoadByte(&S)); | 270 | cl = luaF_newLclosure(L, LoadByte(&S)); |
269 | setclLvalue(L, L->top, cl); | 271 | setclLvalue(L, L->top, cl); |