lua-users home
lua-l archive

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

On Tue, 9 Aug 2022 at 14:21, Perry Smith <> wrote:
> 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.

the detail you're missing is that there's a special syntax for function calls.

any function f can be called with zero or more parameters, like usual:
f(a,b,c)   but you can also call it with a single string constant
without parenthesis, like  f "xxx" and it's exactly like f("xxx"), or
with a single table, again without parenthesis:   f {...}  and it's
the same as  f({...})

you can simply add the parenthesis to those calls if you wish, that
might make it more familiar.  making your first code snippet 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,

and would be exactly the same.  now it's evident that Lua first
creates a table (lets call it t1) with "margin" and "spacing" fields,
then creates another table (say t2) like { title="Job Identifiers"},
calls f:static_text with t2 and sets t1[1] to the result.  then a
third table t3={fill_horizontal=1.0}, calls f:separator with t3 and
sets t1[2] to that result.  finally calls f:column with t1 and sets
your local variable "view" to this final result.

in this explanation, t1, t2, and t3 are imaginary names, to Lua these
temporary tables are fully anonymous.  But you can use variables to do
the same:

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

In Marcus' example, he first constructs this table in a variable
called columnData, adds whatever is needed there, using any normal
table modification method, and then calls f:column(columnData).   If I
read your last email correctly, you were missing the call to f:column
and trying to use columnData directly in subsequent library calls,
which eventually failed.

hope this helps