1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#![deny(missing_docs, clippy::pedantic)]
#![allow(
clippy::cast_sign_loss,
clippy::cast_possible_truncation,
clippy::cast_possible_wrap
)]
#![feature(
slice_patterns,
trait_alias,
type_alias_enum_variants,
never_type,
fnbox
)]
use std::ffi::{CStr, CString};
use std::os::raw::c_char;
#[doc(hidden)]
pub mod c;
mod get_info;
pub use crate::get_info::*;
mod lists;
pub use crate::lists::*;
mod hook;
pub use crate::hook::*;
mod other;
pub use crate::other::*;
mod msg;
pub use crate::msg::*;
mod prefs;
pub use crate::prefs::*;
mod chan;
pub use crate::chan::*;
mod subplugin;
pub use crate::subplugin::*;
#[macro_use]
mod safe_static;
pub use crate::safe_static::*;
#[macro_use]
#[doc(hidden)]
pub mod call;
fn to_cstring(str: &str) -> CString {
CString::new(str).unwrap_or_else(|_| CString::new(str.replace('\0', "")).unwrap())
}
unsafe fn from_cstring(ptr: *const c_char) -> String {
CStr::from_ptr(ptr).to_string_lossy().into_owned()
}
unsafe fn from_cstring_opt(ptr: *const c_char) -> Option<String> {
if ptr.is_null() {
None
} else {
Some(from_cstring(ptr))
}
}
pub struct Context {
handle: *mut c::hexchat_plugin,
}
impl Context {
pub fn send_command(&self, command: &str) {
let command = to_cstring(command);
unsafe {
c!(hexchat_command, self.handle, command.as_ptr());
}
}
}
pub trait Plugin {
const NAME: &'static str;
const DESC: &'static str = "";
const VERSION: &'static str = "";
fn new(context: &Context) -> Self;
}