Call a method from rust
This commit is contained in:
parent
d7b402c764
commit
c280dbe716
7
Cargo.lock
generated
7
Cargo.lock
generated
@ -8,9 +8,16 @@ version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baff4b617f7df3d896f97fe922b64817f6cd9a756bb81d40f8883f2f66dcb401"
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.147"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3"
|
||||
|
||||
[[package]]
|
||||
name = "nmsrust"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"lexopt",
|
||||
"libc",
|
||||
]
|
||||
|
@ -11,4 +11,5 @@ crate-type = ["staticlib"]
|
||||
|
||||
[dependencies]
|
||||
lexopt = "0.3.0"
|
||||
libc = "0.2.147"
|
||||
|
||||
|
14
src/args.rs
14
src/args.rs
@ -3,15 +3,15 @@ use std::ffi::OsString;
|
||||
use lexopt::prelude::*;
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct Args {
|
||||
version: bool,
|
||||
clear_screen: bool,
|
||||
foreground: Option<OsString>,
|
||||
autodecrypt: bool,
|
||||
mask_blanks: bool,
|
||||
pub(crate) struct Args {
|
||||
pub(crate) version: bool,
|
||||
pub(crate) clear_screen: bool,
|
||||
pub(crate) foreground: Option<OsString>,
|
||||
pub(crate) autodecrypt: bool,
|
||||
pub(crate) mask_blanks: bool,
|
||||
}
|
||||
|
||||
pub fn parse_arguments() -> Result<Args, lexopt::Error> {
|
||||
pub(crate) fn parse_arguments() -> Result<Args, lexopt::Error> {
|
||||
let mut parser = lexopt::Parser::from_env();
|
||||
|
||||
let mut args = Args::default();
|
||||
|
15
src/lib.rs
15
src/lib.rs
@ -1,6 +1,21 @@
|
||||
mod args;
|
||||
|
||||
use libc::{c_void, c_int};
|
||||
|
||||
extern {
|
||||
fn nmseffect_set_autodecrypt(_: c_int) -> c_void;
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn rust_main() {
|
||||
println!("Hello from rust");
|
||||
|
||||
let args = args::parse_arguments().unwrap();
|
||||
|
||||
if args.autodecrypt {
|
||||
unsafe {
|
||||
nmseffect_set_autodecrypt(1);
|
||||
}
|
||||
}
|
||||
println!("{:?}", args);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user