I just managed to get running the Lua Module system I described toward the end of my presentation. link.
To sum up the reason for this post, i point you to the google search results of “Lua modules” where you will see that the second page in the list is titled “lua’s module function critiqued”. If you have gone down this route before you know what I am talking about. It is NOT clear cut and dry how to implement modules in lua in the lua book and in a lot of the tutorials online.
The process is not like an import or #include, since “require” searches in the package.loaded table for anything that you have defined in module()… and anything defined WITH module() CANNOT call ANY globals (like print or another require) once this module function is called. (if you go to that critique web page you will see how to overcome this)
Confused? Well it seems like Lua and the Lua team have opportunity to improve the system and straighten things out. Just know that when you call module, the environment is wiped nearly entirely, meaning that those nifty functions like print and such will no longer be with you.
Why don’t I fix it? Because i can see why they do it the way they do, to make each module lightweight and somewhat private… but… there has to be a better way. I really think this is important ALSO because this is the essence of sharing code, and if you cant get the system of sharing code right… how will anyone be able to use it (espcially with the MIT license just begging for free sharing of code).