pub struct ItemRef { /* private fields */ }Expand description
A reference to a Lua value.
When running .execute or .store on a ItemRef.
The global lua variable: self will be the referenced value this links to.
Can also be used as an argument to a Script with arg_ref or named_arg_ref.
Implementations§
Source§impl ItemRef
impl ItemRef
Sourcepub unsafe fn new(resolve: Resolve, id: u64) -> Self
pub unsafe fn new(resolve: Resolve, id: u64) -> Self
Creates a new ItemRef with it’s lua module id and the Resolve instance it was retrieved from.
§Safety
This is unsafe since if you were to mismatch the id and which Resolve instance it was gathered from then it would be undefined behavior.
Only ever use this if you know for a fact that the id you pass it derives from the same Resolve instance and hasn’t already been dropped in the module.
Sourcepub async fn execute<'c, T>(
&'c self,
script: impl Into<Script<'c>>,
) -> Result<T, Error>where
T: DeserializeOwned,
pub async fn execute<'c, T>(
&'c self,
script: impl Into<Script<'c>>,
) -> Result<T, Error>where
T: DeserializeOwned,
Execute some lua code, setting self to the stored reference value and returning what the code returned.
Look at Resolve::execute for more info on how it works.
§Errors
If the module executing the code fails or if the script can’t be sent
Sourcepub async fn store<'c>(
&'c self,
script: impl Into<Script<'c>>,
) -> Result<ItemRef, Error>
pub async fn store<'c>( &'c self, script: impl Into<Script<'c>>, ) -> Result<ItemRef, Error>
Store a reference to Lua value in Rust,
global variable self is set to the value stored in the ItemRef.
Look at Resolve::store for more info on how it works.
§Errors
If the module executing the code fails, if the script can’t be sent or if the returned value is nil
Sourcepub async fn store_option<'c>(
&'c self,
script: impl Into<Script<'c>>,
) -> Result<Option<ItemRef>, Error>
pub async fn store_option<'c>( &'c self, script: impl Into<Script<'c>>, ) -> Result<Option<ItemRef>, Error>
Sourcepub async fn store_list<'c>(
&'c self,
script: impl Into<Script<'c>>,
) -> Result<ItemRefList, Error>
pub async fn store_list<'c>( &'c self, script: impl Into<Script<'c>>, ) -> Result<ItemRefList, Error>
Store multiple references to Lua values in Rust,
Look at Resolve::store_list for more info on how it works.
§Errors
If the module executing the code fails or if the script can’t be sent.
Or if the returned value from lua was not a table
Sourcepub async fn value<T>(&self) -> Result<T, Error>where
T: DeserializeOwned,
pub async fn value<T>(&self) -> Result<T, Error>where
T: DeserializeOwned,
Returns the referenced value directly.
Reference is still valid, this just clones the value.
§Errors
If the module executing the code fails or if the script can’t be sent
Sourcepub async unsafe fn manual_drop(resolve: Resolve, id: u64)
pub async unsafe fn manual_drop(resolve: Resolve, id: u64)
Sends a packet to the lua module to drop the reference in the lua context.
This can be used to ensure a reference is dropped before doing anything else.
Aka, this is blocking if you .await it since the normal Drop can finish anytime it wants in the background.
§Safety
You must ensure that the id came from correct Resolve instance and that the value hasn’t already been dropped
§Error
This will silently fail and print its err to stderr if it fails.