Skip to content

Instantly share code, notes, and snippets.

@Orvid
Forked from ng420/ext_Ptr.cpp
Last active June 15, 2016 16:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Orvid/b3d6da28f2efb41bee0d83f656030779 to your computer and use it in GitHub Desktop.
Save Orvid/b3d6da28f2efb41bee0d83f656030779 to your computer and use it in GitHub Desktop.
#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);
}
<?hh
<<__Native>>
function add(int &$a, int &$b, int &$c): void;
<?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