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

No exported functions #97

Open
euforic opened this issue Dec 13, 2019 · 1 comment
Open

No exported functions #97

euforic opened this issue Dec 13, 2019 · 1 comment

Comments

@euforic
Copy link

euforic commented Dec 13, 2019

after fa85caf was merged I am now getting an panic message that infers no exported functions exist panic: runtime error: index out of range [51] with length 0 my execution code is almost a 1 to 1 duplicate of the projects main.go

entryID, ok := vm.GetFunctionExport(w.context.action)
	if !ok {
		return errors.New("missing 'run' entry function")
	}

	// If any function prior to the entry function was declared to be
	// called by the module, run it first.
	if vm.Module.Base.Start != nil {
		startID := int(vm.Module.Base.Start.Index)
		_, err := vm.Run(startID)
		if err != nil {
			vm.PrintStackTrace()
			return err
		}
	}

	// Run the WebAssembly module's entry function.
	if _, err := vm.Run(entryID); err != nil {
		vm.PrintStackTrace()
		return err
	}
@brynbellomy
Copy link

Bump, also having this issue. My code is:

	bs, err := ioutil.ReadFile("./build/optimized.wasm")
	if err != nil {
		panic(err)
	}

	vm, err := wasm.NewVirtualMachine(bs, wasm.VMConfig{
		DefaultMemoryPages:   128,
		DefaultTableSize:     65536,
		DisableFloatingPoint: true,
	}, &Resolver{}, nil)
	if err != nil { // if the wasm bytecode is invalid
		panic(err)
	}

	fmt.Println(vm.Module.Base.Export.Entries)
	fmt.Println()
	fmt.Println(vm.FunctionCode)

	entryID, ok := vm.GetFunctionExport("add") // can be changed to your own exported function
	if !ok {
		panic("entry function not found")
	}
	fmt.Println(entryID)

	ret, err := vm.Run(entryID, int64(27), int64(46))
	if err != nil {
		vm.PrintStackTrace()
		panic(err)
	}
	fmt.Printf("return value = %d\n", ret)

...and my AssemblyScript file is:

export function add(a: i32, b: i32): i32 {
    return a + b
}

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

2 participants