symisc / PH7

An Embedded Implementation of PHP (C Library)
http://ph7.symisc.net
Other
494 stars 68 forks source link

How to get return value from specific function #27

Closed morpheouss closed 6 years ago

morpheouss commented 6 years ago

I am writing a program that embeds ph7. It executes script and calls a function. This functions returns some value. How can I get this value outside script?

symisc commented 6 years ago

Either create a super global variable and register it via ph7_vm_config() using the PH7_VM_CONFIG_CREATE_SUPER verb or register a foreign function and call it the last one before you die. On the foreign function body (i.e. your C code) you can extract the variable content passed to you as an argument.

morpheouss commented 6 years ago

Thats not a solution for me. I need to take the value returned by specified function and/or whole script. If script uses exit I can catch it via ph7_vm_exec. But returned value is not catched like that. How can I take the value returned by script?

symisc commented 6 years ago

That's the only way to deal with variables shared between C and PHP. Jx9 introduces the jx9_vm_extract_variable() interface that let you do this specifically which is unfortunately not implemented in PH7.