diff options
Diffstat (limited to 'lbaselib.c')
-rw-r--r-- | lbaselib.c | 27 |
1 files changed, 9 insertions, 18 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lbaselib.c,v 1.151 2004/07/01 14:26:28 roberto Exp roberto $ | 2 | ** $Id: lbaselib.c,v 1.152 2004/07/02 18:09:11 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 | */ |
@@ -383,45 +383,36 @@ static int luaB_xpcall (lua_State *L) { | |||
383 | 383 | ||
384 | 384 | ||
385 | static int luaB_tostring (lua_State *L) { | 385 | static int luaB_tostring (lua_State *L) { |
386 | char buff[4*sizeof(void *) + 2]; /* enough space for a `%p' */ | ||
387 | const char *tn = ""; | ||
388 | const void *p = NULL; | ||
389 | luaL_checkany(L, 1); | 386 | luaL_checkany(L, 1); |
390 | if (luaL_callmeta(L, 1, "__tostring")) /* is there a metafield? */ | 387 | if (luaL_callmeta(L, 1, "__tostring")) /* is there a metafield? */ |
391 | return 1; /* use its value */ | 388 | return 1; /* use its value */ |
392 | switch (lua_type(L, 1)) { | 389 | switch (lua_type(L, 1)) { |
393 | case LUA_TNUMBER: | 390 | case LUA_TNUMBER: |
394 | lua_pushstring(L, lua_tostring(L, 1)); | 391 | lua_pushstring(L, lua_tostring(L, 1)); |
395 | return 1; | 392 | break; |
396 | case LUA_TSTRING: | 393 | case LUA_TSTRING: |
397 | lua_pushvalue(L, 1); | 394 | lua_pushvalue(L, 1); |
398 | return 1; | 395 | break; |
399 | case LUA_TBOOLEAN: | 396 | case LUA_TBOOLEAN: |
400 | lua_pushstring(L, (lua_toboolean(L, 1) ? "true" : "false")); | 397 | lua_pushstring(L, (lua_toboolean(L, 1) ? "true" : "false")); |
401 | return 1; | 398 | break; |
402 | case LUA_TNIL: | 399 | case LUA_TNIL: |
403 | lua_pushliteral(L, "nil"); | 400 | lua_pushliteral(L, "nil"); |
404 | return 1; | 401 | break; |
405 | case LUA_TTABLE: | 402 | case LUA_TTABLE: |
406 | p = lua_topointer(L, 1); | 403 | lua_pushfstring(L, "table: %p", lua_topointer(L, 1)); |
407 | tn = "table"; | ||
408 | break; | 404 | break; |
409 | case LUA_TFUNCTION: | 405 | case LUA_TFUNCTION: |
410 | p = lua_topointer(L, 1); | 406 | lua_pushfstring(L, "function: %p", lua_topointer(L, 1)); |
411 | tn = "function"; | ||
412 | break; | 407 | break; |
413 | case LUA_TUSERDATA: | 408 | case LUA_TUSERDATA: |
414 | case LUA_TLIGHTUSERDATA: | 409 | case LUA_TLIGHTUSERDATA: |
415 | p = lua_touserdata(L, 1); | 410 | lua_pushfstring(L, "userdata: %p", lua_topointer(L, 1)); |
416 | tn = "userdata"; | ||
417 | break; | 411 | break; |
418 | case LUA_TTHREAD: | 412 | case LUA_TTHREAD: |
419 | p = lua_tothread(L, 1); | 413 | lua_pushfstring(L, "thread: %p", lua_topointer(L, 1)); |
420 | tn = "thread"; | ||
421 | break; | 414 | break; |
422 | } | 415 | } |
423 | sprintf(buff, "%p", p); | ||
424 | lua_pushfstring(L, "%s: %s", tn, buff); | ||
425 | return 1; | 416 | return 1; |
426 | } | 417 | } |
427 | 418 | ||