summaryrefslogtreecommitdiff
path: root/lauxlib.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2007-02-07 15:51:21 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2007-02-07 15:51:21 -0200
commitcf86576a838dbe7a11f64116bdc9b1942d233ff8 (patch)
treeefa331ab508dd45e2c8b3365a6e1728f91256cc6 /lauxlib.c
parent92dc64e1216ad9559827bdcce7bb9b0cf5d7c0ef (diff)
downloadlua-cf86576a838dbe7a11f64116bdc9b1942d233ff8.tar.gz
lua-cf86576a838dbe7a11f64116bdc9b1942d233ff8.tar.bz2
lua-cf86576a838dbe7a11f64116bdc9b1942d233ff8.zip
new function luaL_tostring
Diffstat (limited to 'lauxlib.c')
-rw-r--r--lauxlib.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/lauxlib.c b/lauxlib.c
index 53c175a7..f2ac74db 100644
--- a/lauxlib.c
+++ b/lauxlib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lauxlib.c,v 1.163 2006/09/25 15:35:00 roberto Exp roberto $ 2** $Id: lauxlib.c,v 1.164 2006/10/16 14:38:38 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*/
@@ -230,6 +230,31 @@ LUALIB_API int luaL_callmeta (lua_State *L, int obj, const char *event) {
230} 230}
231 231
232 232
233LUALIB_API const char *luaL_tostring (lua_State *L, int idx) {
234 if (!luaL_callmeta(L, idx, "__tostring")) { /* no metafield? */
235 switch (lua_type(L, idx)) {
236 case LUA_TNUMBER:
237 lua_pushstring(L, lua_tostring(L, idx));
238 break;
239 case LUA_TSTRING:
240 lua_pushvalue(L, idx);
241 break;
242 case LUA_TBOOLEAN:
243 lua_pushstring(L, (lua_toboolean(L, idx) ? "true" : "false"));
244 break;
245 case LUA_TNIL:
246 lua_pushliteral(L, "nil");
247 break;
248 default:
249 lua_pushfstring(L, "%s: %p", luaL_typename(L, idx),
250 lua_topointer(L, idx));
251 break;
252 }
253 }
254 return lua_tostring(L, -1);
255}
256
257
233LUALIB_API void luaL_register (lua_State *L, const char *libname, 258LUALIB_API void luaL_register (lua_State *L, const char *libname,
234 const luaL_Reg *l) { 259 const luaL_Reg *l) {
235 luaI_openlib(L, libname, l, 0); 260 luaI_openlib(L, libname, l, 0);