addVariable

Declares a variable, and returns a Variable which can be used to easily reference the variable.

Notes: valueFunc may be null.

  1. Variable addVariable(CodeBuilder builder, dstring type, dstring name, CodeFunc valueFunc)
    addVariable
    (,
    dstring type
    ,
    dstring name
    ,)
  2. Variable addVariable(CodeBuilder builder, dstring name, CodeFunc valueFunc)

Parameters

builder CodeBuilder

The CodeBuilder to use.

type dstring

The name of the variable's type.

name dstring

The name of the variable.

valueFunc CodeFunc

The CodeFunc which generates the code to set the variable's intial value.

Return Value

Type: Variable

A Variable describing the variable declared by this function.

Examples

auto builder = new CodeBuilder();

// Declare the variable without setting it.
auto six = builder.addVariable("int", "six");
builder.data.should.equal("int six;\n"d);
six.should.equal(Variable("int", "six"));

builder = new CodeBuilder();


// Declare the variable, and set it's value.
CodeFunc func = (b){b.put("6");};
         six  = builder.addVariable("int", "six", func);

builder.data.should.equal("int six = 6;\n");
six.should.equal(Variable("int", "six", func));

Meta