luaiup

IUPLUA Putting Elements into the .gridbox with table.unpack doesn't work


local gridBox = iup.gridbox{
    table.unpack(Instances),
    --Instances[1],
    --Instances[2],
    numcolumns = 3,
    alignment = "ACENTER",
    expand = "YES"
}

When I run this in VSCode it will show only 1 Element of the Instance Table, which is always random, however if I do it with e.g. Instances[1] then they will show up to 100%. I however need it more "dynamically"

Tried puting in the table directly with

local gridBox = iup.gridbox{
    Instances,
    numcolumns = 3,
    alignment = "ACENTER",
    expand = "YES"
}

and like already mentioned with Instances[1]


Solution

  • Do this instead:

    local gridBox = iup.gridbox{
        numcolumns = 3,
        alignment = "ACENTER",
        expand = "YES",
        table.unpack(Instances)
    }
    

    When a function returns multiple values, if you want to keep them all rather than just the first, there can't be a comma after it. Since order doesn't matter otherwise in your case, just reordering them makes it work. If order did matter, then you'd need a more complicated solution instead, such as the one in my answer to this other question.