https://github.com/semyon422/luajit-byte
Binary data module (moved https://github.com/semyon422/aqua)
https://github.com/semyon422/luajit-byte
binary buffer ffi lua luajit
Last synced: about 1 month ago
JSON representation
Binary data module (moved https://github.com/semyon422/aqua)
- Host: GitHub
- URL: https://github.com/semyon422/luajit-byte
- Owner: semyon422
- License: gpl-3.0
- Created: 2020-02-01T12:34:45.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2022-04-26T11:08:15.000Z (almost 4 years ago)
- Last Synced: 2025-02-02T06:14:51.250Z (about 1 year ago)
- Topics: binary, buffer, ffi, lua, luajit
- Language: Lua
- Homepage:
- Size: 46.9 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# luajit-byte
Binary data module
```lua
local byte = require("byte")
-- Byte buffer example, check source code for more info
local b = byte.buffer(2e9) -- allocate 2GB
b:resize(4e9) -- reallocate to 4GB
ffi.fill(b.pointer, b.size, 0) -- fill with zeros
print(b:fill("Hello, "):fill("World!"):seek(0):string(13)) -- Hello, World!
b:free() -- optional, the garbage collector can handle this correctly
-- nan boxing example
local b = byte.buffer(8)
b:double_be(0 / 0):seek(4):fill("love")
local nanbox = b:seek(0):double_be()
assert(nanbox ~= nanbox) -- nan
assert(b:seek(0):double_be(nanbox):seek(4):string(4) == "love")
```