mirror of
https://github.com/lua/lua.git
synced 2025-01-28 06:03:00 +08:00
luaL_tostring -> luaL_tolstring (more generic)
This commit is contained in:
parent
f9cdd09191
commit
daddc57abd
17
lauxlib.c
17
lauxlib.c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lauxlib.c,v 1.173 2007/09/05 17:17:39 roberto Exp roberto $
|
||||
** $Id: lauxlib.c,v 1.174 2007/09/14 13:26:28 roberto Exp roberto $
|
||||
** Auxiliary functions for building Lua libraries
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -550,23 +550,28 @@ LUALIB_API int luaL_callmeta (lua_State *L, int obj, const char *event) {
|
||||
}
|
||||
|
||||
|
||||
LUALIB_API const char *luaL_tostring (lua_State *L, int idx) {
|
||||
LUALIB_API const char *luaL_tolstring (lua_State *L, int idx, size_t *len) {
|
||||
if (!luaL_callmeta(L, idx, "__tostring")) { /* no metafield? */
|
||||
switch (lua_type(L, idx)) {
|
||||
case LUA_TNUMBER:
|
||||
return lua_pushstring(L, lua_tostring(L, idx));
|
||||
lua_pushstring(L, lua_tostring(L, idx));
|
||||
break;
|
||||
case LUA_TSTRING:
|
||||
lua_pushvalue(L, idx);
|
||||
break;
|
||||
case LUA_TBOOLEAN:
|
||||
return lua_pushstring(L, (lua_toboolean(L, idx) ? "true" : "false"));
|
||||
lua_pushstring(L, (lua_toboolean(L, idx) ? "true" : "false"));
|
||||
break;
|
||||
case LUA_TNIL:
|
||||
return lua_pushliteral(L, "nil");
|
||||
lua_pushliteral(L, "nil");
|
||||
break;
|
||||
default:
|
||||
return lua_pushfstring(L, "%s: %p", luaL_typename(L, idx),
|
||||
lua_pushfstring(L, "%s: %p", luaL_typename(L, idx),
|
||||
lua_topointer(L, idx));
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (len) *len = lua_objlen(L, -1);
|
||||
return lua_tostring(L, -1);
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lauxlib.h,v 1.92 2007/06/22 15:33:54 roberto Exp roberto $
|
||||
** $Id: lauxlib.h,v 1.93 2007/06/22 15:39:34 roberto Exp roberto $
|
||||
** Auxiliary functions for building Lua libraries
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -33,7 +33,7 @@ LUALIB_API void (luaL_register) (lua_State *L, const char *libname,
|
||||
const luaL_Reg *l);
|
||||
LUALIB_API int (luaL_getmetafield) (lua_State *L, int obj, const char *e);
|
||||
LUALIB_API int (luaL_callmeta) (lua_State *L, int obj, const char *e);
|
||||
LUALIB_API const char *luaL_tostring (lua_State *L, int idx);
|
||||
LUALIB_API const char *luaL_tolstring (lua_State *L, int idx, size_t *len);
|
||||
LUALIB_API int (luaL_typerror) (lua_State *L, int narg, const char *tname);
|
||||
LUALIB_API int (luaL_argerror) (lua_State *L, int numarg, const char *extramsg);
|
||||
LUALIB_API const char *(luaL_checklstring) (lua_State *L, int numArg,
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lbaselib.c,v 1.200 2007/10/25 19:31:05 roberto Exp roberto $
|
||||
** $Id: lbaselib.c,v 1.201 2007/11/28 18:25:17 roberto Exp roberto $
|
||||
** Basic library
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -405,7 +405,7 @@ static int luaB_xpcall (lua_State *L) {
|
||||
|
||||
static int luaB_tostring (lua_State *L) {
|
||||
luaL_checkany(L, 1);
|
||||
luaL_tostring(L, 1);
|
||||
luaL_tolstring(L, 1, NULL);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user