All pastes #971436 Raw Edit

Stuff

public text v1 · immutable
·published 2008-04-04 18:59 UTC
rendered paste body
class LuaEntityFactory : public IEntityFactory
{
public:
    IServerNetworkable *Create( const char *pClassName )
    {
        luabind::object obj = call_function( g_LuaState, pClassName );
        if ( !obj )
        {
            // deal with it
            return NULL;
        }
        IServerNetworkable* pEnt;
        try {
            IServerNetworkable* pEnt = luabind::object_cast<IServerNetworkable*>(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 );
}