[PR #1348] [MERGED] feat: Load cairo/lua like a lua-module #4134

Closed
opened 2026-05-22 23:57:48 +01:00 by JakeStanger · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/JakeStanger/ironbar/pull/1348
Author: @untoldwind
Created: 1/27/2026
Status: Merged
Merged: 1/29/2026
Merged by: @JakeStanger

Base: masterHead: improve_load


📝 Commits (9)

📊 Changes

5 files changed (+267 additions, -54 deletions)

View changed files

docs/examples/custom/Cpu-Cores-Graph.md (+164 -0)
📝 docs/modules/Cairo.md (+39 -11)
📝 lua/draw.lua (+2 -2)
📝 src/modules/cairo.rs (+62 -39)
📝 src/modules/mod.rs (+0 -2)

📄 Description

This is more a suggestion/possible solution for the somewhat hacky script.replace("function draw" ....
Instead of having a draw function in the global scope the script is expected to return the drawing function itself.

This allows a greater flexibility in writing scripts without "polluting" the global scope:

  • Just an anonymous function:
    return function(cr, width, height)
       -- draw the thing
    end
    
  • Some local function:
    local function draw_the_thing(cr, width, height)
       -- do it
    end
    
    return draw_the_thing
    
  • A callable table:
    local thingy = {}
    
    function thingy:draw_it(width, height)
       -- do it on self.cr
    end
    
    setmetatable(thingy, {
     __call = function(o, cr, area_width, area_height)
        o.cr = cr
        return o:draw_it(area_width, area_height)
     end,
    })
    return thingy
    

As a bonus it is also no longer necessary to patch the error message to get the correct file reference.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/JakeStanger/ironbar/pull/1348 **Author:** [@untoldwind](https://github.com/untoldwind) **Created:** 1/27/2026 **Status:** ✅ Merged **Merged:** 1/29/2026 **Merged by:** [@JakeStanger](https://github.com/JakeStanger) **Base:** `master` ← **Head:** `improve_load` --- ### 📝 Commits (9) - [`03841a4`](https://github.com/JakeStanger/ironbar/commit/03841a4a8c28f508ec44d0bf9a7258cd3f25d1e9) exp: Load cairo/lua like a lua-module - [`f454b92`](https://github.com/JakeStanger/ironbar/commit/f454b924284eb754698bf8ed74edb84781b1a7d8) Cleanup + adjust documentation - [`1c1e301`](https://github.com/JakeStanger/ironbar/commit/1c1e301cd76aa2d5577860de7f3ddfc35781e67a) Fix typos - [`c488c47`](https://github.com/JakeStanger/ironbar/commit/c488c473a57d118851d2788ef2c885851b7de376) Add a custom cairo example - [`bac5bed`](https://github.com/JakeStanger/ironbar/commit/bac5bed1b3392516c8996634d4cac9cb711f8992) Update src/modules/cairo.rs - [`98ea5ce`](https://github.com/JakeStanger/ironbar/commit/98ea5ce1ace98e50bef2c3c15afe271f76eefff0) Fix imports - [`aeaf5c7`](https://github.com/JakeStanger/ironbar/commit/aeaf5c74a2807a6b449f72c36b9796e020c9d285) Drop id from widget context - [`4a4cb12`](https://github.com/JakeStanger/ironbar/commit/4a4cb126bbc90be2c1f953ff6ca0c06bdc0b8ce6) Drop mutex - [`ddad186`](https://github.com/JakeStanger/ironbar/commit/ddad1862a55e5a4a730e316b4facbe2b3ce43d37) Fix inline image in doc ### 📊 Changes **5 files changed** (+267 additions, -54 deletions) <details> <summary>View changed files</summary> ➕ `docs/examples/custom/Cpu-Cores-Graph.md` (+164 -0) 📝 `docs/modules/Cairo.md` (+39 -11) 📝 `lua/draw.lua` (+2 -2) 📝 `src/modules/cairo.rs` (+62 -39) 📝 `src/modules/mod.rs` (+0 -2) </details> ### 📄 Description This is more a suggestion/possible solution for the somewhat hacky `script.replace("function draw" ...`. Instead of having a draw function in the global scope the script is expected to return the drawing function itself. This allows a greater flexibility in writing scripts without "polluting" the global scope: * Just an anonymous function: ```lua return function(cr, width, height) -- draw the thing end ``` * Some local function: ```lua local function draw_the_thing(cr, width, height) -- do it end return draw_the_thing ``` * A callable table: ```lua local thingy = {} function thingy:draw_it(width, height) -- do it on self.cr end setmetatable(thingy, { __call = function(o, cr, area_width, area_height) o.cr = cr return o:draw_it(area_width, area_height) end, }) return thingy ``` As a bonus it is also no longer necessary to patch the error message to get the correct file reference. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
JakeStanger 2026-05-22 23:57:48 +01:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
JakeStanger/ironbar#4134
No description provided.