HiveMind
Functions | Variables
BittyBuzzUserFunctions Namespace Reference

Namespace to regroup the user functions, ie: custom functions that will be available in the buzz script. The functions needs to be registered using bbzvm_function_register. More...

Functions

void log ()
 Logs to the default output Signature log(args...) More...
 
void registerClosure ()
 register a new function, exposing it to the remote composant of the swarm Signature register_closure(fname, closure, args_desc) More...
 
void callHostFunction ()
 calls a function to a host Signature call_host_function(agent_id, fname, params) More...
 
void callBuzzFunction ()
 calls a function to a buzz Signature call_buzz_function(agent_id, fname, params) More...
 
void isNil ()
 Checks if a variable is nil Signature isnil(arg1) More...
 
void isInt ()
 Checks if a variable is an int Signature isint(arg1) More...
 
void isFloat ()
 Checks if a variable is a float. More...
 
void isString ()
 Checks if a variable is a float Signature istable(arg1) More...
 
void isTable ()
 Checks if a variable is a table Signature istable(arg1) More...
 
void isClosure ()
 Checks if a variable is a function closure Signature isclosure(arg1) More...
 
void isLambdaClosure ()
 Checks if a variable is a lambda, unamed closure Signature islambda_closure(arg1) More...
 
void toInt ()
 Casts a type to int Signature int(arg1) More...
 
void toFloat ()
 Casts a type to float Signature float(arg1) More...
 
void delay ()
 wait for a certain delay Signature delay(arg1) Warning this function make the whole VM sleep which can prevents the VM to processes messages from it's host or the swarm. Eventually the queue can overflow, you should use the executor to execute something every X steps. It is not recommended to use. More...
 

Variables

int16_t g_vmStepDelayMs = 0
 The delay between each call of the step function in buzz. More...
 

Detailed Description

Namespace to regroup the user functions, ie: custom functions that will be available in the buzz script. The functions needs to be registered using bbzvm_function_register.

Function Documentation

◆ callBuzzFunction()

void BittyBuzzUserFunctions::callBuzzFunction ( )

calls a function to a buzz Signature call_buzz_function(agent_id, fname, params)

This closure expects three parameters.

  1. the id of the agent to call (0 for broadcast, using your own id is just a complicated a long way to call a function)
  2. the name of the function
  3. a table with the list of arguments

The table argument's must be by index from 0 to N-1 args.

call_buzz_function(id, "functionName", {.0 = 42, .1 = 43});
Here is the call graph for this function:
Here is the caller graph for this function:

◆ callHostFunction()

void BittyBuzzUserFunctions::callHostFunction ( )

calls a function to a host Signature call_host_function(agent_id, fname, params)

This closure expects three parameters.

  1. the id of the agent to call (0 for broadcast, id for local)
  2. the name of the function
  3. a table with the list of arguments

The table argument's must be by index from 0 to N-1 args.

call_host_function(id, "functionName", {.0 = 42, .1 = 43});
Here is the call graph for this function:
Here is the caller graph for this function:

◆ delay()

void BittyBuzzUserFunctions::delay ( )

wait for a certain delay Signature delay(arg1) Warning this function make the whole VM sleep which can prevents the VM to processes messages from it's host or the swarm. Eventually the queue can overflow, you should use the executor to execute something every X steps. It is not recommended to use.

This closure expects one positive int

  1. the time toe wait
    delay(10); # Waits for 10ms
Here is the caller graph for this function:

◆ isClosure()

void BittyBuzzUserFunctions::isClosure ( )

Checks if a variable is a function closure Signature isclosure(arg1)

This closure expects one parameter

  1. the variable to verify the type returns 1 on true, 0 on false
    if(isclosure(some_val)){
    do_stuff();
    }
Here is the caller graph for this function:

◆ isFloat()

void BittyBuzzUserFunctions::isFloat ( )

Checks if a variable is a float.

This closure expects one parameter

  1. the variable to verify the type returns 1 on true, 0 on false
    if(isfloat(some_val)){
    do_stuff();
    }
Here is the caller graph for this function:

◆ isInt()

void BittyBuzzUserFunctions::isInt ( )

Checks if a variable is an int Signature isint(arg1)

This closure expects one parameter

  1. the variable to verify the type returns 1 on true, 0 on false
    if(isint(some_val)){
    do_stuff(
    }
Here is the caller graph for this function:

◆ isLambdaClosure()

void BittyBuzzUserFunctions::isLambdaClosure ( )

Checks if a variable is a lambda, unamed closure Signature islambda_closure(arg1)

This closure expects one parameter

  1. the variable to verify the type returns 1 on true, 0 on false
    if(islambda_closure(some_val)){
    do_stuff();
    }
Here is the caller graph for this function:

◆ isNil()

void BittyBuzzUserFunctions::isNil ( )

Checks if a variable is nil Signature isnil(arg1)

This closure expects one parameter

  1. the variable to verify the type returns 1 on true, 0 on false
    if(isnil(some_val)){
    do_stuff();
    }
Here is the caller graph for this function:

◆ isString()

void BittyBuzzUserFunctions::isString ( )

Checks if a variable is a float Signature istable(arg1)

This closure expects one parameter

  1. the variable to verify the type returns 1 on true, 0 on false
    if(isstring(some_val)){
    do_stuff();
    }
Here is the caller graph for this function:

◆ isTable()

void BittyBuzzUserFunctions::isTable ( )

Checks if a variable is a table Signature istable(arg1)

This closure expects one parameter

  1. the variable to verify the type returns 1 on true, 0 on false
    if(istable(some_val)){
    do_stuff();
    }
Here is the caller graph for this function:

◆ log()

void BittyBuzzUserFunctions::log ( )

Logs to the default output Signature log(args...)

This closure can take variadic arguments. So the number and type can vary.

log("Hello world, magic number: ", 42);
log("Goodbye", "world", "magic number: ", 42);
Here is the call graph for this function:
Here is the caller graph for this function:

◆ registerClosure()

void BittyBuzzUserFunctions::registerClosure ( )

register a new function, exposing it to the remote composant of the swarm Signature register_closure(fname, closure, args_desc)

This closure expects four parameters, the closure can be a lambda.

  1. stringId (name of the function)
  2. a closure (the callback function)
  3. a table with the description of the arguments
  4. one with the self context

The table description of the arguments is an array of tuples, which hold the arg name as key and a value (float or int), only the type is check, so the value is not considered.You could define a variable as int=0 float=0.0 and use those variables for types description

var context = {.some_context = 42};
function registered_function(arg_int, arg_float) {
log("Context: ", self.some_context, "Arg int: ", arg_int, "Arg float: ", arg_float);
}
var args_description = {
.0 = {.arg_int=0}, // We just pass value so the type is registered
.1 = {.arg_float=0.0} // Same here
};
register_closure("registeredFunction", registered_function, args_description, context);
Here is the call graph for this function:
Here is the caller graph for this function:

◆ toFloat()

void BittyBuzzUserFunctions::toFloat ( )

Casts a type to float Signature float(arg1)

This closure expects one parameter

  1. the variable to cast returns the casted value of the variable Only works with int, if the type is not supported, nil is returned
    let i = 3;
    let f = float(3);
    function_that_takes_float(f);
Here is the caller graph for this function:

◆ toInt()

void BittyBuzzUserFunctions::toInt ( )

Casts a type to int Signature int(arg1)

This closure expects one parameter

  1. the variable to cast returns the casted value of the variable Only works with float, if the type is not supported, nil is returned
    let f = 3.14;
    let i = int(f);
    function_that_takes_int(i);
Here is the caller graph for this function:

Variable Documentation

◆ g_vmStepDelayMs

int16_t BittyBuzzUserFunctions::g_vmStepDelayMs = 0

The delay between each call of the step function in buzz.

log("VM refresh rate: ", 1000/VM_STEP_DELAY_MS);
BittyBuzzUserFunctions::log
void log()
Logs to the default output Signature log(args...)
Definition: BittyBuzzUserFunctions.cpp:67
BittyBuzzUserFunctions::delay
void delay()
wait for a certain delay Signature delay(arg1) Warning this function make the whole VM sleep which ca...
Definition: BittyBuzzUserFunctions.cpp:327