aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lauxlib.c27
-rw-r--r--lauxlib.h3
-rw-r--r--lbaselib.c22
3 files changed, 30 insertions, 22 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);
diff --git a/lauxlib.h b/lauxlib.h
index f7b02db5..b6fedef5 100644
--- a/lauxlib.h
+++ b/lauxlib.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lauxlib.h,v 1.87 2005/12/29 15:32:11 roberto Exp roberto $ 2** $Id: lauxlib.h,v 1.88 2006/04/12 20:31:15 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*/
@@ -45,6 +45,7 @@ LUALIB_API void (luaL_register) (lua_State *L, const char *libname,
45 const luaL_Reg *l); 45 const luaL_Reg *l);
46LUALIB_API int (luaL_getmetafield) (lua_State *L, int obj, const char *e); 46LUALIB_API int (luaL_getmetafield) (lua_State *L, int obj, const char *e);
47LUALIB_API int (luaL_callmeta) (lua_State *L, int obj, const char *e); 47LUALIB_API int (luaL_callmeta) (lua_State *L, int obj, const char *e);
48LUALIB_API const char *luaL_tostring (lua_State *L, int idx);
48LUALIB_API int (luaL_typerror) (lua_State *L, int narg, const char *tname); 49LUALIB_API int (luaL_typerror) (lua_State *L, int narg, const char *tname);
49LUALIB_API int (luaL_argerror) (lua_State *L, int numarg, const char *extramsg); 50LUALIB_API int (luaL_argerror) (lua_State *L, int numarg, const char *extramsg);
50LUALIB_API const char *(luaL_checklstring) (lua_State *L, int numArg, 51LUALIB_API const char *(luaL_checklstring) (lua_State *L, int numArg,
diff --git a/lbaselib.c b/lbaselib.c
index 01decb46..556325af 100644
--- a/lbaselib.c
+++ b/lbaselib.c
@@ -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
397static int luaB_tostring (lua_State *L) { 397static 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