Add function type helper function

Follow up to #254
This commit is contained in:
Joe Hoyle 2023-07-19 15:30:49 +02:00
parent 42ef04a8ae
commit 38cbba0457
2 changed files with 24 additions and 1 deletions

View File

@ -6,6 +6,8 @@ use crate::{
types::{ZendClassObject, ZendObject, Zval}, types::{ZendClassObject, ZendObject, Zval},
}; };
use super::function::Function;
/// Execute data passed when a function is called from PHP. /// Execute data passed when a function is called from PHP.
/// ///
/// This generally contains things related to the call, including but not /// This generally contains things related to the call, including but not
@ -194,6 +196,16 @@ impl ExecuteData {
self.This.object_mut() self.This.object_mut()
} }
/// Attempt to retrieve the function that is being called.
pub fn function(&self) -> Option<&Function> {
unsafe { self.func.as_ref() }
}
/// Attempt to retrieve the previous execute data on the call stack.
pub fn previous(&self) -> Option<&Self> {
unsafe { self.prev_execute_data.as_ref() }
}
/// Translation of macro `ZEND_CALL_ARG(call, n)` /// Translation of macro `ZEND_CALL_ARG(call, n)`
/// zend_compile.h:578 /// zend_compile.h:578
/// ///

View File

@ -2,7 +2,10 @@
use std::{fmt::Debug, os::raw::c_char, ptr}; use std::{fmt::Debug, os::raw::c_char, ptr};
use crate::ffi::zend_function_entry; use crate::{
ffi::{zend_function, zend_function_entry},
flags::FunctionType,
};
/// A Zend function entry. /// A Zend function entry.
pub type FunctionEntry = zend_function_entry; pub type FunctionEntry = zend_function_entry;
@ -36,3 +39,11 @@ impl FunctionEntry {
Box::into_raw(Box::new(self)) Box::into_raw(Box::new(self))
} }
} }
pub type Function = zend_function;
impl Function {
pub fn type_(&self) -> FunctionType {
FunctionType::from(unsafe { self.type_ })
}
}