lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Python needs a main function because in that language toplevel variables are global. If you don't create a main function you will pollute the global namespace. This is not a problem in Lua. When you load a module, it implicitly puts everything inside an invisible main function. Local variables declared at the toplevel are local to the module.

What I do on my projects: if the file is a standalone script I usually don't bother with creating a main function. I the module is intended to be used via require, I put the code inside an exported function. I don't want to have side effects when I call require("mymodule").