Value.constructor(ctype, [value]) constructor
The Value constructor creates a new Value instance, that represents an in-memory C variable of the provided type.
Parameters
ctype
A string
representing the C type for the new Value among any of the following strings :
ctype string |
C type |
"uchar" |
unsigned char |
"char" |
char |
"wchar_t" |
wchar_t |
"bool" |
boolean (C++)/int (C) |
"short" |
short |
"ushort" |
unsigned short |
"int" |
int |
"uint" |
unsigned int |
"long" |
long |
"long long" |
long long |
"ulong" |
unsigned long |
"ulonglong" |
unsigned long long |
"size_t" |
size_t |
"int16_t" |
int16_t |
"int32_t" |
int32_t |
"int64_t" |
int64_t |
"uint16_t" |
uint16_t |
"uint32_t" |
uint32_t |
"uint64_t" |
uint64_t |
"double" |
double |
"string" |
char * |
"wstring" |
wchar_t * |
"pointer" |
void * |
[value]
An optional Lua value of any type that will be used to initialize the created C Value.
- The C module contains functions to create C Values directly depending on the C type.
- When creating a C
string
or wide string
Value, you can initialize it only with another Value, a Lua string
or with a number
that indicates the string length.
Example
local c = require "c"
-- Create a Value that contains a C String (char *) initialized to "Hello World !"
local c_string = c.Value("string", "Hello World !")
-- Converts the Value to a Lua string and prints its
print(c_string)