LIL is a Language Make games, nicely

@array

A dynamic array which automatically grows or shrinks as needed

Example code

//use built in array syntax
var myArr: "apples", "oranges", "pears";
for myArr {
	print @value;
}

//or do it manually
var.@array(i64) otherArr: [1, 2, 3, 4];
otherArr.add(5);

Aliases

  • sbuf

    sbuf

    The static buffer of values.

    //this will be expanded
    var.sbuf foo: [];
    //into this
    var.[#paste SMALL_BUFFER_SIZE x @subtype] foo: [];

Member variables

  • buffer

    Type: var.[2 x @subtype]|ptr(@subtype)

    The space for some values or a pointer to the first value

    if @self.buffer => ptr(@subtype) {
    	return @self.buffer + index;
    }
  • size

    Type: var.i64

    How many values are currently in the array

    if index < @self.size {
    	//etc
    }
  • capacity

    Type: var.i64

    How much space is allocated for values

    if @self.capacity > @self.size {
    	//etc
    }

Member functions

  • at

    Type: fn => ptr(@subtype)|null

    Returns a pointer to the value at the given index or null if not found

    Arguments
    • var.i64 index:

      The offset into the array.

    print myArr.at(0);
  • value

    Type: fn => @subtype

    Returns the value at the given index

    Warning! Might read out of bounds.

    Arguments
    • var.i64 index:

      The offset into the array.

    var lastValue: myArr.value(myArr.size - 1);
  • add

    Type: fn

    Appends a value at the end of the array, resizing the array if necessary

    Arguments
    • var.@subtype value:

      The value to be inserted.

    var.@array(i64) myArray: 1, 2, 3;
    myArray.add(123);
    myArray.add(888);
  • reserve

    Type: fn

    Use this method when you want to increase capacity for more elements ahead of time

    Arguments
    • var.i64 newCapacity:

      How many elements will fit.

    myArr.reserve(1024);
  • initialize

    Type: fn => ptr(@subtype)

    The runtime calls this method to set up the array before copying elements into it

    Arguments
    • var.i64 newCapacity:

      how many elements will fit