From c280dbe71635aa2af889624e167a2b328fe1df60 Mon Sep 17 00:00:00 2001 From: Greg Shuflin Date: Sun, 23 Jul 2023 03:14:38 -0700 Subject: [PATCH] Call a method from rust --- Cargo.lock | 7 +++++++ Cargo.toml | 1 + src/args.rs | 14 +++++++------- src/lib.rs | 15 +++++++++++++++ src/nms.c | 3 --- 5 files changed, 30 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1dcda70..7e5b500 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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", ] diff --git a/Cargo.toml b/Cargo.toml index 9b816d8..5b5d785 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,4 +11,5 @@ crate-type = ["staticlib"] [dependencies] lexopt = "0.3.0" +libc = "0.2.147" diff --git a/src/args.rs b/src/args.rs index 5747380..86f0f53 100644 --- a/src/args.rs +++ b/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, - autodecrypt: bool, - mask_blanks: bool, +pub(crate) struct Args { + pub(crate) version: bool, + pub(crate) clear_screen: bool, + pub(crate) foreground: Option, + pub(crate) autodecrypt: bool, + pub(crate) mask_blanks: bool, } -pub fn parse_arguments() -> Result { +pub(crate) fn parse_arguments() -> Result { let mut parser = lexopt::Parser::from_env(); let mut args = Args::default(); diff --git a/src/lib.rs b/src/lib.rs index bf89d5c..2f4c159 100644 --- a/src/lib.rs +++ b/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); } diff --git a/src/nms.c b/src/nms.c index 67d868d..5f9e2ce 100644 --- a/src/nms.c +++ b/src/nms.c @@ -32,9 +32,6 @@ int main(int argc, char *argv[]) case 'f': nmseffect_set_foregroundcolor(optarg); break; - case 'a': - nmseffect_set_autodecrypt(1); - break; case 's': nmseffect_set_maskblank(1); break;