Skip to content

[help] Get return types? #728

Closed
Closed
@pfortini

Description

@pfortini

I have the following functions on index.ts file:

export function str(): string {
  return "string";
}

export function n32(): i32 {
  return 1
}


export function r32(): f32 {
  return 1.2;
}

export function aStr(): Array<String> {
  return ["a", "b"];
}

export function aN(): Array<i32> {
  return [1, 2];
}

export function aR(): Array<f32> {
  return [1.1, 2.2];
}

export function truth(): bool {
  return true;
}

and I'd like to be able to tell, from my code on Go, what is the return type of the called function. My function on Go looks like this:

func runCode(funcName string) {
	raw, err := ioutil.ReadFile("optimized.wasm")
	if err != nil {
		fmt.Println(err)
	}

	r := new(Resolver)
	vm, err := exec.NewVirtualMachine(raw, exec.VMConfig{}, r, nil)
	if err != nil {
		return
	}

	entryID, ok := vm.GetFunctionExport(funcName)
	if !ok {
		fmt.Println("function not found")
	}

	ret, err := vm.Run(entryID)
	if err != nil {
		vm.PrintStackTrace()
		fmt.Println(err)
	}

	fmt.Println("return:", ret)
}

The problem I'm facing is that ret is sometimes a memory position, sometimes an int32, sometimes a big number (float on IEEE 754 representation). Is there any way to dynamically tell what am I going to receive, so I can properly read it from memory?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions