https://github.com/osch/lua-carray
Lua arrays for primitive numeric C data types
https://github.com/osch/lua-carray
lua lua-capi lua-library
Last synced: 4 months ago
JSON representation
Lua arrays for primitive numeric C data types
- Host: GitHub
- URL: https://github.com/osch/lua-carray
- Owner: osch
- License: mit
- Created: 2022-05-19T20:21:28.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-11-12T16:57:05.000Z (about 2 years ago)
- Last Synced: 2025-04-23T01:35:43.556Z (8 months ago)
- Topics: lua, lua-capi, lua-library
- Language: C
- Homepage:
- Size: 54.7 KB
- Stars: 8
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# lua-carray
[](LICENSE)
[](https://github.com/osch/lua-carray/actions/workflows/test.yml)
[](https://ci.appveyor.com/project/osch/lua-carray/branch/master)
[](https://luarocks.org/modules/osch/carray)
This [Lua] module provides an array data type and the implementation of the [Carray C API]
for handling arrays of primitive numeric C data types in Lua script code and also in native
C code for enhancing native Lua module interoperability and performance.
* [Documentation](./doc/README.md#lua-carray-documentation)
[Lua]: https://www.lua.org
[Carray C API]: https://github.com/lua-capis/lua-carray-capi
## First Example
```lua
local carray = require("carray")
local a = carray.new("int", 10)
for i = 1, a:len() do
assert(a:get(i) == 0)
end
for i = 1, a:len() do
a:set(i, 100 + i)
end
for i = 1, a:len() do
assert(a:get(i) == 100 + i)
end
local x, y, z = a:get(2, 4)
assert(x == 102)
assert(y == 103)
assert(z == 104)
local x, y, z = a:get(-3, -1)
assert(x == 108)
assert(y == 109)
assert(z == 110)
a:set(2, 202, 203, 204)
local x, y, z = a:get(2, 4)
assert(x == 202)
assert(y == 203)
assert(z == 204)
local c = carray.new("char"):append("1234567890")
assert(c:get(1) == string.byte("1"))
assert(c:tostring() == "1234567890")
assert(c:tostring(1,1) == "1")
assert(c:tostring(2,4) == "234")
c:set(4, "ab", string.byte("c"))
assert(c:tostring() == "123abc7890")
```