Skip to content

Instantly share code, notes, and snippets.

@bpetering
Created January 2, 2016 10:43
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 bpetering/02f5062933ba6db2933f to your computer and use it in GitHub Desktop.
Save bpetering/02f5062933ba6db2933f to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
struct foo {
int x;
};
void foo_init(struct foo **f) {
*f = malloc(sizeof(struct foo));
printf("malloc'd, pointer = %p\n", (void *) *f);
}
void foo_shutdown(struct foo *f) {
printf("freeing, pointer = %p\n", (void *) f);
free(f);
}
void foo_test() { printf("foo\n"); }
use NativeCall;
class foo is repr('CPointer') { }
sub foo_init(Pointer[foo] $x is rw)
is native('test')
{ * }
sub foo_shutdown(foo)
is native('test')
{ * }
sub foo_test()
is native('test')
{ * }
# foo_test(); # works
my Pointer[foo] $p;
foo_init($p);
say $p.deref;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment