[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Feature request: make typeerror public somehow
- From: Philipp Janda <siffiejoe@...>
- Date: Wed, 24 Dec 2014 08:12:24 +0100
Am 24.12.2014 um 07:47 schröbte Steven Degutis:
While working on a Swift wrapper around Lua's C API (code is here),
I came up with a way to extend Lua's argument-checking functionality.
The upside is that now I can assert that argument #2 is a "point",
meaning a table that contains keys "x" and "y" pointing to numbers.
This is admittedly not as efficient as just checking lua_type, but
it's also opt-in.
The downside is that I can't use luaL_checktype for these kinds of
custom types, because that function uses lua_type directly.
What about `luaL_argcheck(L, is_point(L, 1), 1, "point expected")`?
Hoping to find another solution, I dug into the source code of
luaL_checktype, and found that typeerror is exactly what I would want
to use here, asking the custom type for typeerror's tname argument.
But typeerror is a private function.
So in my program, I've modified Lua to contain a new public function,
luaL_typeerror, which just calls typeerror directly. I'm not sure how
generally useful this would be, but since this function would be
purely opt-in and can coexist peacefully with luaL_checktype, would it
be a good idea to create this new function in Lua proper (even if with
a different name)?
In Lua 5.1 we had this function, but it got removed in Lua 5.2. To
be fair, it was a trivial function then, but now got a little more
complex for Lua 5.3.
Anonymous Lua User