[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Local Variables
- From: Mason Mackaman <masondeanm@...>
- Date: Fri, 8 Aug 2014 13:54:26 -0500
So to make a program run as fast as possible should you localize everything in _ENV you’re going to use in your program?
On Aug 7, 2014, at 4:44 PM, Elias Barrionovo <elias.tandel@gmail.com> wrote:
> 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
>