[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: [PROPOSAL] more luaL_check* in lauxlib.h (for Lua 5.2)
- From: Tony Finch <dot@...>
- Date: Tue, 31 May 2011 11:40:04 +0100
François Perrad <email@example.com> 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.
f.anthony.n.finch <firstname.lastname@example.org> 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,