diff options
Diffstat (limited to 'src/lj_meta.c')
-rw-r--r-- | src/lj_meta.c | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/src/lj_meta.c b/src/lj_meta.c index 441d571a..db1ce928 100644 --- a/src/lj_meta.c +++ b/src/lj_meta.c | |||
@@ -12,6 +12,7 @@ | |||
12 | #include "lj_obj.h" | 12 | #include "lj_obj.h" |
13 | #include "lj_gc.h" | 13 | #include "lj_gc.h" |
14 | #include "lj_err.h" | 14 | #include "lj_err.h" |
15 | #include "lj_buf.h" | ||
15 | #include "lj_str.h" | 16 | #include "lj_str.h" |
16 | #include "lj_tab.h" | 17 | #include "lj_tab.h" |
17 | #include "lj_meta.h" | 18 | #include "lj_meta.h" |
@@ -19,6 +20,7 @@ | |||
19 | #include "lj_bc.h" | 20 | #include "lj_bc.h" |
20 | #include "lj_vm.h" | 21 | #include "lj_vm.h" |
21 | #include "lj_strscan.h" | 22 | #include "lj_strscan.h" |
23 | #include "lj_lib.h" | ||
22 | 24 | ||
23 | /* -- Metamethod handling ------------------------------------------------- */ | 25 | /* -- Metamethod handling ------------------------------------------------- */ |
24 | 26 | ||
@@ -282,7 +284,7 @@ TValue *lj_meta_cat(lua_State *L, TValue *top, int left) | |||
282 | ** next step: [...][CAT stack ............] | 284 | ** next step: [...][CAT stack ............] |
283 | */ | 285 | */ |
284 | MSize tlen = strV(top)->len; | 286 | MSize tlen = strV(top)->len; |
285 | char *buffer; | 287 | char *buf; |
286 | int i; | 288 | int i; |
287 | for (n = 1; n <= left && tostring(L, top-n); n++) { | 289 | for (n = 1; n <= left && tostring(L, top-n); n++) { |
288 | MSize len = strV(top-n)->len; | 290 | MSize len = strV(top-n)->len; |
@@ -290,15 +292,15 @@ TValue *lj_meta_cat(lua_State *L, TValue *top, int left) | |||
290 | lj_err_msg(L, LJ_ERR_STROV); | 292 | lj_err_msg(L, LJ_ERR_STROV); |
291 | tlen += len; | 293 | tlen += len; |
292 | } | 294 | } |
293 | buffer = lj_str_needbuf(L, &G(L)->tmpbuf, tlen); | 295 | buf = lj_buf_tmp(L, tlen); |
294 | n--; | 296 | n--; |
295 | tlen = 0; | 297 | tlen = 0; |
296 | for (i = n; i >= 0; i--) { | 298 | for (i = n; i >= 0; i--) { |
297 | MSize len = strV(top-i)->len; | 299 | MSize len = strV(top-i)->len; |
298 | memcpy(buffer + tlen, strVdata(top-i), len); | 300 | memcpy(buf + tlen, strVdata(top-i), len); |
299 | tlen += len; | 301 | tlen += len; |
300 | } | 302 | } |
301 | setstrV(L, top-n, lj_str_new(L, buffer, tlen)); | 303 | setstrV(L, top-n, lj_str_new(L, buf, tlen)); |
302 | } | 304 | } |
303 | left -= n; | 305 | left -= n; |
304 | top -= n; | 306 | top -= n; |
@@ -423,6 +425,18 @@ TValue *lj_meta_comp(lua_State *L, cTValue *o1, cTValue *o2, int op) | |||
423 | } | 425 | } |
424 | } | 426 | } |
425 | 427 | ||
428 | /* Helper for ISTYPE and ISNUM. Implicit coercion or error. */ | ||
429 | void lj_meta_istype(lua_State *L, BCReg ra, BCReg tp) | ||
430 | { | ||
431 | L->top = curr_topL(L); | ||
432 | ra++; tp--; | ||
433 | lua_assert(LJ_DUALNUM || tp != ~LJ_TNUMX); /* ISTYPE -> ISNUM broken. */ | ||
434 | if (LJ_DUALNUM && tp == ~LJ_TNUMX) lj_lib_checkint(L, ra); | ||
435 | else if (tp == ~LJ_TNUMX+1) lj_lib_checknum(L, ra); | ||
436 | else if (tp == ~LJ_TSTR) lj_lib_checkstr(L, ra); | ||
437 | else lj_err_argtype(L, ra, lj_obj_itypename[tp]); | ||
438 | } | ||
439 | |||
426 | /* Helper for calls. __call metamethod. */ | 440 | /* Helper for calls. __call metamethod. */ |
427 | void lj_meta_call(lua_State *L, TValue *func, TValue *top) | 441 | void lj_meta_call(lua_State *L, TValue *func, TValue *top) |
428 | { | 442 | { |