Boron 2.1.0
boron_mini.c

This is a basic example of how to use the Boron interpreter.

This is a basic example of how to use the Boron interpreter.

#include <stdio.h>
#include "boron.h"
CFUNC(printHello)
{
int i;
int count = ur_is(a1, UT_INT) ? ur_int(a1) : 1;
(void) ut;
for( i = 0; i < count; ++i )
printf( "Hello World\n" );
ur_setId(res, UT_UNSET);
return UR_OK;
}
static const BoronCFunc myFuncs[] = { printHello };
static const char myFuncSpecs[] = "hello n";
int main()
{
UThread* ut = boron_makeEnv( boron_envParam(&param) ); // Startup.
if( ! ut )
return 255;
boron_defineCFunc( ut, UR_MAIN_CONTEXT, myFuncs, myFuncSpecs,
sizeof(myFuncSpecs)-1 ); // Add our cfunc!.
boron_evalUtf8( ut, "hello 3", -1 ); // Invoke it.
boron_freeEnv( ut ); // Cleanup.
return 0;
}
The Boron programmer interface.
UCell * boron_evalUtf8(UThread *, const char *script, int len)
Run script and put result in the last stack cell.
Definition: eval.c:2033
#define CFUNC(name)
Macro to define C functions.
UThread * boron_makeEnv(UEnvParameters *)
Make Boron environment and initial thread.
Definition: boron.c:721
UStatus boron_defineCFunc(UThread *, UIndex ctxN, const BoronCFunc *funcs, const char *spec, int slen)
Add C functions to context.
Definition: boron.c:388
void boron_freeEnv(UThread *)
Destroy Boron environment.
Definition: boron.c:865
UEnvParameters * boron_envParam(UEnvParameters *)
Initialize UEnvParameters structure to default Boron values.
Definition: boron.c:706
#define ur_setId(c, t)
Set type and initialize the other 24 bits of UCellId to zero.
@ UR_OK
Returned to indicate successful evaluation/operation.
Definition: urlan.h:121
The UEnvParameters struct allows the user to override default buffer and structure sizes.
Definition: urlan.h:488
The UThread struct stores the data specific to a thread of execution.
Definition: urlan.h:309