fn print_out(d : Js_string) -> Unit = "spectest" "print_char"
pub fn test_print() -> Unit {
let x = Js_string::new("Hello, ")
let y = Js_string::new("Js_string!")
let z = x + y
z.log()
print_out(z)
}
new# [ 0, 7 ] * 7 is the len("Hello, ") of x
new# [ 0, 10 ] * 10 is the len("Js_string!") of y
a# [ 0, 7 ] [ 0, 10 ] * append x and y
log# [ '0,70,10' ] * z.log()
#@ 0,70,10 * spectest.print_char(z)
??? whats the "0" in that.
when i didnt set the importObject with js_string :{new ,log,append …}
i got some error of that
Error loading WebAssembly module: [LinkError: WebAssembly.instantiate(): Import #5 module="js_string" function="empty": function import requires a callable]
empty or new or log and append
And, despite searching in repositories on GitHub and taolun.moonbitlang.cn, I haven’t found something about. I am in need of technical assistance, even though I have already obtained alternative solutions.
This is my solution, for your reference.
It is a bit complicated and primitive.
moonbit
fn newJs_string()-> Int = "Js_stringMAp" "newJs_string"
fn appendJs_string(n:Int,ch:Int)-> Unit = "Js_stringMAp" "appendJs_string"
fn endJs_string(n:Int)-> Unit = "Js_stringMAp" "endJs_string"
fn printJs_string(n:Int)-> Unit = "Js_stringMAp" "printJs_string"
pub fn test_print()-> Unit {
let newStringFlag : Int = newJs_string()
let moonbitString = "<《moonbit》_001\nhi~ here\r\n___something\ris".to_array()
let moonbitStringLength = moonbitString.length()
let mut i = 0
while i < moonbitStringLength {
appendJs_string(newStringFlag,moonbitString[i].to_int())
i+=1
} else {
endJs_string(newStringFlag)
}
printJs_string(newStringFlag)
println("\n\nwhats_up")
}