X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fnasal%2Fcppbind%2FGhost.hxx;h=d2a5d22c9906b80610750537961cb6f4720706ad;hb=46442ef50c5a2b7c8e41e5c025f86c1cd35e6e15;hp=6a8ccfb8bf4a85c16659ea033fa3aedd73efd379;hpb=2f0dfc4d7463d24b7c36f81f47bb8167192fed88;p=simgear.git diff --git a/simgear/nasal/cppbind/Ghost.hxx b/simgear/nasal/cppbind/Ghost.hxx index 6a8ccfb8..d2a5d22c 100644 --- a/simgear/nasal/cppbind/Ghost.hxx +++ b/simgear/nasal/cppbind/Ghost.hxx @@ -26,6 +26,7 @@ #include #include +#include #include #include #include @@ -229,8 +230,16 @@ namespace nasal args(args) {} + /** + * Get the argument with given index if it exists. Otherwise returns the + * passed default value. + * + * @tparam T Type of argument (converted using ::from_nasal) + * @param index Index of requested argument + * @param def Default value returned if too few arguments available + */ template - T get(size_t index, const T& def = T()) const + T getArg(size_t index, const T& def = T()) const { if( index >= argc ) return def; @@ -238,8 +247,12 @@ namespace nasal return from_nasal(c, args[index]); } + /** + * Get the argument with given index. Raises a Nasal runtime error if there + * are to few arguments available. + */ template - T require(size_t index) const + T requireArg(size_t index) const { if( index >= argc ) naRuntimeError(c, "Missing required arg #%d", index); @@ -445,12 +458,13 @@ namespace nasal template Ghost& member( const std::string& field, Var (raw_type::*getter)() const, - void (raw_type::*setter)(Var) = 0 ) + void (raw_type::*setter)(typename boost::call_traits::param_type) = 0 ) { member_t m; if( getter ) { - naRef (*to_nasal_)(naContext, Var) = &nasal::to_nasal; + typedef typename boost::call_traits::param_type param_type; + naRef (*to_nasal_)(naContext, param_type) = &nasal::to_nasal; // Getter signature: naRef(naContext, raw_type&) m.getter = boost::bind(to_nasal_, _1, boost::bind(getter, _2)); @@ -616,7 +630,6 @@ namespace nasal return Ghost::getPtr( naGhost_ptr(me) ); // Now if it is derived from a ghost (hash with ghost in parent vector) - // TODO handle recursive parents else if( naIsHash(me) ) { naRef na_parents = naHash_cget(me, const_cast("parents")); @@ -632,8 +645,9 @@ namespace nasal parent != parents.end(); ++parent ) { - if( isBaseOf(naGhost_type(*parent)) ) - return Ghost::getPtr( naGhost_ptr(*parent) ); + pointer ptr = fromNasal(c, *parent); + if( ptr ) + return ptr; } }