summaryrefslogtreecommitdiff
path: root/ltm.c
diff options
context:
space:
mode:
Diffstat (limited to 'ltm.c')
-rw-r--r--ltm.c18
1 files changed, 17 insertions, 1 deletions
diff --git a/ltm.c b/ltm.c
index 3f400d4b..cc28a414 100644
--- a/ltm.c
+++ b/ltm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltm.c,v 2.35 2015/11/02 18:48:07 roberto Exp roberto $ 2** $Id: ltm.c,v 2.36 2015/11/03 15:47:30 roberto Exp roberto $
3** Tag methods 3** Tag methods
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -83,6 +83,22 @@ const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, TMS event) {
83} 83}
84 84
85 85
86/*
87** Return the name of the type of an object. For tables and userdata
88** with metatable, use their '__name' metafield, if present.
89*/
90const char *luaT_objtypename (lua_State *L, const TValue *o) {
91 Table *mt;
92 if ((ttistable(o) && (mt = hvalue(o)->metatable) != NULL) ||
93 (ttisfulluserdata(o) && (mt = uvalue(o)->metatable) != NULL)) {
94 const TValue *name = luaH_getshortstr(mt, luaS_new(L, "__name"));
95 if (ttisstring(name)) /* is '__name' a string? */
96 return getstr(tsvalue(name)); /* use it as type name */
97 }
98 return ttypename(ttnov(o)); /* else use standard type name */
99}
100
101
86void luaT_callTM (lua_State *L, const TValue *f, const TValue *p1, 102void luaT_callTM (lua_State *L, const TValue *f, const TValue *p1,
87 const TValue *p2, TValue *p3, int hasres) { 103 const TValue *p2, TValue *p3, int hasres) {
88 ptrdiff_t result = savestack(L, p3); 104 ptrdiff_t result = savestack(L, p3);