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

调用arkts函数有问题 #24

Closed
liujingxuan opened this issue Nov 7, 2024 · 6 comments
Closed

调用arkts函数有问题 #24

liujingxuan opened this issue Nov 7, 2024 · 6 comments
Labels
bug Something isn't working

Comments

@liujingxuan
Copy link

当参数为多个参数的时候,会出问题,比如, args是"string11","string22", 但是最后是:string11string22, undefine。所有参数会集中在第一个。
match module.call::<_, , ()>(&method, args) {
Ok(
) => qlog!(" successful"),
Err(e) => qlog!("failed: {:?}", e),
}

Copy link

github-actions bot commented Nov 7, 2024

@richerfu Please check this issue, thanks.

@richerfu
Copy link
Member

richerfu commented Nov 8, 2024

请给一个复现的 case @liujingxuan

@richerfu richerfu added the bug Something isn't working label Nov 8, 2024
@liujingxuan
Copy link
Author

好的好的,这个是我的arkts代码:
function updateOldHybrids(newData: string, oldKey: string) { console.log("arkts updateOldHybrids1 :" + newData); console.log("arkts updateOldHybrids2 :" + oldKey); }

这个是我大rust代码:
`pub fn call_arkts_func_no_return(method:String, args:Vec){
let global_runtime_clone = Arc::clone(&GLOBAL_RUNTIME);
let mut runtime_guard = global_runtime_clone.lock().unwrap();
if runtime_guard.is_none() {
*runtime_guard = Some(ArkRuntime::new().unwrap());
}
let runtime = runtime_guard.as_ref().unwrap();
let module = runtime.load_with_info("Manager","com.harm.hos/entry").unwrap();
let js_strings: Vec = args.iter()
.map(|arg| runtime.env.create_string(arg).unwrap())
.collect();
// let ret:JsString = module.call(&method, js_strings).unwrap();

match module.call::<_, , ()>(&method, args) {
Ok(
) => log!("call_arkts_func_no_return successful"),
Err(e) => log!("call_arkts_func_no_return failed: {:?}", e),
}
`
pub fn updata_old_hybrids(json: &String, old_key: &str) {
let args = vec![String::from(json), old_key.to_string()];
call_arkts_func_no_return("updateOldHybrids".to_string(), args);
}

两个string传进去后,得到的现象就是arkts的数据,第一个有两个字符串拼接的,比如str1,str2,但是第二个没有。不知道哪里写的有问题。我也深入到源码分析了,没看出来。多谢啊 @richerfu

@richerfu
Copy link
Member

richerfu commented Nov 8, 2024

多参数使用元组传递 Vec 会被转成数组

@liujingxuan
Copy link
Author

有没有什么好的方法呢,传入多个参数呢

@richerfu
Copy link
Member

richerfu commented Nov 8, 2024

@richerfu richerfu closed this as completed Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants