lua-users home
lua-l archive

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


Hi,

I'm having some ideas for implementing an MVC pattern using Lua + a C library. I want to place the Model in Lua and the Controller and View in the C library. I'm not a very experienced Lua programmer so I'm trying to investigate how I could possibly accomplish this.

I'd like to have Lua values in arbitrary places in my scripts and register them to link to a controller. The controller then has to monitor the Lua values for changes, and update the View. The other way around the changes in the View have to be reflected in the Lua values of course. I'd like to to do something similar to Cocoa's KVC/KVO mechanism, but probably less advanced. The main idea is to easily attach an (optional) user interface to a Lua script without polluting the code a lot.

I can only think of a way to get KVO working. By putting all "registered" values in the same table, and using a proxy table to report all value changes back to the library. The problem with this approach is that all values need to be in the same table, and I don't like that.

Is there a way to connect directly from C with the Lua value memory address and check for value changes / update values? I have a feeling this might not be possible because you then have to know the if the values are still valid and not garbage collected or something.

Like I said I'm pretty new to Lua and just investigating what's possible. Any suggestions are greatly appreciated.


Cheers,
Thijs