Struct ByondApi

Source
pub struct ByondApi { /* private fields */ }

Implementations§

Source§

impl ByondApi

Source

pub unsafe fn init_from_library<L>(library: L) -> Result<ByondApi, Error>
where L: Into<Library>,

Source

pub fn get_version(&self) -> (u32, u32)

Methods from Deref<Target = ByondApi>§

Source

pub unsafe fn Byond_LastError(&self) -> *const c_char

Gets the last error from a failed call The result is a static string that does not need to be freed.

§Returns

Error message

Source

pub unsafe fn Byond_GetVersion(&self, version: *mut u4c, build: *mut u4c)

Gets the current BYOND version

§Arguments
  • version - Pointer to the major version number
  • build - Pointer to the build number
Source

pub unsafe fn Byond_GetDMBVersion(&self) -> u4c

Gets the DMB version

§Returns

Version number the .dmb was built with

Source

pub unsafe fn ByondValue_Clear(&self, v: *mut CByondValue)

Fills a CByondValue struct with a null value.

§Arguments
  • v - Pointer to CByondValue
Source

pub unsafe fn ByondValue_Type(&self, v: *const CByondValue) -> ByondValueType

Reads CByondVale’s 1-byte data type

§Arguments
  • v - Pointer to CByondValue
§Returns

Type of value

Source

pub unsafe fn ByondValue_IsNull(&self, v: *const CByondValue) -> bool

§Arguments
  • v - Pointer to CByondValue
§Returns

True if value is null

Source

pub unsafe fn ByondValue_IsNum(&self, v: *const CByondValue) -> bool

§Arguments
  • v - Pointer to CByondValue
§Returns

True if value is a numeric type

Source

pub unsafe fn ByondValue_IsStr(&self, v: *const CByondValue) -> bool

§Arguments
  • v - Pointer to CByondValue
§Returns

True if value is a string

Source

pub unsafe fn ByondValue_IsList(&self, v: *const CByondValue) -> bool

§Arguments
  • v - Pointer to CByondValue
§Returns

True if value is a list (any list type, not just user-defined)

Source

pub unsafe fn ByondValue_IsTrue(&self, v: *const CByondValue) -> bool

Determines if a value is logically true or false

§Arguments
  • v - Pointer to CByondValue
§Returns

Truthiness of value

Source

pub unsafe fn ByondValue_GetNum(&self, v: *const CByondValue) -> f32

§Arguments
  • v - Pointer to CByondValue
§Returns

Floating point number for v, or 0 if not numeric

Source

pub unsafe fn ByondValue_GetRef(&self, v: *const CByondValue) -> u4c

§Arguments
  • v - Pointer to CByondValue
§Returns

Reference ID if value is a reference type, or 0 otherwise

Source

pub unsafe fn ByondValue_SetNum(&self, v: *mut CByondValue, f: f32)

Fills a CByondValue struct with a floating point number.

§Arguments
  • v - Pointer to CByondValue
  • f - Floating point number
Source

pub unsafe fn ByondValue_SetStr(&self, v: *mut CByondValue, str_: *const c_char)

Creates a string and sets CByondValue to a reference to that string, and increases the reference count. See REFERENCE COUNTING in byondapi.h. Blocks if not on the main thread. If string creation fails, the struct is set to null.

§Arguments
  • v - Pointer to CByondValue
  • str - Null-terminated UTF-8 string [Byond_AddGetStrId()]
Source

pub unsafe fn ByondValue_SetStrId(&self, v: *mut CByondValue, strid: u4c)

Fills a CByondValue struct with a reference to a string with a given ID. Does not validate, and does not increase the reference count. If the strid is NONE, it will be changed to 0.

§Arguments
  • v - Pointer to CByondValue
  • strid - 4-byte string ID [Byond_TestRef()]
Source

pub unsafe fn ByondValue_SetRef( &self, v: *mut CByondValue, type_: ByondValueType, ref_: u4c, )

Fills a CByondValue struct with a reference (object) type. Does not validate.

§Arguments
  • v - Pointer to CByondValue
  • type - 1-byte teference type
  • ref - 4-byte reference ID; for most types, an ID of NONE is invalid [Byond_TestRef()]
Source

pub unsafe fn ByondValue_Equals( &self, a: *const CByondValue, b: *const CByondValue, ) -> bool

Compares two values for equality

§Arguments
  • a - Pointer to CByondValue
  • b - Pointer to CByondValue
§Returns

True if values are equal

Source

pub unsafe fn Byond_ThreadSync( &self, callback: ByondCallback, data: *mut c_void, block: bool, ) -> CByondValue

Runs a function as a callback on the main thread (or right away if already there) All references created from Byondapi calls within your callback are persistent, not temporary, even though your callback runs on the main thread. Blocking is optional. If already on the main thread, the block parameter is meaningless.

§Arguments
  • callback - Function pointer to CByondValue function(void*)
  • data - Void pointer (argument to function)
  • block - True if this call should block while waiting for the callback to finish; false if not
§Returns

CByondValue returned by the function (if it blocked; null if not)

Source

pub unsafe fn Byond_GetStrId(&self, str_: *const c_char) -> u4c

Returns a reference to an existing string ID, but does not create a new string ID. Blocks if not on the main thread.

§Arguments
  • str - Null-terminated string
§Returns

ID of string; NONE if string does not exist

Source

pub unsafe fn Byond_AddGetStrId(&self, str_: *const c_char) -> u4c

Returns a reference to an existing string ID or creates a new string ID reference. The new string is reference-counted. See REFERENCE COUNTING in byondapi.h for details. Call ByondValue_SeStrId() to use the returned ID in a CByondValue. Blocks if not on the main thread.

§Arguments
  • str - Null-terminated string
§Returns

ID of string; NONE if string creation failed

Source

pub unsafe fn Byond_ReadVar( &self, loc: *const CByondValue, varname: *const c_char, result: *mut CByondValue, ) -> bool

Reads an object variable by name. Blocks if not on the main thread.

§Arguments
  • loc - Object that owns the var
  • varname - Var name as null-terminated string
  • result - Pointer to accept result
§Returns

True on success

Source

pub unsafe fn Byond_ReadVarByStrId( &self, loc: *const CByondValue, varname: u4c, result: *mut CByondValue, ) -> bool

Reads an object variable by the string ID of its var name. ID can be cached ahead of time for performance. Blocks if not on the main thread.

§Arguments
  • loc - Object that owns the var
  • varname - Var name as string ID
  • result - Pointer to accept result
§Returns

True on success [Byond_GetStrId()]

Source

pub unsafe fn Byond_WriteVar( &self, loc: *const CByondValue, varname: *const c_char, val: *const CByondValue, ) -> bool

Writes an object variable by name. Blocks if not on the main thread.

§Arguments
  • loc - Object that owns the var
  • varname - Var name as null-terminated string
  • val - New value
§Returns

True on success

Source

pub unsafe fn Byond_WriteVarByStrId( &self, loc: *const CByondValue, varname: u4c, val: *const CByondValue, ) -> bool

Writes an object variable by the string ID of its var name. ID can be cached ahead of time for performance. Blocks if not on the main thread.

§Arguments
  • loc - Object that owns the var
  • varname - Var name as string ID
  • val - New value
§Returns

True on success

Source

pub unsafe fn Byond_CreateList(&self, result: *mut CByondValue) -> bool

Creates an empty list with a temporary reference. Equivalent to list(). Blocks if not on the main thread.

§Arguments
  • result - Result
§Returns

True on success

Source

pub unsafe fn Byond_ReadList( &self, loc: *const CByondValue, list: *mut CByondValue, len: *mut u4c, ) -> bool

Reads items from a list. Blocks if not on the main thread.

§Arguments
  • loc - The list to read
  • list - CByondValue array, allocated by caller (can be null if querying length)
  • len - Pointer to length of array (in items); receives the number of items read on success, or required length of array if not big enough
§Returns

True on success; false with *len=0 for failure; false with *len=required size if array is not big enough

Source

pub unsafe fn Byond_WriteList( &self, loc: *const CByondValue, list: *const CByondValue, len: u4c, ) -> bool

Writes items to a list, in place of old contents. Blocks if not on the main thread.

§Arguments
  • loc - The list to fill
  • list - CByondValue array of items to write
  • len - Number of items to write
§Returns

True on success

Source

pub unsafe fn Byond_ReadListAssoc( &self, loc: *const CByondValue, list: *mut CByondValue, len: *mut u4c, ) -> bool

Reads items as key,value pairs from an associative list, storing them sequentially as key1, value1, key2, value2, etc. Blocks if not on the main thread.

§Arguments
  • loc - The list to read
  • list - CByondValue array, allocated by caller (can be null if querying length)
  • len - Pointer to length of array (in items); receives the number of items read on success, or required length of array if not big enough
§Returns

True on success; false with *len=0 for failure; false with *len=required size if array is not big enough

Source

pub unsafe fn Byond_ReadListIndex( &self, loc: *const CByondValue, idx: *const CByondValue, result: *mut CByondValue, ) -> bool

Reads an item from a list. Blocks if not on the main thread.

§Arguments
  • loc - The list
  • idx - The index in the list (may be a number, or a non-number if using associative lists)
  • result - Pointer to accept result
§Returns

True on success

Source

pub unsafe fn Byond_WriteListIndex( &self, loc: *const CByondValue, idx: *const CByondValue, val: *const CByondValue, ) -> bool

Writes an item to a list. Blocks if not on the main thread.

§Arguments
  • loc - The list
  • idx - The index in the list (may be a number, or a non-number if using associative lists)
  • val - New value
§Returns

True on success

Source

pub unsafe fn Byond_ReadPointer( &self, ptr: *const CByondValue, result: *mut CByondValue, ) -> bool

Reads from a BYOND pointer Blocks if not on the main thread.

§Arguments
  • ptr - The BYOND pointer
  • result - Pointer to accept result
§Returns

True on success

Source

pub unsafe fn Byond_WritePointer( &self, ptr: *const CByondValue, val: *const CByondValue, ) -> bool

Writes to a BYOND pointer Blocks if not on the main thread.

§Arguments
  • ptr - The BYOND pointer
  • val - New value
§Returns

True on success

Source

pub unsafe fn Byond_CallProc( &self, src: *const CByondValue, name: *const c_char, arg: *const CByondValue, arg_count: u4c, result: *mut CByondValue, ) -> bool

Calls an object proc by name. The proc call is treated as waitfor=0 and will return immediately on sleep. Blocks if not on the main thread.

§Arguments
  • src - The object that owns the proc
  • name - Proc name as null-terminated string
  • arg - Array of arguments
  • arg_count - Number of arguments
  • result - Pointer to accept result
§Returns

True on success

Source

pub unsafe fn Byond_CallProcByStrId( &self, src: *const CByondValue, name: u4c, arg: *const CByondValue, arg_count: u4c, result: *mut CByondValue, ) -> bool

Calls an object proc by name, where the name is a string ID. The proc call is treated as waitfor=0 and will return immediately on sleep. Blocks if not on the main thread.

§Arguments
  • src - The object that owns the proc
  • name - Proc name as string ID
  • arg - Array of arguments
  • arg_count - Number of arguments
  • result - Pointer to accept result
§Returns

True on success [Byond_GetStrId()]

Source

pub unsafe fn Byond_CallGlobalProc( &self, name: *const c_char, arg: *const CByondValue, arg_count: u4c, result: *mut CByondValue, ) -> bool

Calls a global proc by name. The proc call is treated as waitfor=0 and will return immediately on sleep. Blocks if not on the main thread.

§Arguments
  • name - Proc name as null-terminated string
  • arg - Array of arguments
  • arg_count - Number of arguments
  • result - Pointer to accept result
§Returns

True on success

Source

pub unsafe fn Byond_CallGlobalProcByStrId( &self, name: u4c, arg: *const CByondValue, arg_count: u4c, result: *mut CByondValue, ) -> bool

Calls a global proc by name, where the name is a string ID. The proc call is treated as waitfor=0 and will return immediately on sleep. Blocks if not on the main thread.

§Arguments
  • name - Proc name as string ID
  • arg - Array of arguments
  • arg_count - Number of arguments
  • result - Pointer to accept result
§Returns

True on success [Byond_GetStrId()]

Source

pub unsafe fn Byond_ToString( &self, src: *const CByondValue, buf: *mut c_char, buflen: *mut u4c, ) -> bool

Uses BYOND’s internals to represent a value as text Blocks if not on the main thread.

§Arguments
  • src - The value to convert to text
  • buf - char array, allocated by caller (can be null if querying length)
  • buflen - Pointer to length of array in bytes; receives the string length (including trailing null) on success, or required length of array if not big enough
§Returns

True on success; false with *buflen=0 for failure; false with *buflen=required size if array is not big enough

Source

pub unsafe fn Byond_Block( &self, corner1: *const CByondXYZ, corner2: *const CByondXYZ, list: *mut CByondValue, len: *mut u4c, ) -> bool

Equivalent to calling block(x1,y1,z1, x2,y2,z2). Blocks if not on the main thread.

§Arguments
  • corner1 - One corner of the block
  • corner2 - Another corner of the block
  • list - CByondValue array, allocated by caller (can be null if querying length)
  • len - Pointer to length of array (in items); receives the number of items read on success, or required length of array if not big enough
§Returns

True on success; false with *len=0 for failure; false with *len=required size if array is not big enough

Source

pub unsafe fn Byond_Length( &self, src: *const CByondValue, result: *mut CByondValue, ) -> bool

Equivalent to calling length(value). Blocks if not on the main thread.

§Arguments
  • src - The value
  • result - Pointer to accept result as a CByondValue (intended for future possible override of length)
§Returns

True on success

Source

pub unsafe fn Byond_LocateIn( &self, type_: *const CByondValue, list: *const CByondValue, result: *mut CByondValue, ) -> bool

Equivalent to calling locate(type), or locate(type) in list. Blocks if not on the main thread.

§Arguments
  • type - The type to locate
  • list - The list to locate in; can be a null pointer instead of a CByondValue to locate(type) without a list
  • result - Pointer to accept result; can be null if nothing is found
§Returns

True on success (including if nothing is found); false on error

Source

pub unsafe fn Byond_LocateXYZ( &self, xyz: *const CByondXYZ, result: *mut CByondValue, ) -> bool

Equivalent to calling locate(x,y,z) Blocks if not on the main thread. Result is null if coords are invalid.

§Arguments
  • xyz - The x,y,z coords
  • result - Pointer to accept result
§Returns

True (always)

Source

pub unsafe fn Byond_New( &self, type_: *const CByondValue, arg: *const CByondValue, arg_count: u4c, result: *mut CByondValue, ) -> bool

Equivalent to calling new type(…) Blocks if not on the main thread.

§Arguments
  • type - The type to create (type path or string)
  • arg - Array of arguments
  • arg_count - Number of arguments
  • result - Pointer to accept result
§Returns

True on success

Source

pub unsafe fn Byond_NewArglist( &self, type_: *const CByondValue, arglist: *const CByondValue, result: *mut CByondValue, ) -> bool

Equivalent to calling new type(arglist) Blocks if not on the main thread.

§Arguments
  • type - The type to create (type path or string)
  • arglist - Arguments, as a reference to an arglist
  • result - Pointer to accept result
§Returns

True on success

Source

pub unsafe fn Byond_Refcount( &self, src: *const CByondValue, result: *mut u4c, ) -> bool

Equivalent to calling refcount(value) Blocks if not on the main thread.

§Arguments
  • src - The object to refcount
  • result - Pointer to accept result
§Returns

True on success

Source

pub unsafe fn Byond_XYZ( &self, src: *const CByondValue, xyz: *mut CByondXYZ, ) -> bool

Get x,y,z coords of an atom Blocks if not on the main thread.

§Arguments
  • src - The object to read
  • xyz - Pointer to accept CByondXYZ result
§Returns

True on success

Source

pub unsafe fn Byond_PixLoc( &self, src: *const CByondValue, pixloc: *mut CByondPixLoc, ) -> bool

Get pixloc coords of an atom Blocks if not on the main thread.

§Arguments
  • src - The object to read
  • pixloc - Pointer to accept CByondPixLoc result
§Returns

True on success

Source

pub unsafe fn Byond_BoundPixLoc( &self, src: *const CByondValue, dir: u1c, pixloc: *mut CByondPixLoc, ) -> bool

Get pixloc coords of an atom based on its bounding box Blocks if not on the main thread.

§Arguments
  • src - The object to read
  • dir - The direction
  • pixloc - Pointer to accept CByondPixLoc result
§Returns

True on success

Source

pub unsafe fn ByondValue_IncRef(&self, src: *const CByondValue)

Increase the persistent reference count of an object used in Byondapi Reminder: Calls only create temporary references when made on the main thread. On other threads, the references are already persistent. Blocks if not on the main thread.

§Arguments
  • src - The object to incref
Source

pub unsafe fn ByondValue_DecRef(&self, src: *const CByondValue)

Mark a persistent reference as no longer in use by Byondapi This is IMPORTANT to call when you make Byondapi calls on another thread, since all the references they create are persistent. This cannot be used for temporary references. See ByondValue_DecTempRef() for those. Blocks if not on the main thread.

§Arguments
  • src - The object to decref
Source

pub unsafe fn ByondValue_DecTempRef(&self, src: *const CByondValue)

Mark a temporary reference as no longer in use by Byondapi Temporary references will be deleted automatically at the end of a tick, so this only gets rid of the reference a little faster. Only works on the main thread. Does nothing on other threads.

§Arguments
  • src - The object to decref
Source

pub unsafe fn Byond_TestRef(&self, src: *mut CByondValue) -> bool

Test if a reference-type CByondValue is valid Blocks if not on the main thread.

§Arguments
  • src - Pointer to the reference to test; will be filled with null if the reference is invalid
§Returns

True if ref is valid; false if not

Source

pub unsafe fn Byond_CRASH(&self, message: *const c_char)

Causes a runtime error to crash the current proc Blocks if not on the main thread.

§Arguments
  • message - Message to use as the runtime error

Trait Implementations§

Source§

impl Deref for ByondApi

Source§

type Target = ByondApi

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl Send for ByondApi

Source§

impl Sync for ByondApi

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.