This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Wilma456's profile picture

Call self function with string

Started by Wilma456, 06 February 2017 - 03:53 PM
Wilma456 #1
Posted 06 February 2017 - 04:53 PM
Id wnat to call a table:func() function with a string. If I write test["func"]() I call test.func and not test:func().Has anybody a idea?
Lupus590 #2
Posted 06 February 2017 - 06:35 PM
I'm not entirely sure if I'm answering our question correctly but I'll have a go as this thread seems quiet.


tab.func(self)
  --# we defined self ourselves
end
--# is same as
tab:func()
  --# self is implied as the first argument by the colon
end
--# calling these functions can be done like so
--# these work for both ways of defining the function above
tab.func(tab) --# pass tab manually
tab:func() --# again implied first argument as tab via colon
--# the one you seem to be interested in but working (or should be)
tab["func"](tab)
Edited on 06 February 2017 - 05:35 PM
Admicos #3
Posted 07 February 2017 - 02:45 AM
You need to provide the table as the self argument manually.