This Article IsCreated at 2023-07-12Last Modified at 2024-01-19Referenced as ia.www.b09Written In the Style of A Hello World Tutorial

How to Run io Scripts From C

A few days ago, I stumbled upon a simple elegant 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 a 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 Javascript this, it is not available at top-level.

If you want to know what foo does, do foo type, foo slotSummary, foo proto slotSummary.


Update (2024-01-19):

As it turns out, you can use stdin/stdout to run io code. Example command: `io -e ‘doFile(“definitions.io”);“awawawa” print’.