lua-users home
lua-l archive

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


François Perrad <francois.perrad@gadz.org> wrote:

> I propose the addition of the following macros in lauxlib.h :
>   #define luaL_checkboolean(L,n)    (luaL_checktype(L, (n), LUA_TBOOLEAN))

Use lua_toboolean. It is more idiomatic than requiring that a value is
exactly true or false.

>   #define luaL_checknil(L,n)    (luaL_checktype(L, (n), LUA_TNIL))

Requiring a function argument to be nil doesn't make sense.

>   #define luaL_checktable(L,n)    (luaL_checktype(L, (n), LUA_TTABLE))

Prevents callers from passing an object with a suitable metatable.

In general the luaL_check* functions deal with transferring data from Lua
to C, and raise an error if this is not possible. If a value remains in
Lua, such as a function or a table, it's easier to just use it as if it
has the type you expect, and allow the lower-level checks to do their job.

Tony.
-- 
f.anthony.n.finch  <dot@dotat.at>  http://dotat.at/
Rockall, Malin, Hebrides: South 5 to 7, occasionally gale 8 at first in
Rockall and Malin, veering west or northwest 4 or 5, then backing southwest 5
or 6 later. Rough or very rough. Occasional rain. Moderate or good,
occasionally poor.