lua-users home
lua-l archive

Should we explicitly cast from luaL_checkinteger() et al?

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


Greetings.
I've asked this question on StackOverflow (see link [1] bellow), and
@lhf suggested that I ask it here.
After I get answers here I'll summarize them on StackOverflow.
--- I'm hereby pasting my question: ---
Lua 5.3 deprecates luaL_checkint, luaL_checklong, luaL_optint,
luaL_optlong, which were just convenience macros calling
luaL_{check|opt}integer.
While we can still use them (because of -DLUA_COMPAT_5_2), they aren't
mentioned in the user manual and we're advised to use
luaL_{check|opt}integer "with a type cast".
Now, I'm not an expert in C and I was wondering:
(1) Is a cast needed in simple cases like the following?
 int i;
 i = (int)luaL_checkinteger(L, 1);
(2) If a cast isn't needed here, where *is* it needed?
(3) Why were those deprecated macros born in the first place if we can
do without them? In other words: what did they serve?
(4) Aren't we losing "documentation" by not having the words
"int"/"long" embedded in the function name?
[1] http://stackoverflow.com/questions/28098822/should-we-explicitly-cast-from-luas-lual-checkinteger-et-al

AltStyle によって変換されたページ (->オリジナル) /