|
Am 07.02.2016 um 14:30 schröbte Roberto Ierusalimschy:
While studying the source code for the standard table library, I noticed that function "unpack" uses the macro "luaL_opt", which is defined in "lauxlib.h". Because it is defined in lauxlib.h, and because of its "luaL_" prefix, I assumed that this macro is considered part of the official auxiliary library, yet it is nowhere to be found in the 5.3 reference manual. Is this an accidental omission, in which case it should be added to the manual, or is it left out of the manual for a reason, and if so, what is that reason?That macro is a kludge. It seems it would be more work to understand its documentation then to write what you want explicitly. (We probably should not use it, too.) (Case in point: its current use in 'tconcat' is just a complicated way to say 'luaL_optinteger'...)
I like it, and I use it about 20 times in my FLTK binding[1]. I have a lot of two-argument type checking functions in there (most of them private, some generated via C macros) and I don't want to go back and forth and add/remove yet another function variant when using `luaL_opt` is just as clear to read. (It almost feels like a higher-order function in C.)
On the other hand, instead of `luaL_optinteger`/`luaL_checkinteger` I prefer a function that also does bounds checking. Many C APIs don't accept the full `lua_Integer` value range.
-- Roberto
Philipp [1]: https://github.com/siffiejoe/lua-fltk4lua/search?utf8=&q=luaL_opt(