mirror of
https://github.com/thepigeongenerator/mcaselector-lite.git
synced 2025-12-17 09:35:46 +01:00
create rust implementation
This commit is contained in:
33
src/error.rs
Normal file
33
src/error.rs
Normal file
@@ -0,0 +1,33 @@
|
||||
unsafe extern "C" {
|
||||
pub fn debug(fmt: *const u8, ...);
|
||||
pub fn info(fmt: *const u8, ...);
|
||||
pub fn warn(fmt: *const u8, ...);
|
||||
pub fn error(fmt: *const u8, ...);
|
||||
pub fn fatal(fmt: *const u8, ...);
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! debug {
|
||||
($fmt:expr) => {{ $crate::error::debug($fmt.as_ptr()); }};
|
||||
($fmt:expr, $($arg:expr),*) => {{ $crate::error::debug($fmt.as_ptr(), ($($arg),*)); }};
|
||||
}
|
||||
#[macro_export]
|
||||
macro_rules! info {
|
||||
($fmt:expr) => {{ $crate::error::info($fmt.as_ptr()); }};
|
||||
($fmt:expr, $($arg:expr),*) => {{ $crate::error::info($fmt.as_ptr(), ($($arg),*)); }};
|
||||
}
|
||||
#[macro_export]
|
||||
macro_rules! warn {
|
||||
($fmt:expr) => {{ $crate::error::warn($fmt.as_ptr()); }};
|
||||
($fmt:expr, $($arg:expr),*) => {{ $crate::error::warn($fmt.as_ptr(), ($($arg),*)); }};
|
||||
}
|
||||
#[macro_export]
|
||||
macro_rules! error {
|
||||
($fmt:expr) => {{ $crate::error::error($fmt.as_ptr()); }};
|
||||
($fmt:expr, $($arg:expr),*) => {{ $crate::error::error($fmt.as_ptr(), ($($arg),*)); }};
|
||||
}
|
||||
#[macro_export]
|
||||
macro_rules! fatal {
|
||||
($fmt:expr) => {{ $crate::error::fatal($fmt.as_ptr()); }};
|
||||
($fmt:expr, $($arg:expr),*) => {{ $crate::error::fatal($fmt.as_ptr(), ($($arg),*)); }};
|
||||
}
|
||||
16
src/lib.rs
16
src/lib.rs
@@ -6,8 +6,16 @@ fn panic(_info: &core::panic::PanicInfo) -> ! {
|
||||
loop {}
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn get_str() -> *const u8 {
|
||||
let str = "Hello, World\0";
|
||||
return str.as_ptr();
|
||||
// contains all publicly facing functions
|
||||
|
||||
mod error;
|
||||
|
||||
pub extern "C" fn test() {
|
||||
unsafe {
|
||||
debug!("%s", "hi");
|
||||
info!("%s", "hi");
|
||||
warn!("%s", "hi");
|
||||
error!("%s", "hi");
|
||||
fatal!("%s", "hi");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
#include <stdio.h>
|
||||
#include "error.h"
|
||||
|
||||
extern char const* get_str(void);
|
||||
extern void test(void);
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
(void)argc, (void)argv;
|
||||
printf("%s\n", get_str());
|
||||
test();
|
||||
debug("owo");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user