test(tests): Update `expected.md` files
This commit is contained in:
parent
a766149521
commit
5a9de1ac0a
|
@ -19,15 +19,29 @@ pub mod trinitrix {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* C API */
|
/* C API */
|
||||||
pub mod trinitrix_c {}
|
pub mod trinitrix_c {
|
||||||
|
#[allow(unused_imports)]
|
||||||
|
use crate::callback_function;
|
||||||
|
}
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn trinitrix_hi(
|
pub extern "C" fn trinitrix_hi(
|
||||||
output: *mut trixy::types::String,
|
output: *mut trixy::types::String,
|
||||||
name: String,
|
name: trixy::types::String,
|
||||||
) -> core::ffi::c_int {
|
) -> core::ffi::c_int {
|
||||||
let output_val: trixy::types::String = {
|
let output_val: trixy::types::String = {
|
||||||
let (tx, rx) = trixy::oneshot::channel();
|
let (tx, rx) = trixy::oneshot::channel();
|
||||||
callback_function(trinitrix_hi);
|
callback_function(
|
||||||
|
Commands::Trinitrix(crate::trinitrix::Trinitrix::hi {
|
||||||
|
trixy_output: tx,
|
||||||
|
name: match name.try_into() {
|
||||||
|
Ok(ok) => ok,
|
||||||
|
Err(err) => {
|
||||||
|
trixy::types::traits::errno::set(err.into());
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
);
|
||||||
let recv = rx
|
let recv = rx
|
||||||
.recv()
|
.recv()
|
||||||
.expect("The channel should not be closed until this value is received");
|
.expect("The channel should not be closed until this value is received");
|
||||||
|
|
|
@ -19,15 +19,29 @@ pub mod trinitrix {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* C API */
|
/* C API */
|
||||||
pub mod trinitrix_c {}
|
pub mod trinitrix_c {
|
||||||
|
#[allow(unused_imports)]
|
||||||
|
use crate::callback_function;
|
||||||
|
}
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn trinitrix_hi(
|
pub extern "C" fn trinitrix_hi(
|
||||||
output: *mut trixy::types::String,
|
output: *mut trixy::types::String,
|
||||||
name: String,
|
name: trixy::types::String,
|
||||||
) -> core::ffi::c_int {
|
) -> core::ffi::c_int {
|
||||||
let output_val: trixy::types::String = {
|
let output_val: trixy::types::String = {
|
||||||
let (tx, rx) = trixy::oneshot::channel();
|
let (tx, rx) = trixy::oneshot::channel();
|
||||||
callback_function(trinitrix_hi);
|
callback_function(
|
||||||
|
Commands::Trinitrix(crate::trinitrix::Trinitrix::hi {
|
||||||
|
trixy_output: tx,
|
||||||
|
name: match name.try_into() {
|
||||||
|
Ok(ok) => ok,
|
||||||
|
Err(err) => {
|
||||||
|
trixy::types::traits::errno::set(err.into());
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
);
|
||||||
let recv = rx
|
let recv = rx
|
||||||
.recv()
|
.recv()
|
||||||
.expect("The channel should not be closed until this value is received");
|
.expect("The channel should not be closed until this value is received");
|
||||||
|
|
|
@ -17,7 +17,10 @@ pub mod test {
|
||||||
pub enum Test {}
|
pub enum Test {}
|
||||||
}
|
}
|
||||||
/* C API */
|
/* C API */
|
||||||
pub mod test_c {}
|
pub mod test_c {
|
||||||
|
#[allow(unused_imports)]
|
||||||
|
use crate::callback_function;
|
||||||
|
}
|
||||||
// vim: filetype=rust
|
// vim: filetype=rust
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,9 @@ File path: `out/dir/api.rs`
|
||||||
pub enum Commands {
|
pub enum Commands {
|
||||||
/// Call out an outstanding person
|
/// Call out an outstanding person
|
||||||
#[allow(non_camel_case_types)]
|
#[allow(non_camel_case_types)]
|
||||||
call_me_back_outstanding { callback: fn(String) -> String },
|
call_me_back_outstanding {
|
||||||
|
callback: extern "C" fn(trixy::types::String) -> trixy::types::String,
|
||||||
|
},
|
||||||
One(one::One),
|
One(one::One),
|
||||||
}
|
}
|
||||||
pub mod one {
|
pub mod one {
|
||||||
|
@ -17,21 +19,44 @@ pub mod one {
|
||||||
pub enum One {
|
pub enum One {
|
||||||
/// Call out a person
|
/// Call out a person
|
||||||
#[allow(non_camel_case_types)]
|
#[allow(non_camel_case_types)]
|
||||||
call_me_back { callback: fn(u32) },
|
call_me_back { callback: extern "C" fn(trixy::types::u32) },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* C API */
|
/* C API */
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn call_me_back_outstanding(
|
pub extern "C" fn call_me_back_outstanding(
|
||||||
callback: fn(String) -> String,
|
callback: extern "C" fn(trixy::types::String) -> trixy::types::String,
|
||||||
) -> core::ffi::c_int {
|
) -> core::ffi::c_int {
|
||||||
callback_function(call_me_back_outstanding);
|
callback_function(crate::Commands::call_me_back_outstanding {
|
||||||
|
callback: match callback.try_into() {
|
||||||
|
Ok(ok) => ok,
|
||||||
|
Err(err) => {
|
||||||
|
trixy::types::traits::errno::set(err.into());
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
pub mod one_c {}
|
pub mod one_c {
|
||||||
|
#[allow(unused_imports)]
|
||||||
|
use crate::callback_function;
|
||||||
|
}
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn one_call_me_back(callback: fn(u32)) -> core::ffi::c_int {
|
pub extern "C" fn one_call_me_back(
|
||||||
callback_function(one_call_me_back);
|
callback: extern "C" fn(trixy::types::u32),
|
||||||
|
) -> core::ffi::c_int {
|
||||||
|
callback_function(
|
||||||
|
crate::Commands::One(crate::one::One::call_me_back {
|
||||||
|
callback: match callback.try_into() {
|
||||||
|
Ok(ok) => ok,
|
||||||
|
Err(err) => {
|
||||||
|
trixy::types::traits::errno::set(err.into());
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
// vim: filetype=rust
|
// vim: filetype=rust
|
||||||
|
@ -61,7 +86,7 @@ extern int one_call_me_back (void (*callback) (uint32_t));
|
||||||
|
|
||||||
struct one
|
struct one
|
||||||
{
|
{
|
||||||
int (*call_me_back) ();
|
int (*call_me_back) (void (*callback) (uint32_t));
|
||||||
};
|
};
|
||||||
|
|
||||||
const struct one one = {
|
const struct one one = {
|
||||||
|
|
|
@ -22,15 +22,29 @@ pub mod trinitrix {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* C API */
|
/* C API */
|
||||||
pub mod trinitrix_c {}
|
pub mod trinitrix_c {
|
||||||
|
#[allow(unused_imports)]
|
||||||
|
use crate::callback_function;
|
||||||
|
}
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn trinitrix_hi(
|
pub extern "C" fn trinitrix_hi(
|
||||||
output: *mut trixy::types::String,
|
output: *mut trixy::types::String,
|
||||||
name: String,
|
name: trixy::types::String,
|
||||||
) -> core::ffi::c_int {
|
) -> core::ffi::c_int {
|
||||||
let output_val: trixy::types::String = {
|
let output_val: trixy::types::String = {
|
||||||
let (tx, rx) = trixy::oneshot::channel();
|
let (tx, rx) = trixy::oneshot::channel();
|
||||||
callback_function(trinitrix_hi);
|
callback_function(
|
||||||
|
Commands::Trinitrix(crate::trinitrix::Trinitrix::hi {
|
||||||
|
trixy_output: tx,
|
||||||
|
name: match name.try_into() {
|
||||||
|
Ok(ok) => ok,
|
||||||
|
Err(err) => {
|
||||||
|
trixy::types::traits::errno::set(err.into());
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
);
|
||||||
let recv = rx
|
let recv = rx
|
||||||
.recv()
|
.recv()
|
||||||
.expect("The channel should not be closed until this value is received");
|
.expect("The channel should not be closed until this value is received");
|
||||||
|
|
|
@ -12,7 +12,7 @@ pub enum Commands {
|
||||||
pub mod trinitrix {
|
pub mod trinitrix {
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum Trinitrix {
|
pub enum Trinitrix {
|
||||||
Std(std::Std),
|
Stdi(stdi::Stdi),
|
||||||
Api(api::Api),
|
Api(api::Api),
|
||||||
}
|
}
|
||||||
/// Language specific functions, which mirror the `trinitrix.api` namespace.
|
/// Language specific functions, which mirror the `trinitrix.api` namespace.
|
||||||
|
@ -20,9 +20,9 @@ pub mod trinitrix {
|
||||||
/// one as it will most likely be more high-level and easier to use (as it isn't abstracted
|
/// one as it will most likely be more high-level and easier to use (as it isn't abstracted
|
||||||
/// over multiple languages). Feel free to drop down to the lower level api, if you feel
|
/// over multiple languages). Feel free to drop down to the lower level api, if you feel
|
||||||
/// like that more, it should be as stable and user-oriented as the `std` functions
|
/// like that more, it should be as stable and user-oriented as the `std` functions
|
||||||
pub mod std {
|
pub mod stdi {
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum Std {}
|
pub enum Stdi {}
|
||||||
}
|
}
|
||||||
/// General API to change stuff in Trinitrix
|
/// General API to change stuff in Trinitrix
|
||||||
pub mod api {
|
pub mod api {
|
||||||
|
@ -54,9 +54,9 @@ pub mod trinitrix {
|
||||||
impl From<crate::trinitrix_c::api_c::ui_c::Mode_c> for Mode {
|
impl From<crate::trinitrix_c::api_c::ui_c::Mode_c> for Mode {
|
||||||
fn from(value: crate::trinitrix_c::api_c::ui_c::Mode_c) -> Self {
|
fn from(value: crate::trinitrix_c::api_c::ui_c::Mode_c) -> Self {
|
||||||
match value {
|
match value {
|
||||||
Mode_c::Normal => Self::Normal,
|
crate::trinitrix_c::api_c::ui_c::Mode_c::Normal => Self::Normal,
|
||||||
Mode_c::Insert => Self::Insert,
|
crate::trinitrix_c::api_c::ui_c::Mode_c::Insert => Self::Insert,
|
||||||
Mode_c::Command => Self::Command,
|
crate::trinitrix_c::api_c::ui_c::Mode_c::Command => Self::Command,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -105,7 +105,7 @@ pub mod trinitrix {
|
||||||
pub enum Keymaps {
|
pub enum Keymaps {
|
||||||
/// Add a new keymapping
|
/// Add a new keymapping
|
||||||
#[allow(non_camel_case_types)]
|
#[allow(non_camel_case_types)]
|
||||||
add { mode: String, key: String, callback: fn() },
|
add { mode: String, key: String, callback: extern "C" fn() },
|
||||||
/// Remove a keymapping
|
/// Remove a keymapping
|
||||||
///
|
///
|
||||||
/// Does nothing, if the keymapping doesn't exists yet
|
/// Does nothing, if the keymapping doesn't exists yet
|
||||||
|
@ -147,20 +147,19 @@ pub mod trinitrix {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* C API */
|
/* C API */
|
||||||
pub mod trinitrix_c {}
|
pub mod trinitrix_c {
|
||||||
pub mod std_c {}
|
#[allow(unused_imports)]
|
||||||
pub mod api_c {}
|
use crate::callback_function;
|
||||||
#[no_mangle]
|
pub mod stdi_c {
|
||||||
pub extern "C" fn trinitrix_api_exit() -> core::ffi::c_int {
|
#[allow(unused_imports)]
|
||||||
callback_function(trinitrix_api_exit);
|
use crate::callback_function;
|
||||||
return 1;
|
}
|
||||||
}
|
pub mod api_c {
|
||||||
#[no_mangle]
|
#[allow(unused_imports)]
|
||||||
pub extern "C" fn trinitrix_api_room_message_send(message: String) -> core::ffi::c_int {
|
use crate::callback_function;
|
||||||
callback_function(trinitrix_api_room_message_send);
|
pub mod ui_c {
|
||||||
return 1;
|
#[allow(unused_imports)]
|
||||||
}
|
use crate::callback_function;
|
||||||
pub mod ui_c {
|
|
||||||
#[allow(non_camel_case_types)]
|
#[allow(non_camel_case_types)]
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -175,76 +174,252 @@ pub mod ui_c {
|
||||||
impl From<crate::trinitrix::api::ui::Mode> for Mode_c {
|
impl From<crate::trinitrix::api::ui::Mode> for Mode_c {
|
||||||
fn from(value: crate::trinitrix::api::ui::Mode) -> Self {
|
fn from(value: crate::trinitrix::api::ui::Mode) -> Self {
|
||||||
match value {
|
match value {
|
||||||
Mode::Normal => Self::Normal,
|
crate::trinitrix::api::ui::Mode::Normal => Self::Normal,
|
||||||
Mode::Insert => Self::Insert,
|
crate::trinitrix::api::ui::Mode::Insert => Self::Insert,
|
||||||
Mode::Command => Self::Command,
|
crate::trinitrix::api::ui::Mode::Command => Self::Command,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn trinitrix_api_ui_set_mode(
|
pub extern "C" fn trinitrix_api_ui_set_mode(
|
||||||
mode: crate::trinitrix::api::ui::Mode,
|
mode: crate::trinitrix_c::api_c::ui_c::Mode_c,
|
||||||
) -> core::ffi::c_int {
|
) -> core::ffi::c_int {
|
||||||
callback_function(trinitrix_api_ui_set_mode);
|
callback_function(
|
||||||
|
crate::Commands::Trinitrix(
|
||||||
|
crate::trinitrix::Trinitrix::Api(
|
||||||
|
crate::trinitrix::api::Api::Ui(crate::trinitrix::api::ui::Ui::set_mode {
|
||||||
|
mode: match mode.try_into() {
|
||||||
|
Ok(ok) => ok,
|
||||||
|
Err(err) => {
|
||||||
|
trixy::types::traits::errno::set(err.into());
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn trinitrix_api_ui_cycle_planes() -> core::ffi::c_int {
|
pub extern "C" fn trinitrix_api_ui_cycle_planes() -> core::ffi::c_int {
|
||||||
callback_function(trinitrix_api_ui_cycle_planes);
|
callback_function(
|
||||||
|
crate::Commands::Trinitrix(
|
||||||
|
crate::trinitrix::Trinitrix::Api(
|
||||||
|
crate::trinitrix::api::Api::Ui(
|
||||||
|
crate::trinitrix::api::ui::Ui::cycle_planes,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn trinitrix_api_ui_cycle_planes_rev() -> core::ffi::c_int {
|
pub extern "C" fn trinitrix_api_ui_cycle_planes_rev() -> core::ffi::c_int {
|
||||||
callback_function(trinitrix_api_ui_cycle_planes_rev);
|
callback_function(
|
||||||
|
crate::Commands::Trinitrix(
|
||||||
|
crate::trinitrix::Trinitrix::Api(
|
||||||
|
crate::trinitrix::api::Api::Ui(
|
||||||
|
crate::trinitrix::api::ui::Ui::cycle_planes_rev,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
pub mod keymaps_c {}
|
pub mod keymaps_c {
|
||||||
#[no_mangle]
|
#[allow(unused_imports)]
|
||||||
pub extern "C" fn trinitrix_api_keymaps_add(
|
use crate::callback_function;
|
||||||
mode: String,
|
}
|
||||||
key: String,
|
#[no_mangle]
|
||||||
callback: fn(),
|
pub extern "C" fn trinitrix_api_keymaps_add(
|
||||||
) -> core::ffi::c_int {
|
mode: trixy::types::String,
|
||||||
callback_function(trinitrix_api_keymaps_add);
|
key: trixy::types::String,
|
||||||
|
callback: extern "C" fn(),
|
||||||
|
) -> core::ffi::c_int {
|
||||||
|
callback_function(
|
||||||
|
crate::Commands::Trinitrix(
|
||||||
|
crate::trinitrix::Trinitrix::Api(
|
||||||
|
crate::trinitrix::api::Api::Keymaps(crate::trinitrix::api::keymaps::Keymaps::add {
|
||||||
|
mode: match mode.try_into() {
|
||||||
|
Ok(ok) => ok,
|
||||||
|
Err(err) => {
|
||||||
|
trixy::types::traits::errno::set(err.into());
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
key: match key.try_into() {
|
||||||
|
Ok(ok) => ok,
|
||||||
|
Err(err) => {
|
||||||
|
trixy::types::traits::errno::set(err.into());
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
callback: match callback.try_into() {
|
||||||
|
Ok(ok) => ok,
|
||||||
|
Err(err) => {
|
||||||
|
trixy::types::traits::errno::set(err.into());
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn trinitrix_api_keymaps_remove(
|
pub extern "C" fn trinitrix_api_keymaps_remove(
|
||||||
mode: String,
|
mode: trixy::types::String,
|
||||||
key: String,
|
key: trixy::types::String,
|
||||||
) -> core::ffi::c_int {
|
) -> core::ffi::c_int {
|
||||||
callback_function(trinitrix_api_keymaps_remove);
|
callback_function(
|
||||||
|
crate::Commands::Trinitrix(
|
||||||
|
crate::trinitrix::Trinitrix::Api(
|
||||||
|
crate::trinitrix::api::Api::Keymaps(crate::trinitrix::api::keymaps::Keymaps::remove {
|
||||||
|
mode: match mode.try_into() {
|
||||||
|
Ok(ok) => ok,
|
||||||
|
Err(err) => {
|
||||||
|
trixy::types::traits::errno::set(err.into());
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
key: match key.try_into() {
|
||||||
|
Ok(ok) => ok,
|
||||||
|
Err(err) => {
|
||||||
|
trixy::types::traits::errno::set(err.into());
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn trinitrix_api_keymaps_get(mode: String) -> core::ffi::c_int {
|
pub extern "C" fn trinitrix_api_keymaps_get(
|
||||||
callback_function(trinitrix_api_keymaps_get);
|
mode: trixy::types::String,
|
||||||
|
) -> core::ffi::c_int {
|
||||||
|
callback_function(
|
||||||
|
crate::Commands::Trinitrix(
|
||||||
|
crate::trinitrix::Trinitrix::Api(
|
||||||
|
crate::trinitrix::api::Api::Keymaps(crate::trinitrix::api::keymaps::Keymaps::get {
|
||||||
|
mode: match mode.try_into() {
|
||||||
|
Ok(ok) => ok,
|
||||||
|
Err(err) => {
|
||||||
|
trixy::types::traits::errno::set(err.into());
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
pub mod raw_c {}
|
pub mod raw_c {
|
||||||
#[no_mangle]
|
#[allow(unused_imports)]
|
||||||
pub extern "C" fn trinitrix_api_raw_raise_error(
|
use crate::callback_function;
|
||||||
error_message: String,
|
pub mod __private_c {
|
||||||
) -> core::ffi::c_int {
|
#[allow(unused_imports)]
|
||||||
callback_function(trinitrix_api_raw_raise_error);
|
use crate::callback_function;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#[no_mangle]
|
||||||
|
pub extern "C" fn trinitrix_api_raw_raise_error(
|
||||||
|
error_message: trixy::types::String,
|
||||||
|
) -> core::ffi::c_int {
|
||||||
|
callback_function(
|
||||||
|
crate::Commands::Trinitrix(
|
||||||
|
crate::trinitrix::Trinitrix::Api(
|
||||||
|
crate::trinitrix::api::Api::Raw(crate::trinitrix::api::raw::Raw::raise_error {
|
||||||
|
error_message: match error_message.try_into() {
|
||||||
|
Ok(ok) => ok,
|
||||||
|
Err(err) => {
|
||||||
|
trixy::types::traits::errno::set(err.into());
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn trinitrix_api_raw_display_output(
|
pub extern "C" fn trinitrix_api_raw_display_output(
|
||||||
output_message: String,
|
output_message: trixy::types::String,
|
||||||
) -> core::ffi::c_int {
|
) -> core::ffi::c_int {
|
||||||
callback_function(trinitrix_api_raw_display_output);
|
callback_function(
|
||||||
|
crate::Commands::Trinitrix(
|
||||||
|
crate::trinitrix::Trinitrix::Api(
|
||||||
|
crate::trinitrix::api::Api::Raw(crate::trinitrix::api::raw::Raw::display_output {
|
||||||
|
output_message: match output_message.try_into() {
|
||||||
|
Ok(ok) => ok,
|
||||||
|
Err(err) => {
|
||||||
|
trixy::types::traits::errno::set(err.into());
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn trinitrix_api_raw_send_input_unprocessed(
|
pub extern "C" fn trinitrix_api_raw_send_input_unprocessed(
|
||||||
input: String,
|
input: trixy::types::String,
|
||||||
) -> core::ffi::c_int {
|
) -> core::ffi::c_int {
|
||||||
callback_function(trinitrix_api_raw_send_input_unprocessed);
|
callback_function(
|
||||||
|
crate::Commands::Trinitrix(
|
||||||
|
crate::trinitrix::Trinitrix::Api(
|
||||||
|
crate::trinitrix::api::Api::Raw(crate::trinitrix::api::raw::Raw::send_input_unprocessed {
|
||||||
|
input: match input.try_into() {
|
||||||
|
Ok(ok) => ok,
|
||||||
|
Err(err) => {
|
||||||
|
trixy::types::traits::errno::set(err.into());
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
return 1;
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#[no_mangle]
|
||||||
|
pub extern "C" fn trinitrix_api_exit() -> core::ffi::c_int {
|
||||||
|
callback_function(
|
||||||
|
crate::Commands::Trinitrix(
|
||||||
|
crate::trinitrix::Trinitrix::Api(crate::trinitrix::api::Api::exit),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
#[no_mangle]
|
||||||
|
pub extern "C" fn trinitrix_api_room_message_send(
|
||||||
|
message: trixy::types::String,
|
||||||
|
) -> core::ffi::c_int {
|
||||||
|
callback_function(
|
||||||
|
crate::Commands::Trinitrix(
|
||||||
|
crate::trinitrix::Trinitrix::Api(crate::trinitrix::api::Api::room_message_send {
|
||||||
|
message: match message.try_into() {
|
||||||
|
Ok(ok) => ok,
|
||||||
|
Err(err) => {
|
||||||
|
trixy::types::traits::errno::set(err.into());
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
pub mod __private_c {}
|
|
||||||
// vim: filetype=rust
|
// vim: filetype=rust
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -347,7 +522,7 @@ extern int trinitrix_api_raw_send_input_unprocessed (const char *input);
|
||||||
* the lower level api, if you feel like that more, it should be as stable and
|
* the lower level api, if you feel like that more, it should be as stable and
|
||||||
* user-oriented as the `std` functions
|
* user-oriented as the `std` functions
|
||||||
*/
|
*/
|
||||||
struct std
|
struct stdi
|
||||||
{
|
{
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -356,7 +531,7 @@ struct std
|
||||||
*/
|
*/
|
||||||
struct ui
|
struct ui
|
||||||
{
|
{
|
||||||
int (*set_mode) ();
|
int (*set_mode) (enum Mode);
|
||||||
int (*cycle_planes) (void);
|
int (*cycle_planes) (void);
|
||||||
int (*cycle_planes_rev) (void);
|
int (*cycle_planes_rev) (void);
|
||||||
};
|
};
|
||||||
|
@ -392,9 +567,9 @@ struct ui
|
||||||
*/
|
*/
|
||||||
struct keymaps
|
struct keymaps
|
||||||
{
|
{
|
||||||
int (*add) ();
|
int (*add) (const char *, const char *, void (*callback) ());
|
||||||
int (*remove) ();
|
int (*remove) (const char *, const char *);
|
||||||
int (*get) ();
|
int (*get) (const char *);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -413,9 +588,9 @@ struct __private
|
||||||
*/
|
*/
|
||||||
struct raw
|
struct raw
|
||||||
{
|
{
|
||||||
int (*raise_error) ();
|
int (*raise_error) (const char *);
|
||||||
int (*display_output) ();
|
int (*display_output) (const char *);
|
||||||
int (*send_input_unprocessed) ();
|
int (*send_input_unprocessed) (const char *);
|
||||||
struct __private __private;
|
struct __private __private;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -425,7 +600,7 @@ struct raw
|
||||||
struct api
|
struct api
|
||||||
{
|
{
|
||||||
int (*exit) (void);
|
int (*exit) (void);
|
||||||
int (*room_message_send) ();
|
int (*room_message_send) (const char *);
|
||||||
struct ui ui;
|
struct ui ui;
|
||||||
struct keymaps keymaps;
|
struct keymaps keymaps;
|
||||||
struct raw raw;
|
struct raw raw;
|
||||||
|
@ -433,11 +608,11 @@ struct api
|
||||||
|
|
||||||
struct trinitrix
|
struct trinitrix
|
||||||
{
|
{
|
||||||
struct std std;
|
struct stdi stdi;
|
||||||
struct api api;
|
struct api api;
|
||||||
};
|
};
|
||||||
|
|
||||||
const struct std std = {};
|
const struct stdi stdi = {};
|
||||||
const struct ui ui = {
|
const struct ui ui = {
|
||||||
.set_mode = trinitrix_api_ui_set_mode,
|
.set_mode = trinitrix_api_ui_set_mode,
|
||||||
.cycle_planes = trinitrix_api_ui_cycle_planes,
|
.cycle_planes = trinitrix_api_ui_cycle_planes,
|
||||||
|
@ -463,7 +638,7 @@ const struct api api = {
|
||||||
.raw = raw,
|
.raw = raw,
|
||||||
};
|
};
|
||||||
const struct trinitrix trinitrix = {
|
const struct trinitrix trinitrix = {
|
||||||
.std = std,
|
.stdi = stdi,
|
||||||
.api = api,
|
.api = api,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ mod trinitrix {
|
||||||
/// one as it will most likely be more high-level and easier to use (as it isn't abstracted
|
/// one as it will most likely be more high-level and easier to use (as it isn't abstracted
|
||||||
/// over multiple languages). Feel free to drop down to the lower level api, if you feel
|
/// over multiple languages). Feel free to drop down to the lower level api, if you feel
|
||||||
/// like that more, it should be as stable and user-oriented as the `std` functions
|
/// like that more, it should be as stable and user-oriented as the `std` functions
|
||||||
mod std {}
|
mod stdi {}
|
||||||
|
|
||||||
/// General API to change stuff in Trinitrix
|
/// General API to change stuff in Trinitrix
|
||||||
mod api {
|
mod api {
|
||||||
|
|
|
@ -15,7 +15,7 @@ pub mod test {
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Callback {
|
pub struct Callback {
|
||||||
/// Very important field
|
/// Very important field
|
||||||
pub func: fn(String) -> String,
|
pub func: extern "C" fn(trixy::types::String) -> trixy::types::String,
|
||||||
/// Very important field for keeping time constant
|
/// Very important field for keeping time constant
|
||||||
pub timeout: u32,
|
pub timeout: u32,
|
||||||
}
|
}
|
||||||
|
@ -58,9 +58,9 @@ pub mod test {
|
||||||
impl From<crate::test_c::CallbackPriority_c> for CallbackPriority {
|
impl From<crate::test_c::CallbackPriority_c> for CallbackPriority {
|
||||||
fn from(value: crate::test_c::CallbackPriority_c) -> Self {
|
fn from(value: crate::test_c::CallbackPriority_c) -> Self {
|
||||||
match value {
|
match value {
|
||||||
CallbackPriority_c::High => Self::High,
|
crate::test_c::CallbackPriority_c::High => Self::High,
|
||||||
CallbackPriority_c::Medium => Self::Medium,
|
crate::test_c::CallbackPriority_c::Medium => Self::Medium,
|
||||||
CallbackPriority_c::Low => Self::Low,
|
crate::test_c::CallbackPriority_c::Low => Self::Low,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -75,6 +75,8 @@ pub mod test {
|
||||||
}
|
}
|
||||||
/* C API */
|
/* C API */
|
||||||
pub mod test_c {
|
pub mod test_c {
|
||||||
|
#[allow(unused_imports)]
|
||||||
|
use crate::callback_function;
|
||||||
/// Same thing as above (and a enum doc comment test)
|
/// Same thing as above (and a enum doc comment test)
|
||||||
#[allow(non_camel_case_types)]
|
#[allow(non_camel_case_types)]
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
|
@ -92,9 +94,9 @@ pub mod test_c {
|
||||||
impl From<crate::test::CallbackPriority> for CallbackPriority_c {
|
impl From<crate::test::CallbackPriority> for CallbackPriority_c {
|
||||||
fn from(value: crate::test::CallbackPriority) -> Self {
|
fn from(value: crate::test::CallbackPriority) -> Self {
|
||||||
match value {
|
match value {
|
||||||
CallbackPriority::High => Self::High,
|
crate::test::CallbackPriority::High => Self::High,
|
||||||
CallbackPriority::Medium => Self::Medium,
|
crate::test::CallbackPriority::Medium => Self::Medium,
|
||||||
CallbackPriority::Low => Self::Low,
|
crate::test::CallbackPriority::Low => Self::Low,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -104,17 +106,43 @@ pub mod test_c {
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Callback_c {
|
pub struct Callback_c {
|
||||||
/// Very important field
|
/// Very important field
|
||||||
pub func: fn(String) -> String,
|
pub func: extern "C" fn(trixy::types::String) -> trixy::types::String,
|
||||||
/// Very important field for keeping time constant
|
/// Very important field for keeping time constant
|
||||||
pub timeout: trixy::types::u32,
|
pub timeout: trixy::types::u32,
|
||||||
}
|
}
|
||||||
|
impl TryFrom<crate::test::Callback> for Callback_c {
|
||||||
|
type Error = trixy::types::error::TypeConversionError;
|
||||||
|
fn try_from(value: crate::test::Callback) -> Result<Self, Self::Error> {
|
||||||
|
Ok(Self {
|
||||||
|
func: value.func.try_into()?,
|
||||||
|
timeout: value.timeout.try_into()?,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn test_execute_callback(
|
pub extern "C" fn test_execute_callback(
|
||||||
callback: crate::test::Callback,
|
callback: crate::test_c::Callback_c,
|
||||||
priority: crate::test::CallbackPriority,
|
priority: crate::test_c::CallbackPriority_c,
|
||||||
) -> core::ffi::c_int {
|
) -> core::ffi::c_int {
|
||||||
callback_function(test_execute_callback);
|
callback_function(
|
||||||
|
crate::Commands::Test(crate::test::Test::execute_callback {
|
||||||
|
callback: match callback.try_into() {
|
||||||
|
Ok(ok) => ok,
|
||||||
|
Err(err) => {
|
||||||
|
trixy::types::traits::errno::set(err.into());
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
priority: match priority.try_into() {
|
||||||
|
Ok(ok) => ok,
|
||||||
|
Err(err) => {
|
||||||
|
trixy::types::traits::errno::set(err.into());
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
// vim: filetype=rust
|
// vim: filetype=rust
|
||||||
|
@ -173,7 +201,7 @@ extern int test_execute_callback (struct Callback callback,
|
||||||
|
|
||||||
struct test
|
struct test
|
||||||
{
|
{
|
||||||
int (*execute_callback) ();
|
int (*execute_callback) (struct Callback, enum CallbackPriority);
|
||||||
};
|
};
|
||||||
|
|
||||||
const struct test test = {
|
const struct test test = {
|
||||||
|
|
|
@ -17,7 +17,10 @@ pub mod trinitrix {
|
||||||
pub enum Trinitrix {}
|
pub enum Trinitrix {}
|
||||||
}
|
}
|
||||||
/* C API */
|
/* C API */
|
||||||
pub mod trinitrix_c {}
|
pub mod trinitrix_c {
|
||||||
|
#[allow(unused_imports)]
|
||||||
|
use crate::callback_function;
|
||||||
|
}
|
||||||
// vim: filetype=rust
|
// vim: filetype=rust
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
Reference in New Issue