lua-users home
lua-l archive

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


While working on a Swift wrapper around Lua's C API (code is here[1]),
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)?

[1]: https://github.com/sdegutis/diywm/tree/master/Lua/Lua --
especially VirtualMachine.swift

Sincerely,
Anonymous Lua User