demonstrates the use of the osevm_respondToString hook to respond to specific strings / addresses
The VM responds by default to a small number of prefixes, such as /!, /@, and /$, which mean "funcall" or "execute", "assign", and "lookup" respectively. Any string that is processed by the VM that doesn't have a prefix that the VM responds to is simply pushed onto the stack. This example shows how to implement a hook and install it in the VM to respond to messages (strings) that the VM doesn't respond to, without need for a special prefix.
#include <stdio.h>
#include <string.h>
#include "ose_print.h"
#define NUM_BYTES 65536
{
while(!ose_bundleIsEmpty(stack))
{
if(ose_peekType(stack) == OSETT_MESSAGE)
{
if(ose_peekMessageArgType(stack) == OSETT_STRING)
{
const char * const str = ose_peekString(stack);
printf("%s ", str);
ose_drop(stack);
}
else
{
ose_drop(stack);
}
}
else
{
ose_drop(stack);
}
}
printf("\n");
}
{
printf("Stay classy!\n");
}
{
const char * const str = ose_peekString(vm_stack);
if(!strcmp(str, "/greet"))
{
ose_drop(vm_stack);
greet(vm_stack);
}
else if(!strcmp(str, "/signoff"))
{
signoff(vm_stack);
}
else
{
}
}
int main(int ac, char **av)
{
char bytes[NUM_BYTES];
ose_bundle bundle = ose_newBundleFromCBytes(NUM_BYTES, bytes);
1024, 1024, 1024, 1024, 1024);
ose_pushMessage(vm_input, "/greet", strlen("/greet"), 2,
OSETT_STRING, "Hello",
OSETT_STRING, "World!");
osevm_run(vm);
ose_pushMessage(vm_input, "/signoff", strlen("/signoff"), 0);
osevm_run(vm);
return 0;
}
provides global definitions and types
contains functions that structure an OSC bundle for use with other parts of this library
contains functions that manipulate the structure and contents of an OSE bundle and its elements
#define OSEVM_INPUT(osevm)
Get the input bundle.
Definition ose_vm.h:362
#define OSEVM_STACK(osevm)
Get the stack bundle.
Definition ose_vm.h:368