Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extending standard library modules

Tags:

module

lua

Is it possible to extend (or even override) standard library modules. I'd like to be able to do something like

-- eggs.lua
table.spam = function(tab)
    return tab[1]
end

and then

-- ham.lua
require('eggs')
table.spam({2,7,1,3})
like image 424
Evpok Avatar asked May 21 '26 19:05

Evpok


1 Answers

Yes, it's possible, although the recommendation would be not to modify the standard library namespace, but use tablex instead as some libraries do.

like image 88
Paul Kulchenko Avatar answered May 23 '26 15:05

Paul Kulchenko