-
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.
- Loading branch information
1 parent
4b8a873
commit edf6ef7
Showing
5 changed files
with
40 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,17 @@ | ||
use crate::prelude::*; | ||
use crate::static_global::byond; | ||
use std::ffi::CString; | ||
use crate::Error; | ||
use std::ffi::{CStr, CString}; | ||
|
||
pub fn str_id_of<T: Into<Vec<u8>>>(string: T) -> u4c { | ||
pub fn str_id_of<T: Into<Vec<u8>>>(string: T) -> Result<u4c, Error> { | ||
let c_string = CString::new(string).unwrap(); | ||
let c_str = c_string.as_c_str(); | ||
str_id_of_cstr(c_string.as_c_str()) | ||
} | ||
|
||
unsafe { byond().Byond_GetStrId(c_str.as_ptr()) } | ||
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
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