TsT Module definition

How to define a LÖVE module ?

Exactly like a LUA module.

How to define a LUA module ?

There is different way to do. In lua 5.1, a module() function exists : Please do not use it. It will be deprecated in next version. See this discuss for detail TODO:link


A "private"(?) module (not affecting the global environment)

in file "mymod.lua" :

local M = {}

local function blah()

end

local function bar()

end

M.foo = blah
M.bar = bar

return M

sample of use in main file :

local mymod = require("mymod")
mymod.blah()
mymod.bar()


or with global module

mymod = require("mymod")
mymod.blah()
mymod.bar()


variant 2 in file "mymod.lua" :

local M = {}

local function blah()

end

local function bar()

end

M.foo = blah
M.bar = bar

mymod = M -- create the global "mymod" variable

sample of use in main file :

require("mymod")
mymod.blah()
mymod.bar()