opened
kyranet
username_0
This is my first time using AssemblyScript and sadly, I don't have a lot of knowledge in this area, I spent a couple of hours dealing with an unreachable error but... this now compiles and runs... but always returns 0.

I have no idea why this happens, but any help on this will be greatly appreciated.
[Help Wanted] Always returns 0
issue
created
MaxGraey
username_1
How you call `levenshtein`function on host (js-side)? You should do something like this:
```ts
import { instantiateStreaming } from "assemblyscript/lib/loader";
const module = await instantiateStreaming(fetch('untouched.wasm'), {})
const a = module.newString('foo')
const b = module.newString('boo')
console.log(module.levenshtein(a, b))
```
comment
created
kyranet
username_0
TypeError: memory_allocate is not a function
    at Object.newString (D:\Repositories\Libraries\levenshtein-wasm\node_modules\assemblyscript\lib\loader\index.js:86:15)
    at levenshtein (D:\Repositories\Libraries\levenshtein-wasm,\index.js:15:44)
```
comment
created
MaxGraey
username_1
You should also export `memory` in your assembly file:
```ts
import "allocator/arena";
export { memory };

... 
```
comment
closed
kyranet
username_0
issue
created
kyranet
username_0
That worked! Thanks you very much! Fixed it with https://github.com/username_0/levenshtein-wasm/commit/9ac41069d72e0dff04fae8e095411654e07f777f, though I had to `// @ts-ignore` the `export { 
memory }`.

Also the typings for `ImportsObject` requires `env` to exist, I'll make a PR to AssemblyScript to make it optional 👍
comment
created
MaxGraey
username_1
Great!)
comment
created
MaxGraey
username_1
Also I highly recommend use `-O3` instead `--optimize` for maximum perf optimization [here](https://github.com/username_0/levenshtein-wasm/blob/master/package.json#L13)
comment
created
kyranet
username_0
Oh yes! The scaffolding wrote those scripts and placed `--optimize` and I forgot to replace it with `-O3` for performance. Surprisingly, that reduced the optimized `.wat`'s amount of lines of code by two (592 -> 590). Fixed in https://github.com/username_0/levenshtein-wasm/commit/92c30b4b52768b7c584bf5621daadd4526f6a1ae, thanks you for the suggestion!
comment