-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from jupyterkat/main
Add some stuff, fixes some stuff
- Loading branch information
Showing
18 changed files
with
702 additions
and
173 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
use crate::prelude::*; | ||
use crate::static_global::byond; | ||
use crate::Error; | ||
use std::ffi::{CStr, CString}; | ||
|
||
pub fn str_id_of<T: Into<Vec<u8>>>(string: T) -> Result<u4c, Error> { | ||
let c_string = CString::new(string).unwrap(); | ||
str_id_of_cstr(c_string.as_c_str()) | ||
} | ||
|
||
pub fn str_id_of_cstr(string: &CStr) -> Result<u4c, Error> { | ||
let res = unsafe { byond().Byond_GetStrId(string.as_ptr()) }; | ||
if res == u2c::MAX as u32 { | ||
return Err(Error::NonExistentString); | ||
} | ||
Ok(res) | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
use crate::prelude::*; | ||
use crate::static_global::byond; | ||
use crate::Error; | ||
|
||
use std::ffi::CString; | ||
|
||
/// Calls a global proc. | ||
/// | ||
/// Implicitly set waitfor=0, will never block. | ||
pub fn call_global<T: Into<Vec<u8>>>(name: T, args: &[ByondValue]) -> Result<ByondValue, Error> { | ||
let c_string = CString::new(name).unwrap(); | ||
let c_str = c_string.as_c_str(); | ||
|
||
let str_id = unsafe { byond().Byond_GetStrId(c_str.as_ptr()) }; | ||
if str_id == crate::sys::u2c::MAX as u32 { | ||
return Err(Error::InvalidProc); | ||
} | ||
let ptr = args.as_ptr(); | ||
let mut new_value = ByondValue::new(); | ||
unsafe { | ||
map_byond_error!(byond().Byond_CallGlobalProcByStrId( | ||
str_id, | ||
ptr.cast(), | ||
args.len() as u32, | ||
&mut new_value.0 | ||
))?; | ||
} | ||
Ok(new_value) | ||
} | ||
|
||
/// Calls a global proc by its string id. | ||
/// | ||
/// Implicitly set waitfor=0, will never block. | ||
pub fn call_global_id(name: u4c, args: &[ByondValue]) -> Result<ByondValue, Error> { | ||
let ptr = args.as_ptr(); | ||
let mut new_value = ByondValue::new(); | ||
unsafe { | ||
map_byond_error!(byond().Byond_CallGlobalProcByStrId( | ||
name, | ||
ptr.cast(), | ||
args.len() as u32, | ||
&mut new_value.0 | ||
))?; | ||
} | ||
Ok(new_value) | ||
} |
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.