[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Updating C structeres from Lua?
- From: Allan Odgaard <Allan@...>
- Date: Sat, 18 Jan 2003 17:41:10 +0100
I am still not subscribed, but it seems I can post to the list and
access the archive at YahooGroups (though please do Cc me in a
potential reply).
I am writing a text editor (for OS X) and have chosen Lua as the
scripting langauge, because this quite frankly seems to be the best
choice :-)
My questions is twofold:
I would like to expose a lot of stuff to the scripts started from my
text editor, but this would probably add a rather big memory (and
performance) overhead, if I had to add all the stuff to Lua, e.g. the
text buffer itself would be a table used as an array consisting of
strings (and I would have to re-add it when text is changed from the
editor).
Instead I can for example provide my "text buffer" table with a
metatable that points to a function for 'index' which will pull the
proper line from C, convert it to Lua, add it and return it.
Problem with this approach is that the user won't be able to do stuff
like "table.foreach(textbuffer,print)" to print all lines.
Is there anyway around this?
Another problem is that there is also a settings table and the user
could change this as he pleases.
Rather than having to go through the entire table when the script exits
(to see what is changed) then I would prefer to supply some sort of
callback function -- unfortunately it seems that 'newindex' (from the
metatable) is only called when new indexes are created, and not when
old ones are updated.
Any way around that?
I gues basically what I ask for is virtual tables, i.e. where all get
and set would go through C code, rather than have to initially map all
C structures to Lua and when the script exits, map it all back again.
I know I could provide my own Lua get/set functions and impose these on
the user, but that would suck big time...
Thanks in advance, Allan