rendered paste bodyclass LuaEntityFactory : public IEntityFactory
{
public:
IServerNetworkable *Create( const char *pClassName )
{
luabind::object obj = call_function( g_LuaState, pClassName );
if ( !obj )
{
// deal with it
return NULL;
}
IBaseEntity* pEnt;
try {
pEnt = luabind::object_cast<IBaseEntity*>(obj);
} catch ( const luabind::cast_failed& e ) {
// deal with it
return NULL;
}
pEnt->PostConstructor();
return pEnt->NetworkProp();
}
void Destroy( IServerNetworkable *pNetworkable )
{
if ( pNetworkable )
{
pNetworkable->Release();
}
}
virtual size_t GetEntitySize()
{
return 0; // TODO: we could dispatch this to Lua somehow....
}
};
static LUA_LINK_ENTITY_TO_CLASS( const char* pClassName )
{
static LuaEntityFactory lua_entity_factory;
EntityFactoryDictionary()->InstallFactory( &lua_entity_factory, pClassName );
}