summaryrefslogtreecommitdiff
path: root/src/lib_base.c
diff options
context:
space:
mode:
authorMike Pall <mike>2010-06-16 19:43:07 +0200
committerMike Pall <mike>2010-06-16 19:43:07 +0200
commitcdc37a33b3b86f436359a6109a19773a31bafe4f (patch)
treed5f4824938ac076d0a1012d882625b81af6800da /src/lib_base.c
parentfa673eb179ed21b0f7a4951d3f498541c1d39622 (diff)
downloadluajit2-cdc37a33b3b86f436359a6109a19773a31bafe4f.tar.gz
Fallback to metamethod resolving for tostring in print().
Diffstat (limited to 'src/lib_base.c')
-rw-r--r--src/lib_base.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/lib_base.c b/src/lib_base.c
index 1f677b50..c8ac5f86 100644
--- a/src/lib_base.c
+++ b/src/lib_base.c
@@ -402,8 +402,15 @@ LJLIB_CF(print)
{
ptrdiff_t i, nargs = L->top - L->base;
cTValue *tv = lj_tab_getstr(tabref(L->env), strV(lj_lib_upvalue(L, 1)));
- int shortcut = (tv && tvisfunc(tv) && funcV(tv)->c.ffid == FF_tostring);
- copyTV(L, L->top++, tv ? tv : niltv(L));
+ int shortcut;
+ if (tv && !tvisnil(tv)) {
+ copyTV(L, L->top++, tv);
+ } else {
+ setstrV(L, L->top++, strV(lj_lib_upvalue(L, 1)));
+ lua_gettable(L, LUA_GLOBALSINDEX);
+ tv = L->top-1;
+ }
+ shortcut = (tvisfunc(tv) && funcV(tv)->c.ffid == FF_tostring);
for (i = 0; i < nargs; i++) {
const char *str;
size_t size;