Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Expand
titleExample of a global function

If you were to create a simple APP.lua file and add a function called APPadd like below:

Code Block
languagelua
function APPadd(a,b)
   local sum = a + b
   return sum
end

In main you can then call APPadd and get the sum:

Image RemovedImage Added
Expand
titleExample of a local function

In the same APP.lua file, now alter the function to be local.

Code Block
languagelua
local function APPadd(a,b)
   local sum = a + b
   return sum
end

return APPadd 

Note: the The function is now local, but we have also returned the APPadd function to create a closure - the values of a and b will be persisted even after the outer function has finished executing.

Now in In main, you can capture the closure returned function in your require statement , and use it as if it were APPadd.

Image Removed

:

Image Added