-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tables as first argument introduces ambiguity - proposal: table wrappers classes #9
Comments
do any of the argcheck users know this? cc: @andresy @ajabri @lvdmaaten |
If we have something other than a table it does work fine: local check_init = argcheck{
noordered=true,
{name="tbl", type = "string", default=false}}
function test:__init(tbl) -- called in case of success
tbl = check_init({tbl = tbl})
print(tbl)
end
print("-- No arguments")
a = test.new()
print("\n-- String")
a = test.new("test")
print("\n-- Should throw error")
a = test.new{tbl="asdsa"} Ends up with the expected output:
I guess this could be averted by specifying the expected table depth. This would cost quite a bit performance but in some use cases the performance isn't that important, e.g. in the torch-dataframe we want to allow users to provide a single column name or multiple column names. The core problem is that the argument packing in Lua stuffs everything into the first parameter without leaving a trace. In my mind this is a design flaw as it unnecessarily limits Lua capabilities, ideally I would like that they add a hidden indicator of that this packing has occurred, e.g. a boolean like |
If this is unsolvable within the current Lua design (found this discussion) a possible (hacky) option could be to have custom classes, e.g. argcheck.Table, argcheck.Array, etc. that take a table as an argument which is then extracted once the variable has been identified. This should take care of any ambiguity cases and possibly also allow for some basic checks of the incoming tables. |
I'm struggling to grasp how to approach argument that can either be a string or a table for the
__init
function. I figured that if I go with ordered arguments the argcheck should just use theenv.istype
and let me worry about the implementation details. Unfortunately nothing seems to happen when using thenonamed
argument, here's an example:Outputs:
The documentation is a little thin on classes, if I'm missing something please consider extending the docs a little so that this awesome package gets easier to implement.
The text was updated successfully, but these errors were encountered: