lib.rs 996 B

12345678910111213141516171819202122232425262728293031323334
  1. /*
  2. * Copyright (c) 2006-2025, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author notes
  8. * 2025-10-10 foxglove load library example
  9. * 2025-10-29 foxglove Updated to demonstrate new modular macro interface
  10. */
  11. #![no_std]
  12. extern crate alloc;
  13. use rt_macros::msh_cmd_export;
  14. use rt_rust::println;
  15. use rt_rust::get_libfn;
  16. use core::ffi::{c_int, c_char};
  17. use rt_rust::param::Param;
  18. #[msh_cmd_export(name = "rust_dl_demo", desc = "Rust dynamic library demo")]
  19. fn main(_param: Param) {
  20. println!("\n=== Dynamic Library Demo ===");
  21. get_libfn!("/hello.mo", "main", my_hello, ());
  22. my_hello();
  23. get_libfn!("/libmylib.mo", "rust_mylib_add", my_add, c_int, a: c_int, b: c_int);
  24. let s = my_add(15, 20);
  25. println!("my_add(15, 20) = {}", s);
  26. get_libfn!("/libmylib.mo", "rust_mylib_println", my_println, (), s: *const c_char);
  27. my_println(b"rustlib: Hello World\0".as_ptr() as *const c_char);
  28. }