Page 1 of 1

Correct way to extend Lua standard libraries

Posted: Fri Feb 03, 2023 4:29 pm
by Tabaqui
Hi all!

I'm working on a large Love2D project using a library i've written to handle OOP, and i've decided to divide it into multiple files (one for each class plus main.lua and conf.lua). Whenever i need to instantiate or extend a class i'm simply requiring it with require "ClassName" and it just works fine.

While the project grows i've noticed that i'm repeating a lot of code for simple tasks like finding items inside tables and stuff like that, so i thought i could write some simple table extension functions, but i would like to use them in pure lua syntax without the need to require some specific library each time (ex: if table.contains(t, element) then etc...).

My first thought was to declare such extension methods in my main.lua, but i don't like this approach very much because i'd like to keep the file as clean as possible.

What would be the best way to extend Lua libraries (possibly by declaring my custom functions in a separate file) and "patch" them once in my main.lua so i can use them from everywhere without worrying to require them?

Thank you in advance

Re: Correct way to extend Lua standard libraries

Posted: Fri Feb 03, 2023 4:45 pm
by darkfrei
Tabaqui wrote: Fri Feb 03, 2023 4:29 pm Hi all!

I'm working on a large Love2D project using a library i've written to handle OOP, and i've decided to divide it into multiple files (one for each class plus main.lua and conf.lua).
http://kiki.to/blog/2014/03/30/a-guide- ... a-modules/