From dfebe439db76b5c9fd9b4e3877857e2449c8ad87 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Wed, 13 Mar 2019 14:04:01 -0300 Subject: New conversion specifier '%p' for 'string.format' The call 'string.format("%p", val)' gives a Lua equivalent to the C API function 'lua_topointer'. --- lstrlib.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'lstrlib.c') diff --git a/lstrlib.c b/lstrlib.c index ab4258e5..6230cd0c 100644 --- a/lstrlib.c +++ b/lstrlib.c @@ -1185,6 +1185,11 @@ static int str_format (lua_State *L) { nb = l_sprintf(buff, MAX_ITEM, form, (LUAI_UACNUMBER)n); break; } + case 'p': { + const void *p = lua_topointer(L, arg); + nb = l_sprintf(buff, MAX_ITEM, form, p); + break; + } case 'q': { if (form[2] != '\0') /* modifiers? */ return luaL_error(L, "specifier '%%q' cannot have modifiers"); -- cgit v1.2.3-55-g6feb