lua-users home
lua-l archive

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


I noticed that Lua code sometimes uses macros where a static inline function
would appear to work equally as well.
For instance, consider the macro isLua defined in lstate.h:

#define isLua(ci)	(!((ci)->callstatus & CIST_C))

I imagine this could be turned into a function like so:

static inline int isLua(CallInfo *ci)	{ return !((ci)->callstatus & CIST_C); }

The reason why one would want to replace macros with functions is because
functions are often easier to reason about than macros.
This is because functions have static scoping, only evaluate their arguments
once, and are typed.
So it may be worthwhile to turn such macros into functions to prevent
developers from accidentally falling into common macro pitfalls, such as those
listed in the GNU C Preprocessor Manual.

How interested would the Lua development team be in replacing such macros with
functions in the future?