aboutsummaryrefslogtreecommitdiff
path: root/c-api
diff options
context:
space:
mode:
authorPhilipp Janda <siffiejoe@gmx.net>2017-08-08 08:45:17 +0200
committerPhilipp Janda <siffiejoe@gmx.net>2017-08-08 08:45:17 +0200
commitb1abaff6353be16009b1bf4ff2f91174632f0819 (patch)
treed44d85a0b0a3eb1b512f1a6a57292ca4bbba139a /c-api
parentf608371c71644f5db60a3c83b2c7a44f1eb30eea (diff)
downloadlua-compat-5.3-b1abaff6353be16009b1bf4ff2f91174632f0819.tar.gz
lua-compat-5.3-b1abaff6353be16009b1bf4ff2f91174632f0819.tar.bz2
lua-compat-5.3-b1abaff6353be16009b1bf4ff2f91174632f0819.zip
Update behavior of luaL_tolstring().
Diffstat (limited to 'c-api')
-rw-r--r--c-api/compat-5.3.c13
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
239COMPAT53_API const char *luaL_tolstring (lua_State *L, int idx, size_t *len) { 239COMPAT53_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}