Coder Social home page Coder Social logo

Comments (6)

brendandahl avatar brendandahl commented on May 30, 2024 1

As for why const std::shared_ptr works, that will be a const reference which has a helper static WireType toWireType(const T& v) { for sending it to JS so it works.

from emscripten.

brendandahl avatar brendandahl commented on May 30, 2024

Embind generally doesn't like raw pointers being sent across since it unclear who owns the object. Can you instead use a std::shared_ptr?

from emscripten.

JankingWonn avatar JankingWonn commented on May 30, 2024

Embind generally doesn't like raw pointers being sent across since it unclear who owns the object. Can you instead use a std::shared_ptr?

Thank you @brendandahl. I'm also bothered by this issue. When I tried to change the function to void passConstObj(const std::shared_ptr<PolyDerived> o), the problem was solved.

But I have a question, ignoring the question of whether embind likes the original pointer preference (because it doesn't affect the compilation of PolyDerived* type arguments), why const PolyDerived* can't compile the same const argument, but const std::shared_ptr<PolyDerived> can

from emscripten.

brendandahl avatar brendandahl commented on May 30, 2024

I misremembered, I thought val::call had the same restrictions as bind.h function bindings where you must explicitly pass allow_raw_pointers if you want to use pointers as arguments. val::call doesn't appear to have that restriction, so yes it is strange that const pointers don't work. I'm not the original author of this code so I'm not sure what the intent was there or if it was just an oversight.

It seems reasonable to automatically remove the const in the val.h code.

from emscripten.

brendandahl avatar brendandahl commented on May 30, 2024

There was a relevant discussion previously #7292 but nothing ever came of it.

from emscripten.

JankingWonn avatar JankingWonn commented on May 30, 2024

Thanks @brendandahl again. Although I didn't figure it out thoroughly, at least there was a solution.

from emscripten.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.