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"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "baff4b617f7df3d896f97fe922b64817f6cd9a756bb81d40f8883f2f66dcb401"
|
checksum = "baff4b617f7df3d896f97fe922b64817f6cd9a756bb81d40f8883f2f66dcb401"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libc"
|
||||||
|
version = "0.2.147"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "nmsrust"
|
name = "nmsrust"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"lexopt",
|
"lexopt",
|
||||||
|
"libc",
|
||||||
]
|
]
|
||||||
|
@ -11,4 +11,5 @@ crate-type = ["staticlib"]
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
lexopt = "0.3.0"
|
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::*;
|
use lexopt::prelude::*;
|
||||||
|
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
pub struct Args {
|
pub(crate) struct Args {
|
||||||
version: bool,
|
pub(crate) version: bool,
|
||||||
clear_screen: bool,
|
pub(crate) clear_screen: bool,
|
||||||
foreground: Option<OsString>,
|
pub(crate) foreground: Option<OsString>,
|
||||||
autodecrypt: bool,
|
pub(crate) autodecrypt: bool,
|
||||||
mask_blanks: 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 parser = lexopt::Parser::from_env();
|
||||||
|
|
||||||
let mut args = Args::default();
|
let mut args = Args::default();
|
||||||
|
15
src/lib.rs
15
src/lib.rs
@ -1,6 +1,21 @@
|
|||||||
mod args;
|
mod args;
|
||||||
|
|
||||||
|
use libc::{c_void, c_int};
|
||||||
|
|
||||||
|
extern {
|
||||||
|
fn nmseffect_set_autodecrypt(_: c_int) -> c_void;
|
||||||
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn rust_main() {
|
pub extern "C" fn rust_main() {
|
||||||
println!("Hello from rust");
|
println!("Hello from rust");
|
||||||
|
|
||||||
|
let args = args::parse_arguments().unwrap();
|
||||||
|
|
||||||
|
if args.autodecrypt {
|
||||||
|
unsafe {
|
||||||
|
nmseffect_set_autodecrypt(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
println!("{:?}", args);
|
||||||
}
|
}
|
||||||
|
@ -32,9 +32,6 @@ int main(int argc, char *argv[])
|
|||||||
case 'f':
|
case 'f':
|
||||||
nmseffect_set_foregroundcolor(optarg);
|
nmseffect_set_foregroundcolor(optarg);
|
||||||
break;
|
break;
|
||||||
case 'a':
|
|
||||||
nmseffect_set_autodecrypt(1);
|
|
||||||
break;
|
|
||||||
case 's':
|
case 's':
|
||||||
nmseffect_set_maskblank(1);
|
nmseffect_set_maskblank(1);
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user