window framebuffer framework with lua!
  • Rust 70.7%
  • Lua 29.3%
Find a file
2025-09-19 21:06:40 -03:00
.vscode add image drawing support 2023-12-18 19:02:58 -03:00
lib rudimentary text rendering 2024-01-15 22:10:02 -03:00
res rudimentary text rendering 2024-01-15 22:10:02 -03:00
src add possibility to pass command line arguments to luafb 2025-09-19 21:06:40 -03:00
.gitignore add configurable environment 2023-11-02 16:02:20 -03:00
Cargo.lock rudimentary text rendering 2024-01-15 22:10:02 -03:00
Cargo.toml rudimentary text rendering 2024-01-15 22:10:02 -03:00
config.lua add configurable environment 2023-11-02 16:02:20 -03:00
COPYING add license 2023-11-02 16:11:56 -03:00
main.lua rudimentary text rendering 2024-01-15 22:10:02 -03:00
README.md typo 2023-11-06 21:32:06 -03:00

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.