lua-users home
lua-l archive

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


          Component
          { (*** line 39 ***)
               parent = "PlayGUI",
               type = "TextLabel"
          }
}



> It doesn't work. Lua complains:

> error: `=' expected;
>  last token read: `{' at line 39 in file `scripts/testSDL/gui.lua'
> stack traceback:
>   1:  function `Exec' [C]
>   2:  main of file `scripts/testSDL/main.lua' at line 5
> *** Syntax error in script file scripts/testSDL/gui.lua

Interesting... without looking at the Lua parser or trying anything, my
hunch
is that you're running into a line-end-aware issue introduced with Lua 5.

Try doing the way I suggested, with
      children = { Component { }, Component { } }

(or some such.)


> I wanted to pass the table into a C function, but I haven't managed to
get that
> working. That's what I was referring to in my code; sorry if that wasn't
clear.

You have to use the Lua API to go through the table. The Lua manual is
reasonably clear, I think; you push the table and the key on the stack,
and then extract the value. Or you can iterate through all of the keys,
but if you know which ones you're looking for, just getting them from
the table is better. It is a matter of style whether you worry about
there being unknown keys in the table: often that indicates a typo, which
means that a check would have been a good thing, but often it means that
the Lua script was stashing extra useful information into the structure.

To get at the values in the children table that I recommend, you want
to use the numeric index API, which will let you extract them in the
right order; if you iterate with next, you might get a surprise.

R.