aboutsummaryrefslogtreecommitdiff
path: root/src/lib_base.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib_base.c')
-rw-r--r--src/lib_base.c41
1 files changed, 9 insertions, 32 deletions
diff --git a/src/lib_base.c b/src/lib_base.c
index 070970ed..44817187 100644
--- a/src/lib_base.c
+++ b/src/lib_base.c
@@ -32,6 +32,7 @@
32#include "lj_dispatch.h" 32#include "lj_dispatch.h"
33#include "lj_char.h" 33#include "lj_char.h"
34#include "lj_strscan.h" 34#include "lj_strscan.h"
35#include "lj_strfmt.h"
35#include "lj_lib.h" 36#include "lj_lib.h"
36 37
37/* -- Base library: checks ------------------------------------------------ */ 38/* -- Base library: checks ------------------------------------------------ */
@@ -301,9 +302,6 @@ LJLIB_ASM(tonumber) LJLIB_REC(.)
301 return FFH_RES(1); 302 return FFH_RES(1);
302} 303}
303 304
304LJLIB_PUSH("nil")
305LJLIB_PUSH("false")
306LJLIB_PUSH("true")
307LJLIB_ASM(tostring) LJLIB_REC(.) 305LJLIB_ASM(tostring) LJLIB_REC(.)
308{ 306{
309 TValue *o = lj_lib_checkany(L, 1); 307 TValue *o = lj_lib_checkany(L, 1);
@@ -312,23 +310,10 @@ LJLIB_ASM(tostring) LJLIB_REC(.)
312 if (!tvisnil(mo = lj_meta_lookup(L, o, MM_tostring))) { 310 if (!tvisnil(mo = lj_meta_lookup(L, o, MM_tostring))) {
313 copyTV(L, L->base-1, mo); /* Replace callable. */ 311 copyTV(L, L->base-1, mo); /* Replace callable. */
314 return FFH_TAILCALL; 312 return FFH_TAILCALL;
315 } else {
316 GCstr *s;
317 if (tvisnumber(o)) {
318 s = lj_str_fromnumber(L, o);
319 } else if (tvispri(o)) {
320 s = strV(lj_lib_upvalue(L, -(int32_t)itype(o)));
321 } else {
322 if (tvisfunc(o) && isffunc(funcV(o)))
323 lua_pushfstring(L, "function: builtin#%d", funcV(o)->c.ffid);
324 else
325 lua_pushfstring(L, "%s: %p", lj_typename(o), lua_topointer(L, 1));
326 /* Note: lua_pushfstring calls the GC which may invalidate o. */
327 s = strV(L->top-1);
328 }
329 setstrV(L, L->base-1, s);
330 return FFH_RES(1);
331 } 313 }
314 lj_gc_check(L);
315 setstrV(L, L->base-1, lj_strfmt_obj(L, L->base));
316 return FFH_RES(1);
332} 317}
333 318
334/* -- Base library: throw and catch errors -------------------------------- */ 319/* -- Base library: throw and catch errors -------------------------------- */
@@ -506,21 +491,13 @@ LJLIB_CF(print)
506 } 491 }
507 shortcut = (tvisfunc(tv) && funcV(tv)->c.ffid == FF_tostring); 492 shortcut = (tvisfunc(tv) && funcV(tv)->c.ffid == FF_tostring);
508 for (i = 0; i < nargs; i++) { 493 for (i = 0; i < nargs; i++) {
494 cTValue *o = &L->base[i];
495 char buf[STRFMT_MAXBUF_NUM];
509 const char *str; 496 const char *str;
510 size_t size; 497 size_t size;
511 cTValue *o = &L->base[i]; 498 MSize len;
512 if (shortcut && tvisstr(o)) { 499 if (shortcut && (str = lj_strfmt_wstrnum(buf, o, &len)) != NULL) {
513 str = strVdata(o); 500 size = len;
514 size = strV(o)->len;
515 } else if (shortcut && tvisint(o)) {
516 char buf[LJ_STR_INTBUF];
517 char *p = lj_str_bufint(buf, intV(o));
518 size = (size_t)(buf+LJ_STR_INTBUF-p);
519 str = p;
520 } else if (shortcut && tvisnum(o)) {
521 char buf[LJ_STR_NUMBUF];
522 size = lj_str_bufnum(buf, o);
523 str = buf;
524 } else { 501 } else {
525 copyTV(L, L->top+1, o); 502 copyTV(L, L->top+1, o);
526 copyTV(L, L->top, L->top-1); 503 copyTV(L, L->top, L->top-1);