aboutsummaryrefslogtreecommitdiff
path: root/src/lib_table.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib_table.c')
-rw-r--r--src/lib_table.c25
1 files changed, 16 insertions, 9 deletions
diff --git a/src/lib_table.c b/src/lib_table.c
index 89884f77..5619f9ad 100644
--- a/src/lib_table.c
+++ b/src/lib_table.c
@@ -16,6 +16,8 @@
16#include "lj_obj.h" 16#include "lj_obj.h"
17#include "lj_gc.h" 17#include "lj_gc.h"
18#include "lj_err.h" 18#include "lj_err.h"
19#include "lj_buf.h"
20#include "lj_str.h"
19#include "lj_tab.h" 21#include "lj_tab.h"
20#include "lj_lib.h" 22#include "lj_lib.h"
21 23
@@ -129,28 +131,33 @@ LJLIB_LUA(table_remove) /*
129 131
130LJLIB_CF(table_concat) 132LJLIB_CF(table_concat)
131{ 133{
132 luaL_Buffer b;
133 GCtab *t = lj_lib_checktab(L, 1); 134 GCtab *t = lj_lib_checktab(L, 1);
134 GCstr *sep = lj_lib_optstr(L, 2); 135 GCstr *sep = lj_lib_optstr(L, 2);
135 MSize seplen = sep ? sep->len : 0; 136 MSize seplen = sep ? sep->len : 0;
136 int32_t i = lj_lib_optint(L, 3, 1); 137 int32_t i = lj_lib_optint(L, 3, 1);
137 int32_t e = L->base+3 < L->top ? lj_lib_checkint(L, 4) : 138 int32_t e = L->base+3 < L->top ? lj_lib_checkint(L, 4) :
138 (int32_t)lj_tab_len(t); 139 (int32_t)lj_tab_len(t);
139 luaL_buffinit(L, &b);
140 if (i <= e) { 140 if (i <= e) {
141 char buf[LJ_STR_NUMBERBUF];
142 SBuf *sb = &G(L)->tmpbuf;
143 setsbufL(sb, L);
144 lj_buf_reset(sb);
141 for (;;) { 145 for (;;) {
142 cTValue *o; 146 cTValue *o = lj_tab_getint(t, i);
143 lua_rawgeti(L, 1, i); 147 MSize len;
144 o = L->top-1; 148 const char *p = lj_str_buftv(buf, o, &len);
145 if (!(tvisstr(o) || tvisnumber(o))) 149 if (!p)
146 lj_err_callerv(L, LJ_ERR_TABCAT, lj_typename(o), i); 150 lj_err_callerv(L, LJ_ERR_TABCAT, lj_typename(o), i);
147 luaL_addvalue(&b); 151 lj_buf_putmem(sb, p, len);
148 if (i++ == e) break; 152 if (i++ == e) break;
149 if (seplen) 153 if (seplen)
150 luaL_addlstring(&b, strdata(sep), seplen); 154 lj_buf_putmem(sb, strdata(sep), seplen);
151 } 155 }
156 setstrV(L, L->top-1, lj_buf_str(L, sb));
157 lj_gc_check(L);
158 } else {
159 setstrV(L, L->top-1, &G(L)->strempty);
152 } 160 }
153 luaL_pushresult(&b);
154 return 1; 161 return 1;
155} 162}
156 163