diff options
Diffstat (limited to 'src/lib_buffer.c')
-rw-r--r-- | src/lib_buffer.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/lib_buffer.c b/src/lib_buffer.c index ae065759..2e364861 100644 --- a/src/lib_buffer.c +++ b/src/lib_buffer.c | |||
@@ -288,7 +288,7 @@ LJLIB_CF(buffer_new) | |||
288 | { | 288 | { |
289 | MSize sz = 0; | 289 | MSize sz = 0; |
290 | int targ = 1; | 290 | int targ = 1; |
291 | GCtab *env, *dict = NULL; | 291 | GCtab *env, *dict_str = NULL, *dict_mt = NULL; |
292 | GCudata *ud; | 292 | GCudata *ud; |
293 | SBufExt *sbx; | 293 | SBufExt *sbx; |
294 | if (L->base < L->top && !tvistab(L->base)) { | 294 | if (L->base < L->top && !tvistab(L->base)) { |
@@ -298,10 +298,16 @@ LJLIB_CF(buffer_new) | |||
298 | } | 298 | } |
299 | if (L->base+targ-1 < L->top) { | 299 | if (L->base+targ-1 < L->top) { |
300 | GCtab *options = lj_lib_checktab(L, targ); | 300 | GCtab *options = lj_lib_checktab(L, targ); |
301 | cTValue *opt_dict = lj_tab_getstr(options, lj_str_newlit(L, "dict")); | 301 | cTValue *opt_dict, *opt_mt; |
302 | opt_dict = lj_tab_getstr(options, lj_str_newlit(L, "dict")); | ||
302 | if (opt_dict && tvistab(opt_dict)) { | 303 | if (opt_dict && tvistab(opt_dict)) { |
303 | dict = tabV(opt_dict); | 304 | dict_str = tabV(opt_dict); |
304 | lj_serialize_dict_prep(L, dict); | 305 | lj_serialize_dict_prep_str(L, dict_str); |
306 | } | ||
307 | opt_mt = lj_tab_getstr(options, lj_str_newlit(L, "metatable")); | ||
308 | if (opt_mt && tvistab(opt_mt)) { | ||
309 | dict_mt = tabV(opt_mt); | ||
310 | lj_serialize_dict_prep_mt(L, dict_mt); | ||
305 | } | 311 | } |
306 | } | 312 | } |
307 | env = tabref(curr_func(L)->c.env); | 313 | env = tabref(curr_func(L)->c.env); |
@@ -312,7 +318,8 @@ LJLIB_CF(buffer_new) | |||
312 | setudataV(L, L->top++, ud); | 318 | setudataV(L, L->top++, ud); |
313 | sbx = (SBufExt *)uddata(ud); | 319 | sbx = (SBufExt *)uddata(ud); |
314 | lj_bufx_init(L, sbx); | 320 | lj_bufx_init(L, sbx); |
315 | setgcref(sbx->dict, obj2gco(dict)); | 321 | setgcref(sbx->dict_str, obj2gco(dict_str)); |
322 | setgcref(sbx->dict_mt, obj2gco(dict_mt)); | ||
316 | if (sz > 0) lj_buf_need2((SBuf *)sbx, sz); | 323 | if (sz > 0) lj_buf_need2((SBuf *)sbx, sz); |
317 | return 1; | 324 | return 1; |
318 | } | 325 | } |