# Patching new methods on resources

**URL:** <https://community.info-beamer.com/t/patching-new-methods-on-resources/1400>\
**Category:** Help\
**Created:** [May 23, 2026, 6:38pm UTC](https://community.info-beamer.com/t/patching-new-methods-on-resources/1400 "2026-05-23T18:38:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![lousimons](https://community.info-beamer.com/user_avatar/community.info-beamer.com/lousimons/32/183_2.png) [@lousimons](https://community.info-beamer.com/u/lousimons)\
**Post date:** [May 23, 2026, 6:38pm UTC](https://community.info-beamer.com/t/patching-new-methods-on-resources/1400/1 "2026-05-23T18:38:13Z")

</div>

I found that I was often writing code like the following to draw images based on x, y, width and height information (since that’s what Inkscape shows when you click an element):

```lua
ticker_bg:draw(100, 964, 100 + 1820, 116)

```

The “100 +” was the reminder to me that I’ve slid this image over by 100 px and let the width be visible as 1820 px.

To avoid that, I wrote a helper:

```lua
draw_image_xywh(ticker_bg, 100, 964, 1820, 116)

```

However, that stuck out as looking different than the other draw method calls. So, my idea was to patch the draw\_xywh method onto the regular image resource.

```lua
local original_load_image = resource.load_image

resource.load_image = function(opt)
    local image = original_load_image(opt)

    return {
        draw = function(self, x1, y1, x2, y2, alpha)
            image:draw(x1, y1, x2, y2, alpha)
        end,

        draw_xywh = function(self, x, y, w, h, alpha)
            image:draw(x, y, x + w, y + h, alpha)
        end
    }
end

```

That lets me write `ticker_bg:draw_xywh(100, 964, 1820, 116)`.

However, my concern is that this shenanigans might be adding a significantly slower wrapper, since it feels like load\_image and drawing would be highly optimized to avoid the Lua interpreter. So, is this a really bad idea? Something silly but harmless? Thanks!

---

<div class="post-metadata">

**Author:** ![infobeamer-fw](https://community.info-beamer.com/user_avatar/community.info-beamer.com/infobeamer-fw/32/3_2.png) [@infobeamer-fw](https://community.info-beamer.com/u/infobeamer-fw)\
**Post date:** [May 24, 2026, 3:03pm UTC](https://community.info-beamer.com/t/patching-new-methods-on-resources/1400/2 "2026-05-24T15:03:00Z")

</div>

> [@lousimons](#):
>
> However, my concern is that this shenanigans might be adding a significantly slower wrapper, since it feels like load\_image and drawing would be highly optimized to avoid the Lua interpreter. So, is this a really bad idea? Something silly but harmless? Thanks!

Totally fine. I doubt you can notice any difference at all. The `load_image` and `draw` is still identical after all and the interpreter doesn’t really care what that are named.
