C.Array(type, dimension1, [dimension2], ...) 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).
This C Array definition is used to define the type and the dimensions to calculate the Array size in memory.
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 :
character | argument 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* |
dimension1,...
The dimensions of the array as sequential arguments. For a 5x2x3 array use 5, 2, 3
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]))