Skip to content

Commit 38cbba0

Browse files
committed
Add function type helper function
Follow up to #254
1 parent 42ef04a commit 38cbba0

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/zend/ex.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ use crate::{
66
types::{ZendClassObject, ZendObject, Zval},
77
};
88

9+
use super::function::Function;
10+
911
/// Execute data passed when a function is called from PHP.
1012
///
1113
/// This generally contains things related to the call, including but not
@@ -194,6 +196,16 @@ impl ExecuteData {
194196
self.This.object_mut()
195197
}
196198

199+
/// Attempt to retrieve the function that is being called.
200+
pub fn function(&self) -> Option<&Function> {
201+
unsafe { self.func.as_ref() }
202+
}
203+
204+
/// Attempt to retrieve the previous execute data on the call stack.
205+
pub fn previous(&self) -> Option<&Self> {
206+
unsafe { self.prev_execute_data.as_ref() }
207+
}
208+
197209
/// Translation of macro `ZEND_CALL_ARG(call, n)`
198210
/// zend_compile.h:578
199211
///

src/zend/function.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
33
use std::{fmt::Debug, os::raw::c_char, ptr};
44

5-
use crate::ffi::zend_function_entry;
5+
use crate::{
6+
ffi::{zend_function, zend_function_entry},
7+
flags::FunctionType,
8+
};
69

710
/// A Zend function entry.
811
pub type FunctionEntry = zend_function_entry;
@@ -36,3 +39,11 @@ impl FunctionEntry {
3639
Box::into_raw(Box::new(self))
3740
}
3841
}
42+
43+
pub type Function = zend_function;
44+
45+
impl Function {
46+
pub fn type_(&self) -> FunctionType {
47+
FunctionType::from(unsafe { self.type_ })
48+
}
49+
}

0 commit comments

Comments
 (0)