diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-03-13 14:04:01 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-03-13 14:04:01 -0300 |
commit | dfebe439db76b5c9fd9b4e3877857e2449c8ad87 (patch) | |
tree | c31aa85dc53d1c0e0704060f313b682765dd459c /lstrlib.c | |
parent | cf71a5ddc742692fad813f89f1c9ef53e1ffde0f (diff) | |
download | lua-dfebe439db76b5c9fd9b4e3877857e2449c8ad87.tar.gz lua-dfebe439db76b5c9fd9b4e3877857e2449c8ad87.tar.bz2 lua-dfebe439db76b5c9fd9b4e3877857e2449c8ad87.zip |
New conversion specifier '%p' for 'string.format'
The call 'string.format("%p", val)' gives a Lua equivalent to the
C API function 'lua_topointer'.
Diffstat (limited to 'lstrlib.c')
-rw-r--r-- | lstrlib.c | 5 |
1 files changed, 5 insertions, 0 deletions
@@ -1185,6 +1185,11 @@ static int str_format (lua_State *L) { | |||
1185 | nb = l_sprintf(buff, MAX_ITEM, form, (LUAI_UACNUMBER)n); | 1185 | nb = l_sprintf(buff, MAX_ITEM, form, (LUAI_UACNUMBER)n); |
1186 | break; | 1186 | break; |
1187 | } | 1187 | } |
1188 | case 'p': { | ||
1189 | const void *p = lua_topointer(L, arg); | ||
1190 | nb = l_sprintf(buff, MAX_ITEM, form, p); | ||
1191 | break; | ||
1192 | } | ||
1188 | case 'q': { | 1193 | case 'q': { |
1189 | if (form[2] != '\0') /* modifiers? */ | 1194 | if (form[2] != '\0') /* modifiers? */ |
1190 | return luaL_error(L, "specifier '%%q' cannot have modifiers"); | 1195 | return luaL_error(L, "specifier '%%q' cannot have modifiers"); |