Skip to content
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

Problem parsing more than 9 input arguments #3

Open
fmassa opened this issue Jan 14, 2015 · 3 comments
Open

Problem parsing more than 9 input arguments #3

fmassa opened this issue Jan 14, 2015 · 3 comments

Comments

@fmassa
Copy link

fmassa commented Jan 14, 2015

The following code snippet reproduces the problem:

argcheck = require 'argcheck'
initcheck = argcheck{
  {name="x1",type="string",help="x1",default="a"},
  {name="x2",type="string",help="x2",default="a"},
  {name="x3",type="string",help="x3",default="a"},
  {name="x4",type="string",help="x4",default="a"},
  {name="x5",type="string",help="x5",default="a"},
  {name="x6",type="string",help="x6",default="a"},
  {name="x7",type="string",help="x7",default="a"},
  {name="x8",type="string",help="x8",default="a"},
  {name="x9",type="string",help="x9",default="a"},
  {name="x10",type="string",help="x10",default="a"}
}

Here is the error I get:

/usr/local/share/lua/5.1/argcheck/init.lua:105: could not generate argument checker: [string "argcheck"]:35093: control structure too long near 'end'
stack traceback:
    [C]: in function 'error'
    /usr/local/share/lua/5.1/argcheck/init.lua:105: in function 'argcheck'
    [string "initcheck = argcheck{..."]:1: in main chunk
    [C]: in function 'xpcall'
    /usr/local/share/lua/5.1/trepl/init.lua:567: in function </usr/local/share/lua/5.1/trepl/init.lua:468>
@andresy
Copy link
Member

andresy commented Jan 23, 2015

You have many default variables.
The case of ordered arguments:
initcheck("a", "b", "c"...)
generates only 10 cases, that is ok.

But in the named argument case, that generates a lot of things, because you can specify any argument to be there or not (and argcheck checks all possible cases)
initcheck{x3="a", x5="b", x10="e") -- note this is not possible with ordered arguments.
This case generate 15K lines of code (see with argcheck{debug=true, ...}). Unfortunately, luajit (which has much more limitations than lua) does not support it (lua is ok though).

If you do not need named arguments, then deactivate it with argcheck{nonamed=true, ...}, and you will be fine. If you really need named arguments for that case... hmmm... i have to think about workarounds which would work with luajit. I could also add an option such that the behavior is the same than with ordered arguments (like initcheck{x1="a", x2="b} is ok, but initcheck{x2="a", x3="b"} is not).

@bamos
Copy link
Contributor

bamos commented Mar 28, 2016

Hi @andresy - any further thoughts on how to solve this? I'd like to overcome this in my application without using hacks like combining arguments into tables, manually defaulting values, or not using named arguments. I'd be happy to contribute some code to resolve this.

-Brandon.

@fmassa
Copy link
Author

fmassa commented Mar 28, 2016

@bamos I wrote a simple workaround function sometime ago specifically for this case. It would sure be much better to solve this problem in argcheck though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants