lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Chances are the couple seconds it takes to type the localization won't be recovered in execution time unless it is a inner loop of a long running program for lots of users. And if you introduce a bug while doing it (even a silly one like a typo) you probably won't recover that time, EVER :)

Jorge

PS: ref https://what-if.xkcd.com/22/

On 08/08/2014 03:54 PM, Mason Mackaman wrote:
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