Now with increment and decrement
This commit is contained in:
@@ -14,7 +14,9 @@ pub mod ffi {
|
||||
|
||||
type Module;
|
||||
|
||||
fn decrement(self: Pin<&mut Module>);
|
||||
fn get_name(self: &Module) -> String;
|
||||
fn increment(self: Pin<&mut Module>);
|
||||
fn render_text(self: Pin<&mut Module>) -> String;
|
||||
fn set_key_text(self: Pin<&mut Module>, key_text: &String) -> ();
|
||||
fn strip_text(self: Pin<&mut Module>) -> String;
|
||||
|
||||
@@ -3,10 +3,18 @@
|
||||
namespace sword_rs {
|
||||
Module::Module(sword::SWModule* module) : module(module) { }
|
||||
|
||||
void Module::decrement() {
|
||||
this->module->decrement();
|
||||
}
|
||||
|
||||
rust::String Module::get_name() const {
|
||||
return rust::String(this->module->getName());
|
||||
}
|
||||
|
||||
void Module::increment() {
|
||||
this->module->increment();
|
||||
}
|
||||
|
||||
rust::String Module::render_text() {
|
||||
return std::string(
|
||||
(const char*) this->module->renderText()
|
||||
|
||||
@@ -13,8 +13,12 @@ namespace sword_rs {
|
||||
public:
|
||||
Module(sword::SWModule* module);
|
||||
|
||||
void decrement();
|
||||
|
||||
rust::String get_name() const;
|
||||
|
||||
void increment();
|
||||
|
||||
rust::String render_text();
|
||||
|
||||
void set_key_text(const rust::String& keyText);
|
||||
|
||||
+9
-5
@@ -9,10 +9,14 @@ fn main() {
|
||||
let random_number: i32 = rand::rng().random_range(1..=20);
|
||||
let random_number_str = format!("John.3.{}", random_number);
|
||||
module.set_key_text(&random_number_str);
|
||||
println!(
|
||||
"Text John 3:{} is \"{}\"",
|
||||
random_number,
|
||||
module.render_text()
|
||||
);
|
||||
for i in 0..10 {
|
||||
module.increment();
|
||||
println!(
|
||||
"Text John 3:{} is \"{}\"",
|
||||
random_number + i,
|
||||
module.render_text()
|
||||
);
|
||||
}
|
||||
println!("==============================");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,10 +10,18 @@ impl Module {
|
||||
Self { module: module }
|
||||
}
|
||||
|
||||
pub fn decrement(&mut self) {
|
||||
self.module.pin_mut().decrement();
|
||||
}
|
||||
|
||||
pub fn get_name(&self) -> String {
|
||||
self.module.get_name()
|
||||
}
|
||||
|
||||
pub fn increment(&mut self) {
|
||||
self.module.pin_mut().increment();
|
||||
}
|
||||
|
||||
pub fn render_text(&mut self) -> String {
|
||||
self.module.pin_mut().render_text()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user