diff options
Diffstat (limited to 'src/lj_buf.c')
-rw-r--r-- | src/lj_buf.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/lj_buf.c b/src/lj_buf.c index 55a885a9..c60cc51f 100644 --- a/src/lj_buf.c +++ b/src/lj_buf.c | |||
@@ -13,6 +13,7 @@ | |||
13 | #include "lj_err.h" | 13 | #include "lj_err.h" |
14 | #include "lj_buf.h" | 14 | #include "lj_buf.h" |
15 | #include "lj_str.h" | 15 | #include "lj_str.h" |
16 | #include "lj_tab.h" | ||
16 | 17 | ||
17 | LJ_NOINLINE void LJ_FASTCALL lj_buf_grow(SBuf *sb, char *en) | 18 | LJ_NOINLINE void LJ_FASTCALL lj_buf_grow(SBuf *sb, char *en) |
18 | { | 19 | { |
@@ -168,6 +169,38 @@ SBuf *lj_buf_putstr_rep(SBuf *sb, GCstr *s, int32_t rep) | |||
168 | return sb; | 169 | return sb; |
169 | } | 170 | } |
170 | 171 | ||
172 | SBuf *lj_buf_puttab(SBuf *sb, GCtab *t, GCstr *sep, int32_t i, int32_t e) | ||
173 | { | ||
174 | MSize seplen = sep ? sep->len : 0; | ||
175 | if (i <= e) { | ||
176 | for (;;) { | ||
177 | cTValue *o = lj_tab_getint(t, i); | ||
178 | char *p; | ||
179 | if (!o) { | ||
180 | badtype: /* Error: bad element type. */ | ||
181 | setsbufP(sb, (intptr_t)i); /* Store failing index. */ | ||
182 | return NULL; | ||
183 | } else if (tvisstr(o)) { | ||
184 | MSize len = strV(o)->len; | ||
185 | p = lj_buf_wmem(lj_buf_more(sb, len + seplen), strVdata(o), len); | ||
186 | } else if (tvisint(o)) { | ||
187 | p = lj_str_bufint(lj_buf_more(sb, LJ_STR_INTBUF + seplen), intV(o)); | ||
188 | } else if (tvisnum(o)) { | ||
189 | p = lj_str_bufnum(lj_buf_more(sb, LJ_STR_NUMBUF + seplen), o); | ||
190 | } else { | ||
191 | goto badtype; | ||
192 | } | ||
193 | if (i++ == e) { | ||
194 | setsbufP(sb, p); | ||
195 | break; | ||
196 | } | ||
197 | if (seplen) p = lj_buf_wmem(p, strdata(sep), seplen); | ||
198 | setsbufP(sb, p); | ||
199 | } | ||
200 | } | ||
201 | return sb; | ||
202 | } | ||
203 | |||
171 | GCstr * LJ_FASTCALL lj_buf_tostr(SBuf *sb) | 204 | GCstr * LJ_FASTCALL lj_buf_tostr(SBuf *sb) |
172 | { | 205 | { |
173 | return lj_str_new(sbufL(sb), sbufB(sb), sbuflen(sb)); | 206 | return lj_str_new(sbufL(sb), sbufB(sb), sbuflen(sb)); |