WasmerSharp icon indicating copy to clipboard operation
WasmerSharp copied to clipboard

ImportFunction that returns a string?

Open rygo6 opened this issue 3 years ago • 0 comments

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?

rygo6 avatar Aug 04 '21 06:08 rygo6