[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Local Variables
- From: Elias Barrionovo <elias.tandel@...>
- Date: Thu, 7 Aug 2014 18:44:44 -0300
On Thu, Aug 7, 2014 at 6:40 PM, Mason Mackaman <masondeanm@aol.com> wrote:
> I see, when I change the variables from the libraries (or should I say modules, I really don’t know when to use what) I’ve written to local, they don’t carry over. So I guess that’s the only time you use globals then?
A module can return a value, just like a function (in fact, a module
*is* a function), so it's idiomatic for the value to return a table
with what it wants to export. A silly example:
-- file double.lua
local double(x) return x*2 end -- local, only this module can see this
return {double = double} -- returning a table that exports the double function
-- file main.lua
local double = require 'double'
print(double.double(4))
--
NI!
() - www.asciiribbon.org
/\ - ascii ribbon campaign against html e-mail and proprietary attachments