diff options
-rw-r--r-- | src/Makefile.dep | 4 | ||||
-rw-r--r-- | src/lib_table.c | 25 |
2 files changed, 18 insertions, 11 deletions
diff --git a/src/Makefile.dep b/src/Makefile.dep index 902d2912..484553c4 100644 --- a/src/Makefile.dep +++ b/src/Makefile.dep | |||
@@ -36,8 +36,8 @@ lib_string.o: lib_string.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h \ | |||
36 | lj_tab.h lj_meta.h lj_state.h lj_ff.h lj_ffdef.h lj_bcdump.h lj_lex.h \ | 36 | lj_tab.h lj_meta.h lj_state.h lj_ff.h lj_ffdef.h lj_bcdump.h lj_lex.h \ |
37 | lj_char.h lj_lib.h lj_libdef.h | 37 | lj_char.h lj_lib.h lj_libdef.h |
38 | lib_table.o: lib_table.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h \ | 38 | lib_table.o: lib_table.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h \ |
39 | lj_def.h lj_arch.h lj_gc.h lj_err.h lj_errmsg.h lj_tab.h lj_lib.h \ | 39 | lj_def.h lj_arch.h lj_gc.h lj_err.h lj_errmsg.h lj_buf.h lj_str.h \ |
40 | lj_libdef.h | 40 | lj_tab.h lj_lib.h lj_libdef.h |
41 | lj_alloc.o: lj_alloc.c lj_def.h lua.h luaconf.h lj_arch.h lj_alloc.h | 41 | lj_alloc.o: lj_alloc.c lj_def.h lua.h luaconf.h lj_arch.h lj_alloc.h |
42 | lj_api.o: lj_api.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \ | 42 | lj_api.o: lj_api.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \ |
43 | lj_err.h lj_errmsg.h lj_debug.h lj_str.h lj_tab.h lj_func.h lj_udata.h \ | 43 | lj_err.h lj_errmsg.h lj_debug.h lj_str.h lj_tab.h lj_func.h lj_udata.h \ |
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 | ||
130 | LJLIB_CF(table_concat) | 132 | LJLIB_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 | ||