eigenbom / lua-example-typed-arrays

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Lua Typed Arrays

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.

Usage

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.

Installation

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.

About

License:MIT License


Languages

Language:C++ 86.9%Language:C 7.1%Language:Lua 5.7%Language:Batchfile 0.3%