REBOL 3 Docs | Guide | Concepts | Functions | Datatypes | Errors |
TOC < Back Next > | Updated: 9-Nov-2010 Edit History |
Explains how to embed extensions into a REBOL executable (using the host-kit).
This feature allows you to extend REBOL by embedding your own native and mezzanine code and data within a REBOL executable program. Embedding an extension makes it possible to use the extension and its native command functions without requiring a separate DLL library to accompany your executable program.
If you already know how to make an extension (from prior pages), embedding it is trivial.
The steps are:
This function is defined as:
RL_API void *RL_Extend(REBYTE *source, RXICAL call);
It accepts as arguments the UTF-8/ASCII source code for a module, along with a pointer to its command dispatcher function.
These values are added to the system/catalog/boot-exts block. Later in the boot process, the boot-exts block is processed to import each of its embedded modules.
We define an extension module:
char *ext = "REBOL [\n" "Title: {Hosted extension}\n" "Name: hosted\n" "Type: module\n" "Exports: [add-mul]\n" "]\n" "add-mul: command [{Add and multiply integers.} a b c]\n" ;
and a simple call dispatcher function:
RXIEXT int RX_Call(int cmd, RXIFRM *frm, REBCEC *ctx) { RXA_INT64(frm, 1) = (RXA_INT64(frm, 1) + RXA_INT64(frm, 2)) * RXA_INT64(frm, 3); return RXR_VALUE; }
We then call the RL_Extend function to add it during boot. This is done in the host-main.c code before (or after, it's your choice) the bundled source code init call:
RL_Extend(hext, &RX_Call); // Initialize host bundled source code: RL_Do_Binary(Reb_Init_Code, REB_INIT_SIZE, 0, 0);
After REBOL boots, we can call the add-mul command that was provided:
print add-mul 1 2 3
9
Note that multiple embedded extensions can be added in the same way.
Editor note: how to use the make-ext tool for creating it. Also, mention the host-ext-test.c example.
TOC < Back Next > | REBOL.com - WIP Wiki | Feedback Admin |