dt2
dt2

Reputation: 183

For rebol3: Want to get started with native extensions on linux. How do I write a hello-world?

I know how to write some 100 lines C, but I do not know how to read/organize larger source like Rebol. Somewhere was a tutorial with hostkit and dll, but it seems R3 is now statically linked. So I do not know where to look.

How would I write a native which gets a value and returns another? Where to put it in the source? What to obey, like telling the GC I created something in C?

Also, how can I embed R3 in other programms, to call it from Python or Node? I ask for Python/Node part comes later. But my learning-main should access R3 in a similar way. Means dll. And are there some typical hooks for startup/shutdown etc in such ffi's?

[Edit: forgot to mention: it is for Rebol 3.]

Upvotes: 2

Views: 287

Answers (1)

That's two questions. :-)


Regarding the first (about adding a native)... it's probably best elaborated as developer documentation on a Wiki. Questions in the tag should generally be more about the language from a user's point of view. The answers regarding source code itself typically will be long, and there's really only a few people who can answer it, or care about the answer (what StackOverflow calls "too localized"). And it will wind up being more of a question at that point, if anything.

So telling the developers to get their act together and write that documentation and put it in a centrally organized place is probably the best idea! :-P But I actually did try this myself. I added a set-env native to set environment variables from the interpreter, and you can look at the diffs it took to do that in GitHub for a bit of an idea.

add SET-ENV, tweaks to host api for environment string handling

An important thing to remember is that when you touch certain files, you have to run make prep which does a lot of scanning and code generation automatically. Adding a native is one of those things where you're definitely going to have to do that, each time you change to an interface that fundamental.


As for your second question, which is more of a user-facing question about interpreter embedding, one of the first places to look is just in how the simple REPL is implemented. There are two versions in the main repository right now, one for Posix and one for Windows.

https://github.com/rebol/r3/blob/master/src/os/host-main.c

So a string goes in and a string comes out. But there are more complicated forms of interaction, and you can get to them from reb-host.h, which includes these files from src/include

#include "reb-config.h"

#include "reb-c.h"
#include "reb-ext.h"        // includes reb-defs.h
#include "reb-args.h"
#include "reb-device.h"
#include "reb-file.h"
#include "reb-event.h"
#include "reb-evtypes.h"
#include "reb-net.h"
#include "reb-filereq.h"

#include "reb-gob.h"
#include "reb-lib.h"

So you can look through those files for the API as it existed at the moment of the December-12th open-sourcing. Things will be evolving, and hopefully much better documented. But for now that's what seems to be available. You could link the host kit as a shared/DLL or static library, it depends on your build settings and what compiler you use.

Upvotes: 1

Related Questions