summaryrefslogtreecommitdiff
path: root/src/lib_base.c
diff options
context:
space:
mode:
authorMike Pall <mike>2013-05-13 00:34:15 +0200
committerMike Pall <mike>2013-05-13 01:23:33 +0200
commit625ffca739a703906fbc321ef9405514d72480fe (patch)
treeca279d81071e8aa749797e0867e168c9db5c2bbe /src/lib_base.c
parent19a9206caf1df71308bd8e4bd61c082026c6811c (diff)
downloadluajit-625ffca739a703906fbc321ef9405514d72480fe.tar.gz
luajit-625ffca739a703906fbc321ef9405514d72480fe.tar.bz2
luajit-625ffca739a703906fbc321ef9405514d72480fe.zip
Refactor raw object to pointer or string conversions.
Diffstat (limited to 'src/lib_base.c')
-rw-r--r--src/lib_base.c23
1 files changed, 4 insertions, 19 deletions
diff --git a/src/lib_base.c b/src/lib_base.c
index 8fecddea..84bf1ef2 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 -------------------------------- */