lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


There is no such thing as a "static" table in Lua. Every time an _expression_ with {} is executed a new table is constructed that you can modify freely.

For your problem of adding child objects to some container, note that

    local view = f:column{
        ...
    }

could be written as

    local columnData = {
        ...
    }
    local view = f:column(columnData)

which would allow you to easily modify the table before you call f:column() to create the view.

    local columnData = {margin=10, spacing=5}

    -- Add three children.
    for i = 1, 3 do
        table.insert(columnData, f:static_text{ title="Text "..i })
    end

    local view = f:column(columnData)

The fact that

    ptr[index+1]["_parent"] = ptr[1]["_parent"]

behaves like

    ptr[index+1]["_viewAttributes"]["_parent"] = ptr[1]["_parent"]

(assuming ptr is some userdata object returned by the API) is probably because the object doesn't allow you to change its attributes however you want, so it just puts your value in _viewAttributes instead. This behavior would be specific to this object in this specific API and has nothing to do with Lua in general.

Also, as a bonus, ptr[1]["_parent"] can be written as ptr[1]._parent, or more generally, foo["bar"] as foo.bar . It's a bit nicer.

I hope this clears things up a bit.

(Also, this is my first message to the mailing list. Hello, list!)


On Tue, 9 Aug 2022 at 01:32, Perry Smith <pedz@easesoftware.com> wrote:
I am inside the SDK of Adobe’s Lightroom Classic.  They are using Lua version 5.1.4 (according to their documentation).  _VERSION seems to be set to nil.

The SDK does not have a way to programmatically create a “View” but only via Lua’s static table declaration syntax such as:

   local f = LrView.osFactory()
   local view = f:column {
      margin = 10,
      spacing = 5,
      f:static_text {
         title = "Job Identifiers"
      },
      f:separator {
         fill_horizontal  = 1.0,
      },
   }

But there is no way to add N checkboxes where N is unknown until run time.

So I wrote code to dump out the resulting table and then more code to try and create the proper data structure.  There is a very good chance that I’m on a fool’s errand but here is my current issue.

I set a value with this piece of code:

      ptr[index+1]["_parent"] = ptr[1]["_parent”]

But instead of the new element going where it “should” go, it effectively does this:

      ptr[index+1]["_viewAttributes"]["_parent"] = ptr[1]["_parent”]

Now… if this is utterly impossible, then perhaps my debug code is buggy but I don’t think so.

Can someone help explain what is going on and how to achieve what I want to do ?

Thank you,
Perry Smith