Skip to content

How to make Io call C function #472

Answered by stevedekorte
iacore asked this question in Q&A
Discussion options

You must be logged in to vote

It's been a while since I've used the C binding so I asked ChatGPT4 for a simple example with just one C function added to the lobby. Here's what it wrote (which looks reasonable, but I'm not sure it's correct). This just adds a method for the function and calls it using doCString so it's not and general purpose binding:

#include <stdio.h>
#include "IoState.h"
#include "IoMessage.h"
#include "IoNumber.h"
#include "IoObject.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);
IoState_init(self);

IoMethodTable methodTable[] = {{…

Replies: 5 comments 3 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@iacore
Comment options

Answer selected by iacore
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@iacore
Comment options

Comment options

You must be logged in to vote
1 reply
@iacore
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants