lua-users home
lua-l archive

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


Thank you.  And welcome to the list.

Your example is not quite what I was trying to do.  Your columnData is a normal table created from {} so it has the (not sure of the term) normal metatable.  After the assignment, view is now a table with a different metatable.  And the code:

    table.insert(view, 1, “foo”)

is what I’m *was* trying to do — which doesn’t work.  But I think the more general essence of your suggestion was to build the structure from the inside out.

So I started with a normal table using { … } and inserted my checkboxes into that table as you suggested.  I then passed that to f:scrolled_view which creates a scroll box with the checkboxes inside.  So far so good.  

Then I used that as part of (again) a normal table and passed that to f:column which creates a column of UI elements.  Rinse and repeat building from the inner most UI elements out.

Where I was confused is I was thinking somehow the syntax f( …, g( … ), … ) was calling f first which of course it isn’t.  I also thought some type of magic was happening as the table was being constructed.  Viewing it in the more primitive terms is what I needed.

Thank you very much
Perry

On Aug 9, 2022, at 06:05, Marcus Thunström <refreezed@gmail.com> wrote:

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


Attachment: signature.asc
Description: Message signed with OpenPGP