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

Comments

Projects
None yet
3 participants
@fmassa

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

This comment has been minimized.

Show comment
Hide comment
@andresy

andresy Jan 23, 2015

Member

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).

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

This comment has been minimized.

Show comment
Hide comment
@bamos

bamos Mar 28, 2016

Contributor

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.

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

This comment has been minimized.

Show comment
Hide comment
@fmassa

fmassa 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.

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