-
-
Notifications
You must be signed in to change notification settings - Fork 647
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
how can I get strings from AS in JS #204
Comments
The loader provides utility to read a string from memory using its pointer (here: |
I read the loader documentation and try to use it withou success, index.ts const loader = require("@assemblyscript/loader");
const file = fs.readFileSync("aaa.wasm")
const fs = require("fs");
const myModule = loader.instatiateBuffer(file, {}); error
|
The loader is not on npm yet. For now, try: const loader = require("assemblyscript/lib/loader"); |
Wow, this worked!!! I found a mistake in the loader documentation, in the example is write Thanks so much for the help! ^^ |
Just posting my tests as reference/example to others adventurers programmers: index.ts import "allocator/tlsf";
export { memory };
export function say(hello: string): string {
return hello + " world"
}
export function add(a: i32, b: i32): i32 {
return a + b;
}
export function teste(): string {
let x = "ZZZZZZZZZZZZ"
return x;
}
export class X {
teste(): String {
return "Aew";
}
} index.js const loader = require("./assemblyscript/lib/loader/index");
const fs = require("fs");
const file = fs.readFileSync("index.wasm")
const lib = loader.instantiateBuffer(file, {});
const x = new lib.X()
console.log(' say :' , lib.getString(lib.say(lib.newString("oi"))))
console.log(' say :' , lib.getString(lib.say(lib.newString("hi"))))
console.log(' add :' , lib.add(100, 100))
console.log(' teste :' , lib.getString(lib.teste()))
console.log('method :' , lib.getString(x.teste())) compile and run
results
|
Closing this issue for now as it hasn't received any replies recently. Feel free to reopen it if necessary! |
I'm pretty new in AS and WA, and my current doubt is how I can get Strings and Arrays from JavaScript.
index.js
index.ts
copile and run with nodejs
$ asc assembly\index.ts -o aaa.wasm $ node index.js
what I get (I suspect these integers is memory pointer, I'm right?)
what I expect
Sorry for my poor english, I'm from Brazil and portuguese is my main language, and tks for the help.
The text was updated successfully, but these errors were encountered: