All pastes #971426 Raw Edit

Stuff

public text v1 · immutable
·published 2008-04-04 18:50 UTC
rendered paste body

class LuaEntityFactory : public IEntityFactory
{
public:
    static register( const char *pClassName )
    {
        EntityFactoryDictionary()->InstallFactory( this, pClassName );
    }

    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....
    }
};