Created
December 23, 2018 07:26
-
-
Save DDRBoxman/23d11ba5f22fb095f1afc555d98913da to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::os::raw::{c_int, c_char, c_void}; | |
use std::ptr; | |
use std::ffi::CString; | |
use std::io::{self, Write}; | |
#[repr(C)] // ensures that the memory layout of the struct is the same in Rust as in C. | |
pub struct obs_module_t { | |
pub mod_name: *mut c_char, | |
pub file: *const c_char, | |
pub bin_path: *mut c_char, | |
pub data_path: *mut c_char, | |
pub module: *mut c_void, | |
pub loaded: bool, | |
load: extern fn() -> bool, | |
unload: extern fn(), | |
post_load: extern fn(), | |
set_locale: extern fn(locale: *const c_char), | |
free_locale: extern fn(), | |
ver: extern fn() -> u32, | |
set_pointer: extern fn(module: *mut obs_module_t), | |
name: extern fn() -> *const c_char, | |
description: extern fn() -> *const c_char, | |
author: extern fn() -> *const c_char, | |
next: *mut obs_module_t | |
} | |
static mut obs_module_pointer: *mut obs_module_t = ptr::null_mut(); | |
#[no_mangle] | |
pub extern fn obs_module_set_pointer(module: *mut obs_module_t) { | |
unsafe { | |
obs_module_pointer = module | |
} | |
} | |
#[no_mangle] | |
pub extern fn obs_module_ver() -> u32 { | |
(22 << 24) | (0 << 16) | 3 | |
} | |
#[no_mangle] | |
pub extern fn obs_module_name() -> *const c_char { | |
let s = CString::new("OBS Rust Module").unwrap(); | |
let p = s.as_ptr(); | |
std::mem::forget(s); | |
p | |
} | |
#[no_mangle] | |
pub extern fn obs_module_load() -> bool { | |
print!("Hello from rust!\n"); | |
return true | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment