lua-users home
lua-l archive

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


The solution to the following problem escapes me. Hopefully someone knows howto.

The file "messages" contains a series of data: 
  Message{field1=.., field2=..,} .. Message{..}

Reading these data in a table with the following code:
local Container = {}
local function readall ()
  function Message (msg) Container[#Container+1] = msg end
  dofile("messages")
end

After the call to readall() the table Container is filled with the data. The field of the data can of course be used with Container[1].field1, etc.

Now the problem: I would like to be able to use in expressions
  Container[1].extrafield
where extrafield is the result of an operation to be performed on the fields of the data. 
For example, if field1 is a string, then extrafield could deliver string.sub(field1,1,2).

Is it possible to do so in Lua, and how? I would be glad if someone can put me on the right track.

Hans van der Meer