diff options
Diffstat (limited to 'src/lib.rs')
-rw-r--r-- | src/lib.rs | 61 |
1 files changed, 46 insertions, 15 deletions
diff --git a/src/lib.rs b/src/lib.rs index e7db70b..0852a24 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -188,22 +188,35 @@ extern crate impl_trait; #[doc(hidden)] pub extern crate libc; +// private macros + +/// Calls a function on a PluginHandle struct. +macro_rules! ph_call { + ($f:ident($ph:expr, $($args:expr),*)) => { + ((*$ph.data.ph).$f)($ph.plugin, $($args),*) + }; + ($f:ident($ph:expr $(,)?)) => { + ((*$ph.data.ph).$f)($ph.plugin) + }; +} + mod eat; mod extra_tests; mod infoid; mod internals; +pub mod list; mod pluginfo; mod strip; mod word; pub use eat::*; pub use infoid::InfoId; -pub use word::*; pub use strip::*; +pub use word::*; -use pluginfo::PluginInfo; -use internals::Ph as RawPh; use internals::HexchatEventAttrs as RawAttrs; +use internals::Ph as RawPh; +use pluginfo::PluginInfo; use std::borrow::Cow; use std::cell::Cell; @@ -227,18 +240,6 @@ use std::time::{SystemTime, UNIX_EPOCH, Duration}; #[doc(hidden)] pub use libc::{c_char, c_int, c_void, time_t}; -// private macros - -/// Calls a function on a PluginHandle struct. -macro_rules! ph_call { - ($f:ident($ph:expr, $($args:expr),*)) => { - ((*$ph.data.ph).$f)($ph.plugin, $($args),*) - }; - ($f:ident($ph:expr $(,)?)) => { - ((*$ph.data.ph).$f)($ph.plugin) - }; -} - // ****** // // PUBLIC // // ****** // @@ -1520,6 +1521,36 @@ impl<'a, 'ph: 'a> ValidContext<'a, 'ph> { } } + /// Retrieves a list. + /// + /// # Examples + /// + /// ```no_run + /// use hexchat_unsafe_plugin::list::Contexts; + /// use hexchat_unsafe_plugin::PluginHandle; + /// + /// fn print_contexts(ph: &mut PluginHandle<'_>) { + /// ph.ensure_valid_context(|ph| { + /// for context in ph.list(&Contexts) { + /// write!(ph, "{}", context.name().unwrap()); + /// } + /// }) + /// } + /// ``` + pub fn list<T: list::List>(&'a self, t: &'a T) -> list::Entries<'a, 'ph, T> { + let ph = &self.ph; + let list = CString::new(&*t.name()).unwrap(); + let list = unsafe { + ph_call!(hexchat_list_get(ph, list.as_ptr())) + }; + list::Entries { + context: self, + list: list, + t: t, + valid: Default::default(), + } + } + // ******** // // FORWARDS // // ******** // |