Skip to content

ImportFunction that returns a string? #19

@rygo6

Description

@rygo6

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions