lua-users home
lua-l archive

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

On Apr 3, 2008, at 12:39 AM, David Given wrote:

Eugen-Andrei Gavriloaie wrote:
Sorry if this is a stupid question. But either I can't find the answer
in the docs because of a "selective" blindness or it's not so obvious
(I'm a newbie in Lua world). So here is the question:

Other people have actually answered your question, but you may want to
consider adopting a slightly different approach: instead of parsing your
data structure from C, you could instead parse it from Lua and inform
your C code of the data it needs that way. This might make the code
easier to handle. So either:

for index, o in ipairs(applications) do
 inform_c_of_application_type(index, o.type)


function GetApplicationType(i)
 return applications[i].type

...depending on whether you want C or Lua to own the data structures.
Either way, putting the messy bits of the code in Lua might be easier
and more reliable than trying to do it in C --- performance isn't an
issue, right?

┌─── ───── ─────
│ "I have always wished for my computer to be as easy to use as my
│ telephone; my wish has come true because I can no longer figure out
│ how to use my telephone." --- Bjarne Stroustrup

Yes, it would be great, but is not looking like a configuration file anymore. A configuration file should be very simple to edit and maintain. Having the user forced to provide some functions will not be such a good idea.

Another idea of how to explain this situation popped into my mind right now. It's like evaluating an expression when you debug a C++ application. It does not alter anything (only if you do stupid things like null-ing some pointers, calling irreversible functions like close(fd) on a socket, etc). Mainly, all I want is just evaluating an expression, not altering anything and be able to do that at run-time.

Thank you for your support guys!