Module lua-refarr
A refarr Lua userdata data-type
A userdata managed LUA_TLIGHTUSERDATA according to memory spec.
Usage:
-- Example for signed integers 1, 2, 4 and 8 bytes in size
-- Change value below to use the intended type (int8_t .. int64_t)
ez = 4 --> 4 bytes integer is a int32_t
blob, sz = ctables.balloc({16}, ez, {0x01, 0x02, 0x03, 0x04});
ctables.braw(blob, sz, ez) --> Show tainted bob
-- 0000: 00000001 00000002 00000003 00000004 00000001 00000002 00000003 00000004
-- 001c: 00000001 00000002 00000003 00000004 00000001 00000002 00000003 00000004
ba = refarr.new(blob, 16, ez, true, false, true) --> memspec of int32_t
len = #ba
print("Read typed array of length: " .. len) --> 16
for i=1, len do
local v = ba[i]
print("Get index[" .. i .."] : " .. v )
end
-- Get index[1] : 1
-- Get index[2] : 2
-- :
-- :
-- Get index[13] : 1
-- Get index[14] : 2
-- Get index[15] : 3
-- Get index[16] : 4
ba[2] = 0x2FF
ba[4] = 0x4FF
ba[10] = 0xAFF
ctables.braw(blob, sz, ez) --> Show blob modified by `refarr` index
-- 0000: 00000001 000002ff 00000003 000004ff 00000001 00000002 00000003 00000004
-- 001c: 00000001 00000aff 00000003 00000004 00000001 00000002 00000003 00000004
-- See @ markers: --^ --^
ba = nil --> Tell Lua VM it's OK to GC
ctables.bfree(blob) --> Free "inside" last (principle)
Info:
- Copyright: © Michael Ambrus 2024
- License: MIT
- Author: Michael Ambrus michael@ambrus.se
Functions
| version () | Return version strings |
| set (Object, Index, Value) | __newindex |
| get (Object, Index) | __index |
| size (Object) | __len |
| string (Object) | __tostring |
| new (Address, Length, Size, IsNum, IsFp, IsSig) | Create a refarr object |
Functions
- version ()
-
Return version strings
Returns:
- String Module version
- String Git SHA1 for this module when built
- String For which Lua-version
Usage:
refarr = require("refarr") refarr.version() --> 1.0.0-1 5bef04a 5.3
- set (Object, Index, Value)
-
__newindex
Parameters:
- Object
refarr
(
selfor of same-type) to modify value - Index integer for set-value
- Value boolean New value
- Object
refarr
(
- get (Object, Index)
-
__index
Parameters:
- Object
refarr
(
selfor of same-type) to apply index-query - Index integer for get-value
Returns:
-
boolean
Value
- Object
refarr
(
- size (Object)
-
__len
Parameters:
- Object
refarr
(
selfor of same-type) to get the "length" from
Returns:
-
integer
Returns the number of elements in array
- Object
refarr
(
- string (Object)
-
__tostring
Parameters:
- Object
refarr
(
selfor of same-type) to "stringize"
Returns:
-
string
of something... (size-info as string)
- Object
refarr
(
- new (Address, Length, Size, IsNum, IsFp, IsSig)
-
Create a
refarrobject Options given with colon are optional and the value is the default.Parameters:
- Address userdata (void*) of LUA_TLIGHTUSERDATA base-pointer
- Length integer of the array
- Size integer of one element in bytes: 4
- IsNum boolean Memory is a numerical of ant kind, or a blob: true
- IsFp boolean If numerical, is it a floating-point: false
- IsSig boolean If integer, is it signed: true
Returns:
-
refarr