diff options
Diffstat (limited to 'c-api/compat-5.3.c')
-rw-r--r-- | c-api/compat-5.3.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/c-api/compat-5.3.c b/c-api/compat-5.3.c index b913196..1e985f9 100644 --- a/c-api/compat-5.3.c +++ b/c-api/compat-5.3.c | |||
@@ -238,7 +238,8 @@ COMPAT53_API void *luaL_testudata (lua_State *L, int i, const char *tname) { | |||
238 | 238 | ||
239 | COMPAT53_API const char *luaL_tolstring (lua_State *L, int idx, size_t *len) { | 239 | COMPAT53_API const char *luaL_tolstring (lua_State *L, int idx, size_t *len) { |
240 | if (!luaL_callmeta(L, idx, "__tostring")) { | 240 | if (!luaL_callmeta(L, idx, "__tostring")) { |
241 | int t = lua_type(L, idx); | 241 | int t = lua_type(L, idx), tt = 0; |
242 | char const* name = NULL; | ||
242 | switch (t) { | 243 | switch (t) { |
243 | case LUA_TNIL: | 244 | case LUA_TNIL: |
244 | lua_pushliteral(L, "nil"); | 245 | lua_pushliteral(L, "nil"); |
@@ -254,10 +255,16 @@ COMPAT53_API const char *luaL_tolstring (lua_State *L, int idx, size_t *len) { | |||
254 | lua_pushliteral(L, "false"); | 255 | lua_pushliteral(L, "false"); |
255 | break; | 256 | break; |
256 | default: | 257 | default: |
257 | lua_pushfstring(L, "%s: %p", lua_typename(L, t), | 258 | tt = luaL_getmetafield(L, idx, "__name"); |
258 | lua_topointer(L, idx)); | 259 | name = (tt == LUA_TSTRING) ? lua_tostring(L, -1) : lua_typename(L, t); |
260 | lua_pushfstring(L, "%s: %p", name, lua_topointer(L, idx)); | ||
261 | if (tt != LUA_TNIL) | ||
262 | lua_replace(L, -2); | ||
259 | break; | 263 | break; |
260 | } | 264 | } |
265 | } else { | ||
266 | if (!lua_isstring(L, -1)) | ||
267 | luaL_error(L, "'__tostring' must return a string"); | ||
261 | } | 268 | } |
262 | return lua_tolstring(L, -1, len); | 269 | return lua_tolstring(L, -1, len); |
263 | } | 270 | } |