Coder Social home page Coder Social logo

Comments (12)

dcodeIO avatar dcodeIO commented on May 12, 2024

That's right, wildcard exports and imports are not handled yet. Going to take a look and marking this issue as enhancement until then :)

from assemblyscript.

torch2424 avatar torch2424 commented on May 12, 2024

Awesome, thank you! :)

from assemblyscript.

gustavomick avatar gustavomick commented on May 12, 2024

Any workaround in the meantime?

from assemblyscript.

dcodeIO avatar dcodeIO commented on May 12, 2024

Normal imports and exports should work, as should imports and exports of entire namespaces. Just the wildcard isn't implemented yet.

from assemblyscript.

gustavomick avatar gustavomick commented on May 12, 2024

Thanks what if I need to import a wasm,eg. compiled code from c++ to wasm then importing that to ts. Any viable way to make that work? Thanks.

from assemblyscript.

dcodeIO avatar dcodeIO commented on May 12, 2024

Linking wasms is a bit tricky currently. What I have in mind for this case is that the compiler could be provided with a base wasm, appending any additional code to it. would that work for your use case?

Other than that there are tools like wasm-merge that can combine multiple wasms into one, resolving imports agains exports. That could already work today, but last time I checked this didn't seem to work reliably.

from assemblyscript.

gustavomick avatar gustavomick commented on May 12, 2024

@dcodeIO thanks sorry about the late answer, i currently on vacations :).

i was thinking about creating empty interfaces/type/mocks on typescript, using them from my main typescript code, then compiling to wasm and then replacing those mocks with real wasm implementations (that were previously compiled from c++ to wasm). that make sense? although not sure how to do that. if you have any suggestion will be helpful thanks.

from assemblyscript.

dcodeIO avatar dcodeIO commented on May 12, 2024

That should be possible as well. On the AssemblyScript side, you'd then have a .ts file that declares the exported interface of the other wasm, which the AS module then imports. On the JS side, you'd then provide the other wasm for this import and it should just work.

declare namespace MyCppModule {
  export function someFunction(): i32;
}

// use it
MyCppModule.someFunction();
...

And simply give { MyCppModule: myCppModuleInstanceExports } as an import when instantiating the AS module.

from assemblyscript.

gustavomick avatar gustavomick commented on May 12, 2024

@dcodeIO im missing something in here, how do i compile so my typescriptfile.wasm get linked to my cppfile.wasm file instead of the linked to the ts mock?
i thought i would had to create a workaround script to merge them, replacing the mock with the real implementation, how that part should work?

from assemblyscript.

dcodeIO avatar dcodeIO commented on May 12, 2024

Merging, or real linking, might be more complicated because a linker will have to move around data segments, table elements etc. and update their indexes where used. There is wasm-merge which might, or might not, help.

My example above was based on the assumption that you'd then have two WebAssembly modules, with the exports of your cpp module being provided as imports to the typescript module.

from assemblyscript.

gustavomick avatar gustavomick commented on May 12, 2024

ok ill try to read about this, thanks 👍

from assemblyscript.

torch2424 avatar torch2424 commented on May 12, 2024

Closed by #489 😄

from assemblyscript.

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.