Struct red4ext_rs::types::StackFrame
source · pub struct StackFrame(/* private fields */);
Expand description
A script stack frame.
Implementations§
source§impl StackFrame
impl StackFrame
sourcepub fn parent(&self) -> Option<&StackFrame>
pub fn parent(&self) -> Option<&StackFrame>
Returns the parent stack frame.
sourcepub fn parent_iter(&self) -> impl Iterator<Item = &StackFrame>
pub fn parent_iter(&self) -> impl Iterator<Item = &StackFrame>
Returns an iterator over all parent stack frames.
sourcepub fn context(&self) -> Option<&IScriptable>
pub fn context(&self) -> Option<&IScriptable>
Returns the context of the stack frame, the this
pointer.
sourcepub fn locals(&self) -> ValueContainer
pub fn locals(&self) -> ValueContainer
Returns the memory address where local variables are stored.
sourcepub fn params(&self) -> ValueContainer
pub fn params(&self) -> ValueContainer
Returns the memory address where parameters are stored.
sourcepub unsafe fn instr_at<I: Instr>(&self, offset: isize) -> Option<&I>
pub unsafe fn instr_at<I: Instr>(&self, offset: isize) -> Option<&I>
Interprets the code at specified offset as an instruction of type I
.
sourcepub unsafe fn get_arg<T>(&mut self) -> T
pub unsafe fn get_arg<T>(&mut self) -> T
Retrieves the next argument from the stack frame.
§Safety
The type T
must be the correct type of the next argument.
sourcepub fn args_state(&self) -> StackArgsState
pub fn args_state(&self) -> StackArgsState
Captures the state of stack arguments.
Use its returned value with restore_args to restore the state of arguments.
sourcepub unsafe fn restore_args(&mut self, state: StackArgsState)
pub unsafe fn restore_args(&mut self, state: StackArgsState)
Allows to reset the state of function arguments.
§Safety
The state must be saved before reading arguments.
The state must be restored before passing it back to game code.
Stack arguments should neither be partially read, nor partially restored.
§Example
unsafe extern "C" fn detour(
i: *mut IScriptable,
f: *mut StackFrame,
a3: VoidPtr,
a4: VoidPtr,
cb: unsafe extern "C" fn(i: *mut IScriptable, f: *mut StackFrame, a3: VoidPtr, a4: VoidPtr),
) {
let frame = &mut *f;
// stack must be saved before reading stack function parameters
let state = frame.args_state();
// assuming our function accepts these 3 parameters
let event_name: CName = StackFrame::get_arg(frame);
let entity_id: EntityId = StackFrame::get_arg(frame);
let emitter_name: CName = StackFrame::get_arg(frame);
if should_detour(event_name) {
// do something else...
} else {
// since we've read stack function arguments,
// stack arguments must be restored before callback.
frame.restore_args(state);
cb(i, f, a3, a4);
}
}