* @param setter Setter for variable (Pass 0 to prevent write access)
*
*/
- template<class Var>
+ template<class Ret, class Param>
Ghost& member( const std::string& field,
- Var (raw_type::*getter)() const,
- void (raw_type::*setter)(typename boost::call_traits<Var>::param_type) = 0 )
+ Ret (raw_type::*getter)() const,
+ void (raw_type::*setter)(Param) )
{
member_t m;
if( getter )
{
- typedef typename boost::call_traits<Var>::param_type param_type;
+ typedef typename boost::call_traits<Ret>::param_type param_type;
naRef (*to_nasal_)(naContext, param_type) = &nasal::to_nasal;
// Getter signature: naRef(naContext, raw_type&)
if( setter )
{
- Var (*from_nasal_)(naContext, naRef) = &nasal::from_nasal;
+ typename boost::remove_reference<Param>::type
+ (*from_nasal_)(naContext, naRef) = &nasal::from_nasal;
// Setter signature: void(naContext, raw_type&, naRef)
m.setter = boost::bind(setter, _2, boost::bind(from_nasal_, _1, _3));
return member(field, m.getter, m.setter);
}
+ /**
+ * Register a read only member variable.
+ *
+ * @param field Name of member
+ * @param getter Getter for variable
+ */
+ template<class Ret>
+ Ghost& member( const std::string& field,
+ Ret (raw_type::*getter)() const )
+ {
+ return member<Ret, Ret>(field, getter, 0);
+ }
+
/**
* Register a write only member variable.
*
Ghost& member( const std::string& field,
void (raw_type::*setter)(Var) )
{
- return member<Var>(field, 0, setter);
+ return member<Var, Var>(field, 0, setter);
}
/**
std::string getString() const { return ""; }
void setString(const std::string&) {}
+
+ std::string var;
+ const std::string& getVar() const { return var; }
+ void setVar(const std::string v) { var = v; }
};
struct Derived:
public Base
Ghost<BasePtr>::init("BasePtr")
.method<&Base::member>("member")
- .member("str", &Base::getString, &Base::setString);
+ .member("str", &Base::getString, &Base::setString)
+ .member("var_r", &Base::getVar)
+ .member("var_w", &Base::setVar)
+ .member("var", &Base::getVar, &Base::setVar);
Ghost<DerivedPtr>::init("DerivedPtr")
.bases<BasePtr>()
.member("x", &Derived::getX, &Derived::setX)
}
//----------------------------------------------------------------------------
- std::string from_nasal_helper(naContext c, naRef ref, std::string*)
+ std::string from_nasal_helper(naContext c, naRef ref, const std::string*)
{
naRef na_str = naStringValue(c, ref);
return std::string(naStr_data(na_str), naStr_len(na_str));
}
//----------------------------------------------------------------------------
- Hash from_nasal_helper(naContext c, naRef ref, Hash*)
+ Hash from_nasal_helper(naContext c, naRef ref, const Hash*)
{
if( !naIsHash(ref) )
throw bad_nasal_cast("Not a hash");
}
//----------------------------------------------------------------------------
- String from_nasal_helper(naContext c, naRef ref, String*)
+ String from_nasal_helper(naContext c, naRef ref, const String*)
{
if( !naIsString(ref) )
throw bad_nasal_cast("Not a string");
/**
* Simple pass through for unified handling also of naRef.
*/
- inline naRef from_nasal_helper(naContext, naRef ref, naRef*) { return ref; }
+ inline naRef from_nasal_helper(naContext, naRef ref, const naRef*)
+ { return ref; }
/**
* Convert Nasal string to std::string
*/
- std::string from_nasal_helper(naContext c, naRef ref, std::string*);
+ std::string from_nasal_helper(naContext c, naRef ref, const std::string*);
/**
* Convert a Nasal string to an SGPath
*/
- SGPath from_nasal_helper(naContext c, naRef ref, SGPath*);
+ SGPath from_nasal_helper(naContext c, naRef ref, const SGPath*);
/**
* Convert a Nasal hash to a nasal::Hash
*/
- Hash from_nasal_helper(naContext c, naRef ref, Hash*);
+ Hash from_nasal_helper(naContext c, naRef ref, const Hash*);
/**
* Convert a Nasal string to a nasal::String
*/
- String from_nasal_helper(naContext c, naRef ref, String*);
+ String from_nasal_helper(naContext c, naRef ref, const String*);
/**
* Convert a Nasal number to a C++ numeric type
typename boost::enable_if< boost::is_arithmetic<T>,
T
>::type
- from_nasal_helper(naContext c, naRef ref, T*)
+ from_nasal_helper(naContext c, naRef ref, const T*)
{
naRef num = naNumValue(ref);
if( !naIsNum(num) )
* Convert a Nasal vector to a std::vector
*/
template<class T>
- std::vector<T> from_nasal_helper(naContext c, naRef ref, std::vector<T>*)
+ std::vector<T>
+ from_nasal_helper(naContext c, naRef ref, const std::vector<T>*)
{
if( !naIsVector(ref) )
throw bad_nasal_cast("Not a vector");
*/
template<class Vec2>
typename boost::enable_if<is_vec2<Vec2>, Vec2>::type
- from_nasal_helper(naContext c, naRef ref, Vec2*)
+ from_nasal_helper(naContext c, naRef ref, const Vec2*)
{
std::vector<double> vec =
from_nasal_helper(c, ref, static_cast<std::vector<double>*>(0));