#&

1 messages · Page 1 of 1 (latest)

jade ferry
#

is there a way to do this reference trick

local function func(p)
  p.value += 1
end

local var = {value = 0}
func(var)
print(var.value)
hoary path
#

however newer languages don't support ByRef parameters

#

you can just return the value of p, and set the var to that value

#
local function func(p)
  p.value += 1
  return p
end

local var = {value = 0}
var = func(var)
print(var.value)
jade ferry
#

that's ugly 😔

vernal roost
#

you don't need the var=func(var)

#

all tables pass by reference

#
local function func(p)
  p.value += 1
end

local var = {value = 0}
func(var)
print(var.value)```
warm marshBOT
visual dirge
#

wtf is func()

vernal roost
#

all other base types get passed by value / copy

#

only things passed by reference I am aware of is tables, and userdata like instances (which are effectively just tables)

jade ferry
#

there's another way but it uses metatables and it looks more ugly

vernal roost
jade ferry