Code: Select all
local b
function lol()
b = somethingRather
end
Code: Select all
local b
function lol()
b = somethingRather
end
Depends on what you're doing, here's a small example:pancakepalace wrote:I don't think there is, but I don't see why this would be necessary.
Code: Select all
local x = 0
local Add = function(number)
x = x + number
return x
end
Code: Select all
function fun (arg)
local arg = arg or default_value
do_stuff
end
Code: Select all
function fun (arg1)
local arg
if arg1 then
arg = arg1
else
arg = default_value
end
arg1 = nil
do_stuff
end
Code: Select all
function fun (arg)
arg = arg or default_value
do_stuff
end
Code: Select all
function fun (arg)
if arg then
arg = arg
else
arg = default_value
end
do_stuff
end
Code: Select all
function fun (arg)
if not arg then
arg = default_value
end
do_stuff
end
pancakepalace wrote:I'm not too sure what's the problem with your example.
If you're talking to me, then first of all I'm not complaining. i was just wondering if there was syntax for declaring something "file-local". Turns out there isn't, which isn't a problembartbes wrote:Yeah, you're asking us how to affect a 'file-local' local and then complaining it does? You lost me, anyway.
That post confused me. First you claim there is no such consept as a file, then you refer to "the file scope". If you declare something as local in one .lua file, can you still reach it from another? I'm still getting used to script languages so I get confused about stuff like thisbartbes wrote:There is no such concept as a file, every file is just another block of code. So in the end what matters is where you define it/first use it.
As a language with lexical scoping it means it basically searches from the inside out, so where you last defined it as local, is what it will use. The solution to your 'problem' is indeed, to define the variable as local at the scope you want it, the file scope, in your case.
No, if it's local to a file, it can't be reached by other files.T-Bone wrote:That post confused me. First you claim there is no such consept as a file, then you refer to "the file scope". If you declare something as local in one .lua file, can you still reach it from another? I'm still getting used to script languages so I get confused about stuff like thisbartbes wrote:There is no such concept as a file, every file is just another block of code. So in the end what matters is where you define it/first use it.
As a language with lexical scoping it means it basically searches from the inside out, so where you last defined it as local, is what it will use. The solution to your 'problem' is indeed, to define the variable as local at the scope you want it, the file scope, in your case.
Users browsing this forum: No registered users and 3 guests