New conversion specifier '%p' for 'string.format'

The call 'string.format("%p", val)' gives a Lua equivalent to the
C API function 'lua_topointer'.
This commit is contained in:
Roberto Ierusalimschy
2019-03-13 14:04:01 -03:00
parent cf71a5ddc7
commit dfebe439db
3 changed files with 31 additions and 3 deletions

View File

@@ -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");