Working on better C++ bindings for Io
I'm working on a C++ binding library for Io that allows you to make your C++ objects callable from Io without typing a lot of code. It's called LikeMagic. ("Any sufficiently advanced technology is indistinguishable from magic." --Arthur C. Clarke)
Contrived example:
// Here's an existing C++ class we want to bind to Io.
class SomeClass
{
int GetNum();
void SetNum(int n);
int AddTwo(int a, int b);
// various other functions
};
// Here's the LikeMagic binding:
class Binds_SomeClass
: public LikeMagic::TypeConverter<SomeClass, Backend_Io>
{
public:
BoundTestObj()
{
BIND(GetNum);
BIND(OtherF);
BIND(SetNum);
BIND(AddTwo);
BIND(CompareWith);
BIND(GetHalf);
BIND(SetHalf);
}
} instance;
/*
LikeMagic only requires that you:
1. Inherit from the TypeConverter class
2. Pass the names of all the methods to BIND().
What you get from this is:
- All the Io callback functions registered for you.
- Creates an IoMethodTable and Io-callable wrapper functions
for all the methods you passed to the BIND() macro.
- Automatically converts the arguments in the Io message to the
equivalent C++ types to pass to the C++ function in BIND().
- Automatically converts the value returned by the C++ function
to an equivalent Io primitive or LikeMagic bound Io object.
- The TypeConverter you just made will automatically be picked up
and used if some other function returns this type of object to Io.
*/