Skip to content

Problem parsing more than 9 input arguments #3

Open

Description

@fmassa

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>

Activity

  1. andresy commented on Jan 23, 2015

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

  2. bamos commented on Mar 28, 2016

    @bamos

    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.

  3. fmassa commented on Mar 28, 2016

    @fmassa
    Author

    @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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions