What is the purpose of this word? I have seen programming with it and without it what purpose does it serve??
also COULD I get a list of ALL THE FUNCTIONS?
What is the purpose of this word? I have seen programming with it and without it what purpose does it serve??
also COULD I get a list of ALL THE FUNCTIONS?
All of the functions we provide is listed here: http://docs.coronalabs.com/api/index.html
When you see “local” at the beginning of a function or variable, it’s telling you that function or variable is visible to the block it’s defined in. If you leave the local off, the function or variable becomes global. However if you see something like:
function object.functionName
or
function object:functionName
Then those functions are part of that object and have the same scope as the table they are added to.
Judging from your forum posts you are very determined to make your game. So my friendly advice is to put the game to the side for few days and learn Lua programming properly and life will become a lot easier.
Roughly, these are a matter of how much the rest of the program is aware of (and affected by) the variable in question. For small test programs or example code, non-local variables are usually fine and maybe easier to follow.
The big problem is that these “globals” all end up in the _G table. On the one hand, this might be bad just because you end up with a lot of stuff that was maybe only needed once or twice and is now junk. More importantly, however, is that your variables will be competing for the same spots! Consider the following:
name = "Max281" ... a lot more code name = "StarCrunch" -- Previous `name' is overwritten!
This is not what you want, if you were still using the first value of name. :) Once your programs start to get bigger, it’s really not worth the hassle trying to keep track of every variable in your head. By themselves, locals won’t completely solve this (you’ll also want to be using Lua’s block structures like if, while, functions, etc.), but it’s a key piece of the puzzle.
All else being equal, it should also make your code slightly faster (though you probably wouldn’t notice unless you were doing something really intense), and drives some slightly more advanced Lua features.
For function listings, try dropping this somewhere and see if it helps:
local function Name (prefix, name) if prefix == "" then return name else return prefix .. "." .. name end end local function DumpFunctions (t, visited, prefix) visited[t] = true for k, v in pairs(t) do local vtype = type(v) if vtype == "function" then print(Name(prefix, k)) elseif vtype == "table" then if not visited[v] and v ~= package.loaded then DumpFunctions(v, visited, Name(prefix, k)) end end end end DumpFunctions(\_G, {}, "")
Quick and dirty, but seems to work… sort of a stripped-down version of what I normally use. Shows a few things, including locals, I guess. I filtered package.loaded since it’s mostly redundant, but tinker as you wish.
EDIT:
Err, yes, the API’s page was probably what you meant by functions.
Oh well, maybe the example’s handy too.
All of the functions we provide is listed here: http://docs.coronalabs.com/api/index.html
When you see “local” at the beginning of a function or variable, it’s telling you that function or variable is visible to the block it’s defined in. If you leave the local off, the function or variable becomes global. However if you see something like:
function object.functionName
or
function object:functionName
Then those functions are part of that object and have the same scope as the table they are added to.
Judging from your forum posts you are very determined to make your game. So my friendly advice is to put the game to the side for few days and learn Lua programming properly and life will become a lot easier.
Roughly, these are a matter of how much the rest of the program is aware of (and affected by) the variable in question. For small test programs or example code, non-local variables are usually fine and maybe easier to follow.
The big problem is that these “globals” all end up in the _G table. On the one hand, this might be bad just because you end up with a lot of stuff that was maybe only needed once or twice and is now junk. More importantly, however, is that your variables will be competing for the same spots! Consider the following:
name = "Max281" ... a lot more code name = "StarCrunch" -- Previous `name' is overwritten!
This is not what you want, if you were still using the first value of name. :) Once your programs start to get bigger, it’s really not worth the hassle trying to keep track of every variable in your head. By themselves, locals won’t completely solve this (you’ll also want to be using Lua’s block structures like if, while, functions, etc.), but it’s a key piece of the puzzle.
All else being equal, it should also make your code slightly faster (though you probably wouldn’t notice unless you were doing something really intense), and drives some slightly more advanced Lua features.
For function listings, try dropping this somewhere and see if it helps:
local function Name (prefix, name) if prefix == "" then return name else return prefix .. "." .. name end end local function DumpFunctions (t, visited, prefix) visited[t] = true for k, v in pairs(t) do local vtype = type(v) if vtype == "function" then print(Name(prefix, k)) elseif vtype == "table" then if not visited[v] and v ~= package.loaded then DumpFunctions(v, visited, Name(prefix, k)) end end end end DumpFunctions(\_G, {}, "")
Quick and dirty, but seems to work… sort of a stripped-down version of what I normally use. Shows a few things, including locals, I guess. I filtered package.loaded since it’s mostly redundant, but tinker as you wish.
EDIT:
Err, yes, the API’s page was probably what you meant by functions.
Oh well, maybe the example’s handy too.