lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]



Hello all,

I added the following lines to the beginning of <lua.h>:

#if !defined __GNUC__ && !defined __attribute__
# define __attribute__(X)
#endif

and changed lines from <lua.h> and <lauxlib.h> as follows:

LUA_API const char *lua_pushfstring (lua_State *L, const char *fmt, ...)
     __attribute__((format (printf, 2, 3)));

LUALIB_API int luaL_error (lua_State *L, const char *fmt, ...)
     __attribute__((noreturn, format (printf, 2, 3)));

This enables type checking on all arguments passed through ... to a
printf-like format string. The result was one warning:

lstrlib.c:192: warning: unknown conversion type character `'' in format

Looks like this line should rather read:

        luaL_error(ms->L, "malformed pattern (ends with `%%')");


I have had no problems with this kind of __attribute__ definition in various
large multi-platform projects so far. It helps some and does not impose
portability problems.

I'm not sure about the "noreturn" attribute to luaL_error(): Can this
function ever return?

Cheers
Dirk