addFuncDeclaration

Creates a function using the given data.

  1. CodeBuilder addFuncDeclaration(CodeBuilder builder, dstring returnType, dstring name, Variable[] params, CodeFunc body_)
  2. CodeBuilder addFuncDeclaration(CodeBuilder builder, dstring name, Variable[] params, CodeFunc body_)

Parameters

builder CodeBuilder

The CodeBuilder to use.

returnType dstring

The name of the type that the function returns.

name dstring

The name of the function.

params Variable[]

The function's parameters.

body_ CodeFunc

The CodeFunc which generates the code for the function's body.

Return Value

builder

Examples

auto builder = new CodeBuilder();

builder.addFuncDeclaration("int", "sum", [Variable("int", "a"), Variable("int", "b")], (b){b.addReturn("a + b"d);});

builder.data.should.equal("int sum(int a, int b)\n{\n\treturn a + b;\n}\n");

Meta