diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2023-08-30 11:26:16 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2023-08-30 11:26:16 -0300 |
commit | f33cda8d6eb1cac5b9042429e85f1096175c7ca5 (patch) | |
tree | fc82b6d637628a489bb68fa8ac6f320334170ace /ldump.c | |
parent | 96f77142374da8a4a7d4e5e8afd559fbaf0430e8 (diff) | |
download | lua-f33cda8d6eb1cac5b9042429e85f1096175c7ca5.tar.gz lua-f33cda8d6eb1cac5b9042429e85f1096175c7ca5.tar.bz2 lua-f33cda8d6eb1cac5b9042429e85f1096175c7ca5.zip |
New macro 'getlstr'
Accesses content and length of a 'TString'.
Diffstat (limited to 'ldump.c')
-rw-r--r-- | ldump.c | 15 |
1 files changed, 8 insertions, 7 deletions
@@ -112,24 +112,25 @@ static void dumpInteger (DumpState *D, lua_Integer x) { | |||
112 | ** size==size-2 and means that string, which will be saved with | 112 | ** size==size-2 and means that string, which will be saved with |
113 | ** the next available index. | 113 | ** the next available index. |
114 | */ | 114 | */ |
115 | static void dumpString (DumpState *D, TString *s) { | 115 | static void dumpString (DumpState *D, TString *ts) { |
116 | if (s == NULL) | 116 | if (ts == NULL) |
117 | dumpSize(D, 0); | 117 | dumpSize(D, 0); |
118 | else { | 118 | else { |
119 | const TValue *idx = luaH_getstr(D->h, s); | 119 | const TValue *idx = luaH_getstr(D->h, ts); |
120 | if (ttisinteger(idx)) { /* string already saved? */ | 120 | if (ttisinteger(idx)) { /* string already saved? */ |
121 | dumpSize(D, 1); /* reuse a saved string */ | 121 | dumpSize(D, 1); /* reuse a saved string */ |
122 | dumpInt(D, ivalue(idx)); /* index of saved string */ | 122 | dumpInt(D, ivalue(idx)); /* index of saved string */ |
123 | } | 123 | } |
124 | else { /* must write and save the string */ | 124 | else { /* must write and save the string */ |
125 | TValue key, value; /* to save the string in the hash */ | 125 | TValue key, value; /* to save the string in the hash */ |
126 | size_t size = tsslen(s); | 126 | size_t size; |
127 | const char *s = getlstr(ts, size); | ||
127 | dumpSize(D, size + 2); | 128 | dumpSize(D, size + 2); |
128 | dumpVector(D, getstr(s), size); | 129 | dumpVector(D, s, size); |
129 | D->nstr++; /* one more saved string */ | 130 | D->nstr++; /* one more saved string */ |
130 | setsvalue(D->L, &key, s); /* the string is the key */ | 131 | setsvalue(D->L, &key, ts); /* the string is the key */ |
131 | setivalue(&value, D->nstr); /* its index is the value */ | 132 | setivalue(&value, D->nstr); /* its index is the value */ |
132 | luaH_finishset(D->L, D->h, &key, idx, &value); /* h[s] = nstr */ | 133 | luaH_finishset(D->L, D->h, &key, idx, &value); /* h[ts] = nstr */ |
133 | /* integer value does not need barrier */ | 134 | /* integer value does not need barrier */ |
134 | } | 135 | } |
135 | } | 136 | } |