- Rust 70.7%
- Lua 29.3%
| .vscode | ||
| lib | ||
| res | ||
| src | ||
| .gitignore | ||
| Cargo.lock | ||
| Cargo.toml | ||
| config.lua | ||
| COPYING | ||
| main.lua | ||
| README.md | ||
luafb
A window framebuffer framework heavily inspired by LÖVE, that lets you draw pixels using Lua.
How To?
luafb runs from the current working directory's main.lua file or from the file passed to luafb.
luafb is based on the declaration of two functions: fb.init() and fb.update().
fb.init() runs only once right after luafb is configured and initialized.
fb.update() runs at every frame.
function fb.init()
print("Hello luafb!")
end
delta = 1
function fb.update()
print("This is frame "..delta)
delta = delta + 1
end
Configuration
To modify luafb's environment you need to create a config.lua file in the current working directory.
This file needs to declare the fb.configure(cfg) function.
cfg is a table with luafb's environment variables. Any modification to this parameter will also change luafb's environment.
---@param cfg fb.config
function fb.configure(cfg)
cfg.title = "luafb example!"
cfg.width = 600
cfg.height = 600
end
You may use the example config.lua as reference.
It is also possible to access luafb's environment variables in the middle of the program runtime with the fb.config table.
Drawing
In order to draw something at the screen we need to directly modify the screen pixels through the fb.buffer array. Each array item stores the hexadecimal color value of that pixel.
function fb.init()
-- writes a white pixel at the center of a 300x300 window
fb.buffer[45150] = 0xffffff
end
delta = 1
function fb.update()
fb.buffer[delta] = 0xffffff
delta = delta + 1
end
You can find other examples on the example main.lua file.
Acknowledgements
luafb is based on rust_minifb. Really, minifb is doing all the hard work here. I just integrated it with Lua.
License
luafb is licensed under LGPL 3.0 or later. You may freely copy, distribute and modify it. Any modifications must also be distributed under LGPL or GPL. Use from interfaces (e.g. using and distributing luafb's binary without modifications alongside your work) is alloed. You can read the COPYING file for more information.