Taken (with slightly adapted formatting) from Lua 5.2.3: ** $Id: lauxlib.c,v 1.248.1.1 2013/04/12 18:48:47 roberto Exp $ ** Auxiliary functions for building Lua libraries * Copyright (C) 1994-2013 Lua.org, PUC-Rio. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software withou
| 33 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 34 | */ |
| 35 | LUABIND_API char const* luaL_tolstring (lua_State* L, int idx, size_t* len) |
| 36 | { |
| 37 | if (!luaL_callmeta(L, idx, "__tostring")) { /* no metafield? */ |
| 38 | switch (lua_type(L, idx)) { |
| 39 | case LUA_TNUMBER: |
| 40 | case LUA_TSTRING: |
| 41 | lua_pushvalue(L, idx); |
| 42 | break; |
| 43 | case LUA_TBOOLEAN: |
| 44 | lua_pushstring(L, (lua_toboolean(L, idx) ? "true" : "false")); |
| 45 | break; |
| 46 | case LUA_TNIL: |
| 47 | lua_pushliteral(L, "nil"); |
| 48 | break; |
| 49 | default: |
| 50 | lua_pushfstring(L, "%s: %p", luaL_typename(L, idx), |
| 51 | lua_topointer(L, idx)); |
| 52 | break; |
| 53 | } |
| 54 | } |
| 55 | return lua_tolstring(L, -1, len); |
| 56 | } |
| 57 | |
| 58 | #endif // LUA_VERSION_NUM < 502 |
no test coverage detected