diff options
Diffstat (limited to '')
| -rw-r--r-- | ldebug.c | 10 | ||||
| -rw-r--r-- | ltm.c | 18 | ||||
| -rw-r--r-- | ltm.h | 5 |
3 files changed, 25 insertions, 8 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldebug.c,v 2.117 2015/11/02 18:48:07 roberto Exp roberto $ | 2 | ** $Id: ldebug.c,v 2.118 2015/12/16 16:40:07 roberto Exp roberto $ |
| 3 | ** Debug Interface | 3 | ** Debug Interface |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -564,7 +564,7 @@ static const char *varinfo (lua_State *L, const TValue *o) { | |||
| 564 | 564 | ||
| 565 | 565 | ||
| 566 | l_noret luaG_typeerror (lua_State *L, const TValue *o, const char *op) { | 566 | l_noret luaG_typeerror (lua_State *L, const TValue *o, const char *op) { |
| 567 | const char *t = objtypename(o); | 567 | const char *t = luaT_objtypename(L, o); |
| 568 | luaG_runerror(L, "attempt to %s a %s value%s", op, t, varinfo(L, o)); | 568 | luaG_runerror(L, "attempt to %s a %s value%s", op, t, varinfo(L, o)); |
| 569 | } | 569 | } |
| 570 | 570 | ||
| @@ -596,9 +596,9 @@ l_noret luaG_tointerror (lua_State *L, const TValue *p1, const TValue *p2) { | |||
| 596 | 596 | ||
| 597 | 597 | ||
| 598 | l_noret luaG_ordererror (lua_State *L, const TValue *p1, const TValue *p2) { | 598 | l_noret luaG_ordererror (lua_State *L, const TValue *p1, const TValue *p2) { |
| 599 | const char *t1 = objtypename(p1); | 599 | const char *t1 = luaT_objtypename(L, p1); |
| 600 | const char *t2 = objtypename(p2); | 600 | const char *t2 = luaT_objtypename(L, p2); |
| 601 | if (t1 == t2) | 601 | if (strcmp(t1, t2) == 0) |
| 602 | luaG_runerror(L, "attempt to compare two %s values", t1); | 602 | luaG_runerror(L, "attempt to compare two %s values", t1); |
| 603 | else | 603 | else |
| 604 | luaG_runerror(L, "attempt to compare %s with %s", t1, t2); | 604 | luaG_runerror(L, "attempt to compare %s with %s", t1, t2); |
| @@ -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 | */ | ||
| 90 | const 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 | |||
| 86 | void luaT_callTM (lua_State *L, const TValue *f, const TValue *p1, | 102 | void 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); |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltm.h,v 2.20 2014/06/10 18:53:18 roberto Exp roberto $ | 2 | ** $Id: ltm.h,v 2.21 2014/10/25 11:50:46 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 | */ |
| @@ -51,11 +51,12 @@ typedef enum { | |||
| 51 | #define fasttm(l,et,e) gfasttm(G(l), et, e) | 51 | #define fasttm(l,et,e) gfasttm(G(l), et, e) |
| 52 | 52 | ||
| 53 | #define ttypename(x) luaT_typenames_[(x) + 1] | 53 | #define ttypename(x) luaT_typenames_[(x) + 1] |
| 54 | #define objtypename(x) ttypename(ttnov(x)) | ||
| 55 | 54 | ||
| 56 | LUAI_DDEC const char *const luaT_typenames_[LUA_TOTALTAGS]; | 55 | LUAI_DDEC const char *const luaT_typenames_[LUA_TOTALTAGS]; |
| 57 | 56 | ||
| 58 | 57 | ||
| 58 | LUAI_FUNC const char *luaT_objtypename (lua_State *L, const TValue *o); | ||
| 59 | |||
| 59 | LUAI_FUNC const TValue *luaT_gettm (Table *events, TMS event, TString *ename); | 60 | LUAI_FUNC const TValue *luaT_gettm (Table *events, TMS event, TString *ename); |
| 60 | LUAI_FUNC const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, | 61 | LUAI_FUNC const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, |
| 61 | TMS event); | 62 | TMS event); |
