Lua
- Files that export a singular
Class type, similar to ES modules default export, will use CamelCase.lua.
- Files that export a regular table, similar to ES modules named exports, will use
camelCase.lua.
- Files should not execute code within the root-level that will affect external runtime environment or behavior during the course of inclusion. The exception is made for files named
bt-init.lua.
Wrong
-- module.lua
local exports = {}
-- this chunk is okay because it only changes internal vars
local names = {}
for ... do
names[#names+1] =...
end
-- this chunk is NOT okay because it touches external vars
tfm.exec.chatMessage("test")
_G.print = nil
return exports
Correct
-- module.lua
local exports = {}
-- this chunk is also okay because it does not touch external vars in the course of inclusion
exports.btInit = function ()
tfm.exec.chatMessage("test")
_G.print = nil
end
return exports
-- bt-init.lua
local module = require("module")
-- allow touching external vars in the course of inclusion for bt-init.lua
module.btInit()
_G.hello = 0
Lua
Classtype, similar to ES modules default export, will useCamelCase.lua.camelCase.lua.bt-init.lua.Wrong
Correct