Lupus590

pass by value VS pass by reference.lua

Apr 30th, 2021 (edited)
1,400
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.41 KB | None | 0 0
  1. local function passByValue(value)
  2.     value = "no"
  3. end
  4.  
  5. local example = "hello"
  6. passByValue(example)
  7. print(example) -- what get's printed?
  8.  
  9. local function passByReference(reference)
  10.     reference[1]= "no"
  11. end
  12.  
  13. local example2 = {"hello"}
  14. passByReference(example2)
  15. print(example2[1]) -- what get's printed?
  16.  
  17. -- In lua tables, functions, and coroutines are passed by reference. This is unlike every other type in lua.
Advertisement
Add Comment
Please, Sign In to add comment