This repository demonstrates how to implement resizable typed arrays for Lua. This code exists for testing and education purposes only and shouldn't be used in production. It is a light wrapper around stb_ds.h with some additional Lua for type annotations, etc.
local carray = require("carray")
-- Create a new array of unsigned 8-bit integers with size 4
local arr = carray.new_u8(4)
assert(#arr == 4)
print(type(arr)) --> "carray<u8>: 0x013964632950"
arr[1] = 4 -- assign the first element
arr[10] = 42 -- assign the tenth element and automatically resize
See spec/carray_spec.lua for more examples.
You can use luarocks build system, e.g., download this repo and then luarocks make
.
Alternatively manually compile carray.c and stb_ds.h. Optionally include types.lua for type annotations.