Array:constructor(type)constructor



The Array constructor creates a new C Array definition, that can be used later to create new C Array instances (see Calling C Array definition).

Parameters

type

This argument defines the type of data stored in the C Array. The type can be either :

  • A C definition object : Value, Struct, Union, Pointer or [] Array
  • A string with a single signature character for integral C types :
  • characterargument type
    "B"int (or bool for C++)
    "c"char
    "C"unsigned char
    "s"short / int16_t
    "S"unsigned short / uint16_t
    "i"int / int32_t
    "I"unsigned int / uint32_t
    "j"long / int32_t
    "J"unsigned long / uint32_t
    "l"long long / int64_t
    "L"unsigned long long / uint64_t
    "#"size_t
    "f"float
    "d"double
    "Z"char* / >const char*
    "W"wchar_t* / >const wchar_t*
    "p"void*

Return value

The constructor returns a new Array instance.

Example

local c = require 'c' -- Defines a C array with 3 rows of 4 chars local CharArray = c.Array("c", 3, 4) -- Creates a new CharArray with an initialization table local array = CharArray { { "a", "b", "c", '\0' }, { "d", "e", "f", '\0' }, { "g", "h", "i", '\0' } } -- prints the first row as a char Pointer print(c.Pointer(array[0]))