fork download
  1. -- Normal way to define a function
  2. function funcOne(foo)
  3. print(foo)
  4. end
  5.  
  6. -- Another way
  7. funcTwo = function(bar) print(type(bar)) end
  8.  
  9. -- Let's see them both in action
  10. funcOne('hello')
  11. funcTwo('hello')
  12.  
  13. -- Pass function as paramater.
  14. -- Note the lack of the () after funcOne.
  15. -- We want to pass the function, not call it.
  16. funcTwo(funcOne)
  17.  
  18. -- Hmm, that worked. Lets try something odd
  19. myTable = {}
  20. myTable[funcTwo] = "Does this work?"
  21. print(myTable[funcTwo])
Success #stdin #stdout 0s 14120KB
stdin
Standard input is empty
stdout
hello
string
function
Does this work?