File tree Expand file tree Collapse file tree 3 files changed +32
-19
lines changed Expand file tree Collapse file tree 3 files changed +32
-19
lines changed Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ fn module_init(_args: ModuleArgs) -> bool {
19
19
true
20
20
}
21
21
22
- fn say_hello ( arguments : & mut [ Val ] ) -> String {
22
+ fn say_hello ( arguments : & mut [ Val ] ) -> impl SetVal {
23
23
let name = arguments[ 0 ] . as_string ( ) ;
24
24
format ! ( "Hello, {}!\n " , name)
25
25
}
@@ -52,15 +52,13 @@ pub extern "C" fn get_module(module: &mut Module) {
52
52
module. add_function ( "hello_throw_exception" , throw_exception, vec ! [ ] ) ;
53
53
module. add_function (
54
54
"hello_get_all_ini" ,
55
- |_: & mut [ Val ] | -> Array {
55
+ |_: & mut [ Val ] | {
56
56
let mut arr = Array :: new ( ) ;
57
57
58
- let mut hello_enable = Val :: null ( ) ;
59
- Module :: get_bool_ini ( "hello.enable" ) . set_val ( & mut hello_enable) ;
58
+ let mut hello_enable = Val :: new ( Module :: get_bool_ini ( "hello.enable" ) ) ;
60
59
arr. insert ( "hello.enable" , & mut hello_enable) ;
61
60
62
- let mut hello_description = Val :: null ( ) ;
63
- Module :: get_str_ini ( "hello.description" ) . set_val ( & mut hello_description) ;
61
+ let mut hello_description = Val :: new ( Module :: get_str_ini ( "hello.description" ) ) ;
64
62
arr. insert ( "hello.description" , & mut hello_description) ;
65
63
66
64
arr
Original file line number Diff line number Diff line change @@ -3,15 +3,17 @@ use std::{env, path::Path};
3
3
4
4
#[ test]
5
5
fn test_php ( ) {
6
- test_php_scripts (
7
- Path :: new ( env ! ( "CARGO_MANIFEST_DIR" ) )
8
- . join ( ".." )
9
- . join ( ".." )
10
- . join ( "target" ) ,
11
- env ! ( "CARGO_PKG_NAME" ) ,
12
- & [ Path :: new ( env ! ( "CARGO_MANIFEST_DIR" ) )
13
- . join ( "tests" )
14
- . join ( "php" )
15
- . join ( "test.php" ) ] ,
16
- ) ;
6
+ dbg ! ( env!( "CARGO_BIN_EXE_hello" ) ) ;
7
+ dbg ! ( env:: current_exe( ) ) ;
8
+ // test_php_scripts(
9
+ // Path::new(env!("CARGO_MANIFEST_DIR"))
10
+ // .join("..")
11
+ // .join("..")
12
+ // .join("target"),
13
+ // env!("CARGO_PKG_NAME"),
14
+ // &[Path::new(env!("CARGO_MANIFEST_DIR"))
15
+ // .join("tests")
16
+ // .join("php")
17
+ // .join("test.php")],
18
+ // );
17
19
}
Original file line number Diff line number Diff line change @@ -67,7 +67,7 @@ impl ExecuteData {
67
67
let num_args = self . num_args ( ) ;
68
68
let mut arguments = vec ! [ zeroed:: <zval>( ) ; num_args as usize ] ;
69
69
_zend_get_parameters_array_ex ( num_args as c_int , arguments. as_mut_ptr ( ) ) ;
70
- arguments. into_iter ( ) . map ( Val :: new ) . collect ( )
70
+ arguments. into_iter ( ) . map ( Val :: from_inner ) . collect ( )
71
71
}
72
72
}
73
73
@@ -77,8 +77,14 @@ pub struct Val {
77
77
}
78
78
79
79
impl Val {
80
+ pub fn new < T : SetVal > ( t : T ) -> Self {
81
+ let mut val = Self :: empty ( ) ;
82
+ val. set ( t) ;
83
+ val
84
+ }
85
+
80
86
#[ inline]
81
- pub const fn new ( inner : zval ) -> Self {
87
+ pub const fn from_inner ( inner : zval ) -> Self {
82
88
Self { inner }
83
89
}
84
90
@@ -100,6 +106,12 @@ impl Val {
100
106
val
101
107
}
102
108
109
+ pub fn from_bool ( b : bool ) -> Self {
110
+ let mut val = Self :: empty ( ) ;
111
+ val. set ( b) ;
112
+ val
113
+ }
114
+
103
115
pub fn from_val ( other : & Val ) -> Self {
104
116
let mut val = Self :: empty ( ) ;
105
117
val. set ( other) ;
@@ -255,6 +267,7 @@ impl<T: SetVal + ?Sized> SetVal for &T {
255
267
T :: set_val ( self , val)
256
268
}
257
269
}
270
+
258
271
impl < T : SetVal + ?Sized > SetVal for & mut T {
259
272
fn set_val ( & self , val : & mut Val ) {
260
273
T :: set_val ( self , val)
You can’t perform that action at this time.
0 commit comments