Jump to content




Call self function with string


  • You cannot reply to this topic
2 replies to this topic

#1 Wilma456

  • Members
  • 187 posts
  • LocationGermany

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?

#2 Lupus590

  • Members
  • 2,028 posts
  • LocationUK

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 by Lupus590, 06 February 2017 - 06:35 PM.


#3 Admicos

  • Members
  • 207 posts
  • LocationTurkey

Posted 07 February 2017 - 02:45 AM

You need to provide the table as the self argument manually.





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users