flat entity structure. bing.
the entity database is saved as a giant table called entity. as each entity is
parsed, its c++ object is created using a special constructor. the object should
build anything to do with itself at this point and add itself to the entity database
somehow.
now the file is fully parsed and all the entities exist.
next each entity is visited and calls its entityLink method. if the class wants to call into lua, it is up to it. if it needs to link to anything it can do it by searching the entity database, or calling lua to do it. an entities geoms are also accessible by entityGetNumGeoms and entityGetGeomAt. same goes for joints.
next each entity is visited and calls entityGetGeomAt to add all the geoms to the universe.
now it is time to configure the objects. each entity is visited and calls entityConfigure. this is done last on purpose to limit its power/abuse. typically this would call out to the object's lua function entityConfigure. that function has the name of an external text file and a dotted path to the name of a function to call to configure the object. that same file is the one used to populate with. it has a function entry to populate and one to configure.
all this business happens just like it does not with the template gbEntityClass trick. the difference is now it also registers gets and sets for lua to use for all of the the member variable. the class data is shared for between lua instances via __index tricks and the object is passed into it to make the call. maybe those should be stored in enitityConfig.*
saving
each entity is visited and the save method writes out the class with a custom handler as lua code. once again, it can call lua code if it wants. it probably should because there usually will be extra lua only variables lying around.
hmm. maybe the save method should always call the lua code and it is up to the lua to decide if it should call the c++. maybe that is a better way for everything. that way you don't have to do that template trick. the problem is you always end up calling
lua for the tick and that sucks. this also forces a class to always implement a lua version. if you lose the requirement then the lua could just be considered a file format.