Pointer indexing [ ]
The Pointer object can be indexed to get/set the memory content of the pointed memory at the specified index, as a Value
The memory offset is calculated from the internal Pointer type with the provided integer index.
- The property Pointer.content is equivalent to indexing the pointer at index
0
- This property permits pointer dereferencing, the operation of accessing/manipulating the data value that a pointer points to.
- The type of the Value depends on the Pointer.type property.
Example
local c = require "c"
-- Create a C integer Value, that contains the number 10
local int = c.int(10)
-- Creates a Pointer to this Value
local int_ptr = c.Pointer(int)
-- Gets the content of the pointed memory to a new integer Value
local derefer = int_ptr.content
-- Changes the pointed memory content to 20 instead of 10
int_ptr.content = 20
-- int Value now contains 20 (defer Value is still 10)
print("int =", int)
print("derefer =", derefer)