lua-users home
lua-l archive

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


{snip}
Because the reason to use local is for when you don't want anyone else
to be able to see the variable:
that is the whole point of local; and to remove that... why are you
using local in the first place??????

In this way, its like a global 'static' in a C file.


I do like locals but local to a do-end blocks or functions not necessary files. So here is a simple use case.

Let's say I define 1 function and put it in a file called function.lua, it looks something like this:
function silly1() print "reallly long string that greets user" end

and define 1 local variable
local x = 10
and put it in another file called local.lua.

I could then write code in another file that would patch the two together something like this:
 function sillyCode()
include("functions.lua)
silly1()
local y =2
include("locals.lua")
print(x + y)
end

the include file is just a way to store code somewhere else. I have download code from luaforge that had 3K lines in one file, this is weird. Other languages have this simple-PHP like mechanism, it's not about encapsulation it's just about typing. This example was short but why could someone not define 100 local variables and then when the include is called from within a function, those locals become local to that function as if they were typed inside it.