Usage

To use Chopper, a template of type Chop_Template_typ will need to be declared. Optionally a function block of type Chopper can be used instead of functions.

Initialization

Declare a variable template of type Chop_Template_typ, and compile source. If using FUB interface declare an additional variable Chop of type Chopper. Before using Chop, set pSource, pTemplate, pDest, and destSize. template is not required to be compiled before using Chop.

FUB Interface

variable.text:= 'Chopper FUB';
source:= 'This is a {{variable.text}} example!';

Chop.pSource:= 		ADR(source);
Chop.pTemplate:= 	ADR(template);
Chop.pDest:= 		ADR(destination);
Chop.destSize:= 	SIZEOF(destination);

Fn Interface

variable.text:= 'Chopper FUB';
source:= 'This is a {{variable.text}} example!';

ChopCompile(ADR(template), ADR(source));

Operation

Each time Chop is called it will compile pTemplate if not already compiled or recompile is true, and Each time Chop or ChopRender is called, pTemplate will render to pDest. Chop / ChopRender will render in a single call and can be called multiple times per a cycle. A single fub can be used to compile/render multiple templates. For more information see ChopCompile and ChopRender functions.

FUB Interface

Chop();
// destination = 'This is a Chopper Fub example!'

FN Interface

ChopRender(ADR(destination), ADR(template), SIZEOF(destination), ADR(length));
// destination = 'This is a Chopper example!'
// length = 26

Formatting

Variables in source should be surrounded by double curly braces “{{”, “}}”, and should be specified in format TaskName:VarName for local variables and VarName for global variables. Only variables declared in .var files can be used by name, for variables not declare in a .var file see Special_Variables.

"This is a global variable {{gState}} and this is a local variable {{machine:localState}}"

Variables can be manually formatted using by adding a “,” and providing additional formatting. This conforms to printf format style, see cplusplus.com/reference/cstdio/printf. Note: If manually formatting is used, variable type must support the format flag being used or undefined behavior will occur. Note: Width of ‘*’ is not supported and will cause undefined behavior.

// Assume gInt: -1000, gUint: 1000, gReal: 1.12345, gString: "Hello World"

"int {{gInt, %d}}, uint {{gUint, %u}}, real {{gReal, %f}}, string {{gString, %s}}"
// int -1000, uint 1000, real 1.12345, string Hello World

"int {{gInt, %05d}}, uint {{gUint, %+u}}, real {{gReal, %e}}, string {{gString, %.5s}}"
// int -01000, uint +1000, real 1.12345e+0, string Hello

Special variables

Variables not declared in a .var file can still be used in Chopper sources by using a tag (temporary name) and ChopReplace to replace with variable address. Note: Chopper will reference variable by address and is subject to scope. If variable goes outside scope it may loose its value. For variables declared on the stack, ChopReplace may need to be called multiple times, if the location of the variable changes.

Made by Loupe