-
-
Save Orvid/b3d6da28f2efb41bee0d83f656030779 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "hphp/runtime/ext/extension.h" | |
#include "hphp/runtime/base/execution-context.h" | |
#include "hphp/runtime/vm/native-data.h" | |
void add(int *x, int *y, int *result) { | |
*result = *x + *y; | |
} | |
namespace HPHP { | |
void HHVM_FUNCTION(add, VRefParam a, VRefParam b, VRefParam c) { | |
int ta = a.toInt64(); | |
int tb = b.toInt64(); | |
int tc = 0; | |
add(&ta, &tb, &tc); | |
a.assignIfRef(ta); | |
b.assignIfRef(tb); | |
c.assignIfRef(tc); | |
} | |
class PtrExtension : public Extension { | |
public: | |
PtrExtension(): Extension("Ptr", "1.0") {} | |
void moduleInit() override { | |
HHVM_FE(add); | |
loadSystemlib(); | |
} | |
} s_Ptr_extension; | |
HHVM_GET_MODULE(Ptr); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?hh | |
<<__Native>> | |
function add(int &$a, int &$b, int &$c): void; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$a = 37; | |
$b = 42; | |
$c = 0; // $c must be defined and not null. | |
print " a = $a\n"; | |
print " b = $b\n"; | |
# Call the add() function wuth some pointers | |
add($a, $b, $c); | |
print " $a + $b = $c\n"; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment