From 37c38c70de43d9d9ee3c9f0e2f175e19bcc0b485 Mon Sep 17 00:00:00 2001 From: Emiel Bruijntjes Date: Tue, 10 Sep 2013 09:54:14 -0700 Subject: When registering functions, it now is also possible to specify the signature of the parameters --- tests/simple/simple.cpp | 28 ++++++++++++++++------------ tests/simple/simple.php | 10 +++++++++- 2 files changed, 25 insertions(+), 13 deletions(-) (limited to 'tests') diff --git a/tests/simple/simple.cpp b/tests/simple/simple.cpp index 954bfa9..2ab177f 100644 --- a/tests/simple/simple.cpp +++ b/tests/simple/simple.cpp @@ -17,16 +17,8 @@ using namespace std; static Php::Value my_plus(Php::Parameters ¶ms) { - cout << "my_plus called" << endl; - - cout << "params: " << params.size() << endl; - string p1 = params[0]; string p2 = params[1]; - - cout << "p1: " << p1 << endl; - cout << "p2: " << p2 << endl; - return p1 + p2; } @@ -35,9 +27,15 @@ class MyCustomFunction : public Php::Function public: MyCustomFunction(const char *name) : Function(name) {} + }; + + + + + // symbols are exported according to the "C" language extern "C" { @@ -47,13 +45,19 @@ extern "C" // create extension static Php::Extension extension("simple","1.0"); - // define the functions - extension.add("my_plus", my_plus); - extension.add("my_concat", my_concat); + // define the functionsnm + extension.add("my_plus", my_plus, { + Php::ByVal("a", Php::stringType), + Php::ByVal("b", Php::arrayType), + Php::ByVal("c", "MyClass"), + Php::ByRef("d", Php::stringType) + }); + +// extension.add("my_concat", my_concat); extension.add(new MyCustomFunction("my_custom")); // define classes -// extension.add("my_class", MyCustomClass()); +// extension.add("my_class", MyCustomClass()); // return the module entry return extension.module(); diff --git a/tests/simple/simple.php b/tests/simple/simple.php index a6bf7f5..6f70a7a 100644 --- a/tests/simple/simple.php +++ b/tests/simple/simple.php @@ -10,7 +10,15 @@ class XXX $myvar = "hoi"; -$result = my_plus($myvar, 1, 2, 3, "blabla", new XXX()); +class MyClass { + + public function __toString() + { + return "aksjdfhsdfkj"; + } +} + +$result = my_plus(new MyClass(), array(), new MyClass(), $myvar, "blabla", new XXX()); echo("myvar = $myvar\n"); -- cgit v1.2.3