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

ImportFunction that returns a string? #19

Open
rygo6 opened this issue Aug 4, 2021 · 0 comments
Open

ImportFunction that returns a string? #19

rygo6 opened this issue Aug 4, 2021 · 0 comments

Comments

@rygo6
Copy link

rygo6 commented Aug 4, 2021

I am trying to implement an ImportFunction that returns a string but am failing to do so. Seems to just crash. Is this even possible?

This about how far I got:

    private void RunWASMTest()
    {
        Import getPlatformFunc = new Import("index", "getPlatformExtern", new ImportFunction((Func<InstanceContext, int>) GetPlatform));
        _memory = Memory.Create(minPages: 256, maxPages: 256);
        Import memoryImport = new Import("env", "memory", _memory);

        byte[] wasm = File.ReadAllBytes("AssemblyScript/optimized.wasm");
        
        Instance instance = new Instance(wasm, memoryImport, getPlatformFunc);
    }

    private int GetPlatform(InstanceContext ctx)
    {
        //Figure out code for how to write string to unmanaged memory here:
        return 0;
    }

Can ImportFunctions take Funcs like that?

How would I do this exactly of returning a string on an imported method call?

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

No branches or pull requests

1 participant