commit a45945b6d511b00b1c84dc73881474030737e956
parent 9e1f1b1f6230f71d95eba4457d8ac2719ed9e7c7
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date: Wed, 19 Apr 2017 13:34:08 -0300
new macro 'lua_pointer2str' to encapsulate use of 'l_sprintf' inside
the kernel
Diffstat:
2 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/lobject.c b/lobject.c
@@ -1,5 +1,5 @@
/*
-** $Id: lobject.c,v 2.112 2016/06/27 13:15:08 roberto Exp roberto $
+** $Id: lobject.c,v 2.113 2016/12/22 13:08:50 roberto Exp roberto $
** Some generic functions over Lua objects
** See Copyright Notice in lua.h
*/
@@ -435,7 +435,8 @@ const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) {
}
case 'p': { /* a pointer */
char buff[4*sizeof(void *) + 8]; /* should be enough space for a '%p' */
- int l = l_sprintf(buff, sizeof(buff), "%p", va_arg(argp, void *));
+ void *p = va_arg(argp, void *);
+ int l = lua_pointer2str(buff, sizeof(buff), p);
pushstr(L, buff, l);
break;
}
diff --git a/luaconf.h b/luaconf.h
@@ -1,5 +1,5 @@
/*
-** $Id: luaconf.h,v 1.258 2016/12/20 18:37:00 roberto Exp roberto $
+** $Id: luaconf.h,v 1.259 2016/12/22 13:08:50 roberto Exp roberto $
** Configuration file for Lua
** See Copyright Notice in lua.h
*/
@@ -621,6 +621,13 @@
/*
+@@ lua_pointer2str converts a pointer to a readable string in a
+** non-specified way.
+*/
+#define lua_pointer2str(buff,sz,p) l_sprintf(buff,sz,"%p",p)
+
+
+/*
@@ lua_number2strx converts a float to an hexadecimal numeric string.
** In C99, 'sprintf' (with format specifiers '%a'/'%A') does that.
** Otherwise, you can leave 'lua_number2strx' undefined and Lua will