Using io in C
A few days ago, I stumbled upon a tiny little language called “io”. Its syntax is unlike every mainstream language that I know. Even Smalltalk pales in front of its elegant syntax.
After a few days of fiddling with it, I decided to embed it in my projects. However, there exists no documentation on how to easily do this. I asked on the Io Forum. They replied.
Long story short, here’s how you say hello world in io and C.
#include <stdio.h>
#include <io/IoVM.h>
IoObject* hello(IoObject *self, IoObject *locals, IoMessage *m) {
puts("Hello world!");
return self;
}
int main(int argc, const char *argv[]) {
IoState *self = IoState_new();
IoObject *lobby = IoState_lobby(self);
IoObject_addMethod_(lobby, IoState_symbolWithCString_(self, "hello"), hello);
// this also works
// IoMethodTable methodTable[] = {{"hello", hello}, {NULL, NULL}};
// IoObject_addMethodTable_(lobby, methodTable);
IoState_doCString_(self, "hello print");
IoState_free(self);
return 0;
}
From now on, io will be the scripting language I use.
With that out of the way, here are some tips on how to use io.
The
self
slot is only set during a method or block. You can think of it as a local variable. Unlike Javascriptthis
, it is not available at top-level.
If you want to know what
foo
does, dofoo type
,foo slotSummary
,foo proto slotSummary
.