diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2017-06-27 11:21:12 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2017-06-27 11:21:12 -0300 |
commit | 124bfd20817d4624d2b69a4dc41182485912b821 (patch) | |
tree | 313f1bfaa63f108b900ed620fb1d4f4e83036c0f /lundump.c | |
parent | b42430fd3a6200eaaf4020be90c4d47f7e251b67 (diff) | |
download | lua-124bfd20817d4624d2b69a4dc41182485912b821.tar.gz lua-124bfd20817d4624d2b69a4dc41182485912b821.tar.bz2 lua-124bfd20817d4624d2b69a4dc41182485912b821.zip |
dumping ints and size_ts compacted
Diffstat (limited to 'lundump.c')
-rw-r--r-- | lundump.c | 26 |
1 files changed, 17 insertions, 9 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lundump.c,v 2.44 2015/11/02 16:09:30 roberto Exp roberto $ | 2 | ** $Id: lundump.c,v 2.45 2017/06/27 11:35:31 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 | */ |
@@ -58,16 +58,26 @@ static void LoadBlock (LoadState *S, void *b, size_t size) { | |||
58 | 58 | ||
59 | 59 | ||
60 | static lu_byte LoadByte (LoadState *S) { | 60 | static lu_byte LoadByte (LoadState *S) { |
61 | lu_byte x; | 61 | int b = zgetc(S->Z); |
62 | LoadVar(S, x); | 62 | if (b == EOZ) |
63 | error(S, "truncated"); | ||
64 | return cast_byte(b); | ||
65 | } | ||
66 | |||
67 | |||
68 | static size_t LoadSize (LoadState *S) { | ||
69 | size_t x = 0; | ||
70 | int b; | ||
71 | do { | ||
72 | b = LoadByte(S); | ||
73 | x = (x << 7) | (b & 0x7f); | ||
74 | } while ((b & 0x80) == 0); | ||
63 | return x; | 75 | return x; |
64 | } | 76 | } |
65 | 77 | ||
66 | 78 | ||
67 | static int LoadInt (LoadState *S) { | 79 | static int LoadInt (LoadState *S) { |
68 | int x; | 80 | return cast_int(LoadSize(S)); |
69 | LoadVar(S, x); | ||
70 | return x; | ||
71 | } | 81 | } |
72 | 82 | ||
73 | 83 | ||
@@ -86,9 +96,7 @@ static lua_Integer LoadInteger (LoadState *S) { | |||
86 | 96 | ||
87 | 97 | ||
88 | static TString *LoadString (LoadState *S) { | 98 | static TString *LoadString (LoadState *S) { |
89 | size_t size = LoadByte(S); | 99 | size_t size = LoadSize(S); |
90 | if (size == 0xFF) | ||
91 | LoadVar(S, size); | ||
92 | if (size == 0) | 100 | if (size == 0) |
93 | return NULL; | 101 | return NULL; |
94 | else if (--size <= LUAI_MAXSHORTLEN) { /* short string? */ | 102 | else if (--size <= LUAI_MAXSHORTLEN) { /* short string? */ |