From: Thomas Geymayer Date: Fri, 16 Nov 2012 11:24:47 +0000 (+0100) Subject: Nasal bindings: Always pass object by reference X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=1cbe271ad5fe7e262b9ca02b5c6bfc1e40890e6c;p=simgear.git Nasal bindings: Always pass object by reference --- diff --git a/simgear/canvas/elements/CanvasElement.cxx b/simgear/canvas/elements/CanvasElement.cxx index bc150fc2..be0903dc 100644 --- a/simgear/canvas/elements/CanvasElement.cxx +++ b/simgear/canvas/elements/CanvasElement.cxx @@ -108,6 +108,18 @@ namespace canvas } } + //---------------------------------------------------------------------------- + SGConstPropertyNode_ptr Element::getProps() const + { + return _node; + } + + //---------------------------------------------------------------------------- + SGPropertyNode_ptr Element::getProps() + { + return _node; + } + //---------------------------------------------------------------------------- bool Element::handleMouseEvent(const MouseEvent& event) { diff --git a/simgear/canvas/elements/CanvasElement.hxx b/simgear/canvas/elements/CanvasElement.hxx index d28baaec..547b3863 100644 --- a/simgear/canvas/elements/CanvasElement.hxx +++ b/simgear/canvas/elements/CanvasElement.hxx @@ -67,6 +67,9 @@ namespace canvas */ virtual void update(double dt); + SGConstPropertyNode_ptr getProps() const; + SGPropertyNode_ptr getProps(); + /** * Handle mouse event (transforms coordinates to local coordinate frame * and forwards event to #handleLocalMouseEvent) diff --git a/simgear/nasal/cppbind/Ghost.hxx b/simgear/nasal/cppbind/Ghost.hxx index 05c4fd4a..ddb2c1f5 100644 --- a/simgear/nasal/cppbind/Ghost.hxx +++ b/simgear/nasal/cppbind/Ghost.hxx @@ -210,8 +210,8 @@ namespace nasal typedef typename GhostTypeTraits::raw_type raw_type; typedef naRef (raw_type::*member_func_t)(naContext, int, naRef*); typedef naRef (*free_func_t)(raw_type&, naContext, int, naRef*); - typedef boost::function getter_t; - typedef boost::function setter_t; + typedef boost::function getter_t; + typedef boost::function setter_t; /** * A ghost member. Can consist either of getter and/or setter functions @@ -352,7 +352,7 @@ namespace nasal { naRef (*to_nasal_)(naContext, Var) = &nasal::to_nasal; - // Getter signature: naRef(naContext, raw_type*) + // Getter signature: naRef(naContext, raw_type&) m.getter = boost::bind(to_nasal_, _1, boost::bind(getter, _2)); } @@ -360,7 +360,7 @@ namespace nasal { Var (*from_nasal_)(naContext, naRef) = &nasal::from_nasal; - // Setter signature: void(naContext, raw_type*, naRef) + // Setter signature: void(naContext, raw_type&, naRef) m.setter = boost::bind(setter, _2, boost::bind(from_nasal_, _1, _3)); } @@ -567,7 +567,7 @@ namespace nasal return Ghost::getRawPtr( static_cast(naGhost_ptr(me)) ); } - static raw_type* requireObject(naContext c, naRef me) + static raw_type& requireObject(naContext c, naRef me) { raw_type* obj = Ghost::from_nasal(me); if( !obj ) @@ -578,7 +578,7 @@ namespace nasal getSingletonPtr()->_ghost_type.name ); - return obj; + return *obj; } /** @@ -596,7 +596,7 @@ namespace nasal */ static naRef call(naContext c, naRef me, int argc, naRef* args) { - return (requireObject(c, me)->*func)(c, argc, args); + return (requireObject(c, me).*func)(c, argc, args); } }; @@ -618,7 +618,7 @@ namespace nasal */ static naRef call(naContext c, naRef me, int argc, naRef* args) { - return func(*requireObject(c, me), c, argc, args); + return func(requireObject(c, me), c, argc, args); } }; @@ -690,7 +690,7 @@ namespace nasal if( member->second.func ) *out = nasal::to_nasal(c, member->second.func); else if( !member->second.getter.empty() ) - *out = member->second.getter(c, Ghost::getRawPtr(g)); + *out = member->second.getter(c, *Ghost::getRawPtr(g)); else return "Read-protected member"; @@ -711,7 +711,7 @@ namespace nasal if( member->second.setter.empty() ) naRuntimeError(c, "ghost: Write protected member: %s", key.c_str()); - member->second.setter(c, Ghost::getRawPtr(g), val); + member->second.setter(c, *Ghost::getRawPtr(g), val); } };