Add a New Built-in Function
All built-in functions are children of NodeFunctionBuiltin class and are generated by gen_builtin.pl Perl script. To define a new built-in function you have to do:
- Write a new unit test to ../samples/tests.txt.
- Write the function declaration in format $funcdecl = 'funcName(arguments) : return'.
- Define the code for including files.
- Define the body of the built-in function.
- Call genBFClass('built-in name', 'class name', number of parameters, code, includes) function.
- Run make to regenerate the classes and rebuild the related code.
- Add the newly generated files classname.h and classname.cpp to Qt Creator project.
- Check the changes for memory leaks using valgrind ./graphal_cli --unit-tests ../samples/tests.txt.
- Commit/send me the code.
$funcdecl = 'getAdjacencyMatrix(graph) : array';
$include = <<END_OF_CODE;
#include "valuegraph.h"
END_OF_CODE
$code = <<END_OF_CODE;
ValueGraph* g = NULL;
if((g = par[0]->toValueGraph()) != NULL)
return g->getAdjacencyMatrix();
else
{
WARN_P(_("Bad parameters type: $funcdecl"));
return VALUENULL;
}
END_OF_CODE
genBFClass('getAdjacencyMatrix', 'NodeBuiltinGetAdjacencyMatrix', 1, $code, $include);