Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: Like a script host #46

Open
Astn opened this issue Nov 2, 2021 · 5 comments
Open

Question: Like a script host #46

Astn opened this issue Nov 2, 2021 · 5 comments
Labels

Comments

@Astn
Copy link

Astn commented Nov 2, 2021

I've done a little script hosting before for things such as games, and rules engines, and I really like the idea of being able to do the same thing with webassembly, because the user could pick from various languages that compile to web-assembly.

I'm hoping this would be an incredible performance improvement over script hosting.

I feel like I would need to define some interfaces, and hook functions and then somehow let those be defined in web-assembly so they could be used by script clients to compile against.

I see that interface types is still a proposal and might solve this issue.

Do you have any advice on how this could be done right now? I'd love an example if you have a little time on a setup where we are able to pass an object, or struct to a standard named handler on the webAssembly side, and then deal with the result on the host side.

The specific use case I'm thinking of at the moment would be for supporting user defined functions similar to SQL server stored procedures, or UDFs inside a database engine.

Thoughts?

@furesoft
Copy link

furesoft commented Nov 4, 2021

I am currently writing a wrapper to allow this. But you could do it by your own. You need an interface between some types of .net and webassembly.

when you add a normal .net method eg. WriteLine(String) the wrapper adds a for me called a "grain". It adds a ptr and length parameter for the string to the webassembly function. after the call the result do the same but reverse.

@RyanLamansky
Copy link
Owner

JIT-based WebAssembly implementations (including this project and the ones built into browsers) are very fast and would outperform most traditional script engines.

This project currently only covers WebAssembly 1.0, which only has 4 types: 32-bit and 64-bit flavors of integer and floating point. Fortunately, most data structures can be broken down into these (a byte is 1/4th of an int, for example, and boolean is 0 vs. non-zero int). Memory is essentially a long byte array and you can reference things within using their integer address.

It would be inconvenient to break down complex .NET types every time, so wrappers (as suggested by @furesoft) and other helpers would be required. The WASM spec allows for importing and exporting memory, functions, and "global" variables, which are all the building blocks you need to do complicated things, as we've seen by all the things already being done with WASM.

@furesoft
Copy link

furesoft commented Nov 5, 2021

@Astn I have implemented something to import static functions easily. I could give you the source, if you want.

I also want to implement to be able to import struct values

@Astn
Copy link
Author

Astn commented Nov 5, 2021

@furesoft That would be great, thanks!

@furesoft
Copy link

furesoft commented Nov 5, 2021

@Astn https://github.com/furesoft/Slithin/tree/develop/Slithin.ModuleSystem

You can integrate it in your library

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants