lua-users home
lua-l archive

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


I'm designing a system in which various "modules" work together, handling different events, in order to provide an overall result. I know this is extremely vague, so let me explain some more before I get to my question.

Let's assume I had a robot, for example. Under my system, one module would handle the hand movement, one would handle foot movement (and coordinate walking), and one might handle speech. Unfortunately, there's a couple of catches.

Modules should only be able to access certain members of other modules. I've got about ten people or so who have expressed interest in scripting a module, but I don't fully trust them all to not execute functions that might destroy the bot (or even just an accident, like unloading all of the other modules). I don't want function collisions, either, but I don't want to lay down a huge system of rules or naming conventions for its script writers to prevent multiple modules from having functions of the same name. However, certain modules need to be able to communicate with certain other modules (for example, hand-eye coordination, or remembering what the bot was doing). I'll also have some modules that will be only libraries; that is, they'll have some basic functions that all the other modules should be able to call. Also, each module needs to be loadable or unloadable at will (unless of course other modules are depending on it at the time). If I need to fix a bug in the eye system, I don't want to have to restart the entire bot, which will then cause it to forget everything in its other modules--and if the eye system has an error, I'd like the bot to continue with its other systems, ignoring the fact that its eyes are no longer open, until I tell it to reload the eye script.

At first I was going to have each module be a separate Lua state. However, I couldn't find a good way to allow separate Lua states to call each others' functions. It seems the only viable option is to use a single Lua state, but then I do not know how you could "unload" a certain section of that state without completely resetting the state. It's possible that I could store all of the functions and variables of that module in a table, which could then be nilled when that module was unloaded, but I don't believe that tables can have private members (unless I'm mistaken), so that still wouldn't solve all of my problems.

So, what's the best way to implement multiple reloadable scripts and make sure that they don't have member collisions, and yet have them still interact with each other on a limited level?

I'm completely clueless, and I'm terribly sorry if I've just wasted everyone's time anyway....

--
Irayo