Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Simple C++ class with C interface for Luajit ffi bindings
// g++ simple.cpp -shared -o libsimple.dylib
#include <stdio.h>
class Simple {
int id_;
Simple(int id);
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