embind smart pointer issue

151 views
Skip to first unread message

Joshua Auerbach

unread,
Jan 11, 2016, 12:50:53 PM1/11/16
to emscripte...@googlegroups.com
Hi,

I am having an issue calling a function with a smart ptr to a derived
class as an argument, when that function expects a smart ptr to the base
class.

More specifically I have the following bindings

emscripten::class_<PositionObservable>("PositionObservable")
.smart_ptr<boost::shared_ptr<PositionObservable>
>("shared_ptr<PositionObservable>")
.function("getPosition", &getObservablePosition)
.function("getAttitude", &getObservableAttitude)
;

emscripten::class_<LightSource,
emscripten::base<PositionObservable>>("LightSource")
.smart_ptr<boost::shared_ptr<LightSource>
>("shared_ptr<LightSource>")
.function("getIntensity", &LightSource::getIntensity)
;

getObservablePosition and getObservableAttitude both take
boost::shared_ptr<PositionObservable> as their only argument (these are
wrapper functions that convert the relevant C++ types to something more
appropriate for JS)

but if I try to call getPosition on one of my LightSources in JS I get
the following error

"BindingError: Cannot convert argument of type shared_ptr<LightSource>
to parameter type shared_ptr<PositionObservable>"

Why does this not work properly and is there some way I can fix it?

Thanks so much!
Josh


--
Dr. Joshua E. Auerbach
Postdoctoral Researcher
Laboratory of Intelligent Systems
École Polytechnique Fédérale de Lausanne

Joshua Auerbach

unread,
Jan 11, 2016, 3:29:14 PM1/11/16
to emscripte...@googlegroups.com
It does work fine if I make those methods part of PositionObservable and
change the binding to

emscripten::class_<PositionObservable>("PositionObservable")
.smart_ptr<boost::shared_ptr<PositionObservable>
>("shared_ptr<PositionObservable>")
.function("getPosition", &PositionObservable::getPositionJS)
.function("getAttitude", &PositionObservable::getAttitudeJS)
;

but, why doesn't it work with the helper methods? I'd rather not
pollute the object model with things specific to the JS bindings.

Thanks!
Josh
Reply all
Reply to author
Forward
0 new messages