Re: Overriding property setters

"Thomas Nelson" <[email protected]>
Newsgroups gmane.comp.lang.lua.bind.user
Message-ID <075D9B4B8D774B5DAAD558F399B3DBAD@Spawn>
Thanks Jim!  That turns the trick beautifully.

The code ends up looking like this:

template <typename ValType_tt>
void ProxyTypeBase::setPropertyOrPolicy(const std::string &strName, 
    const luabind::object &obj)
{
    boost::optional<ValType_tt> val;

    val = luabind::object_cast_nothrow<ValType_tt>(obj);
    if (val)
    {
        setProperty<ValType_tt>(strName, *val);
        return;
    }
    else
    {
        boost::optional<ControllerPolicy<ValType_tt> *>	policy;

        policy = luabind::object_cast_nothrow<ControllerPolicy<ValType_tt>
*>(obj);
        if (policy)
        {
            setPropertyPolicy(strName,
                static_cast<ControllerPolicy<ValType_tt> *>(*policy));
            return;
        }
    }
	
    std::stringstream strError;

    strError << "Property \"" << strName << "\" must be either " <<
        typeid(ValType_tt).name() << " or " << 
        typeid(ControllerPolicy<ValType_tt>).name();

    throw invalid_argument(strError.str());
}
--
Thomas Nelson  [email protected] 
--------------------------------------------------------------
"If you still have gas, you're not lost".
- French explorer Pierre Frontage.
(M.Frontage was so influential in the exploration of North America many
roads are still named after him.)

> -----Original Message-----
> From: James Porter [mailto:[email protected]]
> Sent: Wednesday, July 15, 2009 9:29 AM
> To: [email protected]
> Subject: Re: [luabind] Overriding property setters
> 
> Thomas Nelson wrote:
> > Is there a way to provide an alternate function binding for property
> > setters?
> 
> You could make your property setter take a luabind::object and then try
> to cast it with object_cast<T>() to the various types you want to handle.
> 
> - Jim




------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge  
This is your chance to win up to $100,000 in prizes! For a limited time, 
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize  
details at: http://p.sf.net/sfu/Challenge
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.