[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Feature request: make typeerror public somehow
- From: Steven Degutis <sbdegutis@...>
- Date: Wed, 24 Dec 2014 00:47:03 -0600
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.
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)?
: https://github.com/sdegutis/diywm/tree/master/Lua/Lua --
Anonymous Lua User