Skip to content

Instantly share code, notes, and snippets.

@gaspard
Created July 17, 2011 09:02
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save gaspard/1087380 to your computer and use it in GitHub Desktop.
Save gaspard/1087380 to your computer and use it in GitHub Desktop.
Simple C++ class with C interface for Luajit ffi bindings
// g++ simple.cpp -shared -o libsimple.dylib
#include <stdio.h>
class Simple {
int id_;
public:
Simple(int id);
~Simple();
int id();
};
Simple::Simple(int id) : id_(id) {
printf("[%p:%i] Simple()\n", this, id_);
}
Simple::~Simple() {
printf("[%p:%i] ~Simple()\n", this, id_);
}
int Simple::id() {
return id_;
}
extern "C" {
Simple *Simple_Simple(int id) {
return new Simple(id);
}
void Simple__gc(Simple *this_) {
delete this_;
}
int Simple_id(Simple *this_) {
return this_->id();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment