lua-users home
lua-l archive

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


Dear Lua people,

I'm about to write some C functions to provide Mac Lua with some
(hopefully) flexible dialog boxes. My idea was to let my Lua script define
the dialog box on the fly through a Lua table/list of item specs, somewhat
like this:

  name, pwd = dialog{{type=btn, name="OK"},{type=btn, name="Cancel"},
                     {type=fld, name="Name"},{type=pwfld, name="Password"}}

What I would now like to know, is what's the most elegant way to transfer
(the values of) such a nested table from the calling Lua script to the C
function? Should I let the calling script push the entire table as one
object onto lua2C, or should I let the script push lots of smaller units?

In "5.5 - How do I traverse a table in C?*" in the Lua FAQ, the suggestion is:

  lua_pushobject(table);
  lua_pushcfunction(f);
  lua_call("foreach");

I'm suspecting, however, that this technique may not be very useful to me.
Will it be safe to have a Lua script call a C function that in turn calls
lua_call("foreach") ? If it is safe, I may just end up with a lot of
smaller units on lua2C, instead of a table ...

(I guess the proper name for "lua_call" is now "lua_callfunction".)


Sincerely,

Jon Kleiser