diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2007-02-07 15:51:21 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2007-02-07 15:51:21 -0200 |
commit | cf86576a838dbe7a11f64116bdc9b1942d233ff8 (patch) | |
tree | efa331ab508dd45e2c8b3365a6e1728f91256cc6 /lbaselib.c | |
parent | 92dc64e1216ad9559827bdcce7bb9b0cf5d7c0ef (diff) | |
download | lua-cf86576a838dbe7a11f64116bdc9b1942d233ff8.tar.gz lua-cf86576a838dbe7a11f64116bdc9b1942d233ff8.tar.bz2 lua-cf86576a838dbe7a11f64116bdc9b1942d233ff8.zip |
new function luaL_tostring
Diffstat (limited to 'lbaselib.c')
-rw-r--r-- | lbaselib.c | 22 |
1 files changed, 2 insertions, 20 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lbaselib.c,v 1.194 2006/10/20 19:30:53 roberto Exp roberto $ | 2 | ** $Id: lbaselib.c,v 1.195 2006/10/24 19:46:12 roberto Exp roberto $ |
3 | ** Basic library | 3 | ** Basic library |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -396,25 +396,7 @@ static int luaB_xpcall (lua_State *L) { | |||
396 | 396 | ||
397 | static int luaB_tostring (lua_State *L) { | 397 | static int luaB_tostring (lua_State *L) { |
398 | luaL_checkany(L, 1); | 398 | luaL_checkany(L, 1); |
399 | if (luaL_callmeta(L, 1, "__tostring")) /* is there a metafield? */ | 399 | luaL_tostring(L, 1); |
400 | return 1; /* use its value */ | ||
401 | switch (lua_type(L, 1)) { | ||
402 | case LUA_TNUMBER: | ||
403 | lua_pushstring(L, lua_tostring(L, 1)); | ||
404 | break; | ||
405 | case LUA_TSTRING: | ||
406 | lua_pushvalue(L, 1); | ||
407 | break; | ||
408 | case LUA_TBOOLEAN: | ||
409 | lua_pushstring(L, (lua_toboolean(L, 1) ? "true" : "false")); | ||
410 | break; | ||
411 | case LUA_TNIL: | ||
412 | lua_pushliteral(L, "nil"); | ||
413 | break; | ||
414 | default: | ||
415 | lua_pushfstring(L, "%s: %p", luaL_typename(L, 1), lua_topointer(L, 1)); | ||
416 | break; | ||
417 | } | ||
418 | return 1; | 400 | return 1; |
419 | } | 401 | } |
420 | 402 | ||