Function xsCreateMachine

Returns a machine if successful, otherwise null.

xs.bindings.xsMachineRecord* xsCreateMachine (
  const(xs.bindings.xsCreationRecord*) creation,
  string name,
  void* context = null
);

xs.bindings.xsMachineRecord* xsCreateMachine (
  const(xs.bindings.xsCreationRecord*) creation,
  const(char*) name,
  void* context = null
);

Regarding the parameters of the machine that are specified in the xsCreation structure:

Parameters

NameDescription
creationThe parameters of the machine
nameThe name of the machine as a string
contextThe initial context of the machine, or null

Examples

The following example illustrates the use of xsCreateMachine and xsDeleteMachine.

int main(int argc, char* argv[]) {
typedef struct {
int argc;
char** argv;
} xsContext;

void xsMainContext(xsMachine* theMachine, int argc, char* argv[])
{
xsContext* aContext;

aContext = malloc(sizeof(xsContext));
if (aContext) {
aContext->argc = argc;
aContext->argv = argv;
xsSetContext(theMachine, aContext);
xsSetContext(theMachine, NULL);
free(aContext);
}
else
fprintf(stderr, "### Cannot allocate context\n");
}

xsCreation aCreation = {
128 * 1024 * 1024,	/* initialChunkSize */
16 * 1024 * 1024, 	/* incrementalChunkSize */
4 * 1024 * 1024, 	/* initialHeapCount */
1 * 1024 * 1024,	/* incrementalHeapCount */
1024,			/* stack count */
2048+1024,		/* key count */
1993,			/* name modulo */
127			/* symbol modulo */
};
xsMachine* aMachine;

aMachine = xsCreateMachine(&aCreation, "machine", NULL);
if (aMachine) {
xsMainContext(aMachine, argc, argv);
xsDeleteMachine(aMachine);
}
else
fprintf(stderr, "### Cannot allocate machine\n");
return 0;
}