diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2008-01-03 15:07:59 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2008-01-03 15:07:59 -0200 |
| commit | daddc57abd31e30215922a716cb6d26422f3658b (patch) | |
| tree | 9b1a5d628c40d5551595d9349e09e7aba56a88fc /lauxlib.c | |
| parent | f9cdd09191e01ef38da674ef66af408d7e309d9f (diff) | |
| download | lua-daddc57abd31e30215922a716cb6d26422f3658b.tar.gz lua-daddc57abd31e30215922a716cb6d26422f3658b.tar.bz2 lua-daddc57abd31e30215922a716cb6d26422f3658b.zip | |
luaL_tostring -> luaL_tolstring (more generic)
Diffstat (limited to 'lauxlib.c')
| -rw-r--r-- | lauxlib.c | 17 |
1 files changed, 11 insertions, 6 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lauxlib.c,v 1.173 2007/09/05 17:17:39 roberto Exp roberto $ | 2 | ** $Id: lauxlib.c,v 1.174 2007/09/14 13:26:28 roberto Exp roberto $ |
| 3 | ** Auxiliary functions for building Lua libraries | 3 | ** Auxiliary functions for building Lua libraries |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -550,23 +550,28 @@ LUALIB_API int luaL_callmeta (lua_State *L, int obj, const char *event) { | |||
| 550 | } | 550 | } |
| 551 | 551 | ||
| 552 | 552 | ||
| 553 | LUALIB_API const char *luaL_tostring (lua_State *L, int idx) { | 553 | LUALIB_API const char *luaL_tolstring (lua_State *L, int idx, size_t *len) { |
| 554 | if (!luaL_callmeta(L, idx, "__tostring")) { /* no metafield? */ | 554 | if (!luaL_callmeta(L, idx, "__tostring")) { /* no metafield? */ |
| 555 | switch (lua_type(L, idx)) { | 555 | switch (lua_type(L, idx)) { |
| 556 | case LUA_TNUMBER: | 556 | case LUA_TNUMBER: |
| 557 | return lua_pushstring(L, lua_tostring(L, idx)); | 557 | lua_pushstring(L, lua_tostring(L, idx)); |
| 558 | break; | ||
| 558 | case LUA_TSTRING: | 559 | case LUA_TSTRING: |
| 559 | lua_pushvalue(L, idx); | 560 | lua_pushvalue(L, idx); |
| 560 | break; | 561 | break; |
| 561 | case LUA_TBOOLEAN: | 562 | case LUA_TBOOLEAN: |
| 562 | return lua_pushstring(L, (lua_toboolean(L, idx) ? "true" : "false")); | 563 | lua_pushstring(L, (lua_toboolean(L, idx) ? "true" : "false")); |
| 564 | break; | ||
| 563 | case LUA_TNIL: | 565 | case LUA_TNIL: |
| 564 | return lua_pushliteral(L, "nil"); | 566 | lua_pushliteral(L, "nil"); |
| 567 | break; | ||
| 565 | default: | 568 | default: |
| 566 | return lua_pushfstring(L, "%s: %p", luaL_typename(L, idx), | 569 | lua_pushfstring(L, "%s: %p", luaL_typename(L, idx), |
| 567 | lua_topointer(L, idx)); | 570 | lua_topointer(L, idx)); |
| 571 | break; | ||
| 568 | } | 572 | } |
| 569 | } | 573 | } |
| 574 | if (len) *len = lua_objlen(L, -1); | ||
| 570 | return lua_tostring(L, -1); | 575 | return lua_tostring(L, -1); |
| 571 | } | 576 | } |
| 572 | 577 | ||
