Pipi Caca
Pipi Caca

Reputation: 133

Is this a correct way of making modules in Lua?

On the official lua wiki it states that this is how you make a module

local mymodule = {}

function mymodule.foo()
    print("Hello World!")
end

return mymodule

But couldn't you just do

return { foo=function() print("Hello World!") end }

I am familiar with Lua but not an expert. So is there anything wrong with what I've written?

Upvotes: 2

Views: 61

Answers (1)

lhf
lhf

Reputation: 72312

Your way is perfectly fine.

The example in the wiki is better suited for larger modules, with several functions and possibly private data.

Upvotes: 2

Related Questions