   [Lua] designing an event system...
  Well, hello again.Right now I'm working at integrating lua into my objects through 'event functions' - each object (and derived object) can define a method that checks to see if a given function exists within the script and calls it if possible. I'd like to be able to omit any number of these functions from within the script so that the event is simply not processed instead of requiring empty functions in the lua file. This also improves portability somewhat by allowing derived classes to use scripts from their base class, etc. Keep in mind that each object is maintaining it's own lua state as well.Now, I know I can check for the existence of any given function/variable in luabind by doing something like:if ( luabind::globals(myLuaState)["eventFunc_name"] ){    //Pseudo-pseudo code but you get the idea    luaL_doString(eventFunc_name + "()");}But to me that seems excessive, especially considering the event functions themselves are more or less static and that it could be processed at worst every frame.So, I thought about checking for the event functions on creation and storing the result in a boolean. That would work, but it does mean I need to store a boolean for each new event type which probably isn't all that much more work considering the C++ event functions are already hard coded (for now). I could also store all the globals in a std::set regardless of whether they're important or not and use std::set::find to check if something exists, which eliminates the booleans but is probably somewhat slower, although the data can most likely be cached if needed.My actual question was is there a better way to handle this? Or should I even bother? I'm pretty brain-dead at the moment and still reasonably new to embedding lua, so any advice what so ever would be appreciated.Thanks!   
  It sounds like what you're really after here is a table, for each class of object in the system, which explains which function to use for which event.The obvious way to do this is to do it the way C++ does it.Have a constructor function inside your lua file. So, presumably you have a directory or tree full of "foo.lua" files. Each of which implements a class of object, so you have "bottle.lua" and "book.lua".Inside each of them you have a "dropped()", "thrown()" method for the events.You could add a "_construct()" method which populates a table of connections.So, in book.lua, the _construct() method might assign "thrown=pages_fall_out" and omit dropped because you want the default method used.In bottle.lua the method assigns "dropped=breaks" and "thrown=breaks".You could compile in all the baseclass code into the state as well (meaning bottle.lua can call methods in object.lua by itself) but you'll need to sort out a naming convention - perhaps bottle_construct() calls object_construct() and then fills in thrown = object_break()Another thing this gives you is that your objects can rewrite their structure as the game progresses. The player can try and bless a sword, the sword can ask if they're in the right location and if so, the sword can change which method is called when you try and attack something with it.So after you call the constructor, you can get the table out of the state and ask for entries from it in C++...So when you get an event, you go look to see if there's an entry in there for it. You've basically just built a Lua equivalent of the vtable.Even better, what you store in the table are not the NAMES of Lua functions, they can actually be function references, saving a whole bundle of time doing compilations.This means that the events which are called, and the way in which objects handle them is completely removed from the code which does the bindings.