Implement find_context

This commit is contained in:
SoniEx2 2018-03-31 15:02:41 -03:00
parent b2be734b53
commit 6d5d3e7297
2 changed files with 15 additions and 4 deletions

View File

@ -1,6 +1,6 @@
[package] [package]
name = "hexchat-plugin" name = "hexchat-plugin"
version = "0.2.1" version = "0.2.2"
authors = ["SoniEx2 <endermoneymod@gmail.com>"] authors = ["SoniEx2 <endermoneymod@gmail.com>"]
description = "Lets you write HexChat plugins in Rust" description = "Lets you write HexChat plugins in Rust"
license = "AGPL-3.0+" license = "AGPL-3.0+"

View File

@ -95,7 +95,7 @@
* -[ ] hexchat_hook_server_attrs * -[ ] hexchat_hook_server_attrs
* -[x] hexchat_hook_timer * -[x] hexchat_hook_timer
* -[x] ~~hexchat_unhook~~ not available - use Drop impls * -[x] ~~hexchat_unhook~~ not available - use Drop impls
* -[ ] hexchat_find_context * -[x] hexchat_find_context
* -[x] hexchat_get_context * -[x] hexchat_get_context
* -[x] hexchat_set_context * -[x] hexchat_set_context
* -[ ] hexchat_pluginpref_set_str * -[ ] hexchat_pluginpref_set_str
@ -631,9 +631,20 @@ impl<'a> EnsureValidContext<'a> {
* context take an `&mut self`, things that do take an `self`. * context take an `&mut self`, things that do take an `self`.
*/ */
/// Finds an open context for the given servname and channel.
pub fn find_context(&mut self, servname: Option<&str>, channel: Option<&str>) -> Option<Context> { pub fn find_context(&mut self, servname: Option<&str>, channel: Option<&str>) -> Option<Context> {
// TODO // this was a mistake but oh well
unimplemented!() let ph = self.ph.ph;
let servname = CString::new(servname).unwrap();
let channel = CString::new(channel).unwrap();
let ctx = unsafe {
((*ph).hexchat_find_context)(ph, servname.as_ptr(), channel.as_ptr())
};
if ctx.is_null() {
None
} else {
Some(Context { ctx })
}
} }
pub fn nickcmp(&mut self, nick1: &str, nick2: &str) -> ::std::cmp::Ordering { pub fn nickcmp(&mut self, nick1: &str, nick2: &str) -> ::std::cmp::Ordering {