Search code examples
luacoronasdk

Call colon function with brackets in lua


I've been researching this for a while with no luck. I want to dynamically call colon function in lua like I do regular functions.

obj['functionName']()

However the following won't work.

obj:['functionName']()

is there a work around? Do I have to explicitly add the obj to the function arguments? I'd rather not do the following unless I have to... ie:

obj['functionName'](obj)

Thanks!


Solution

  • the "obj:function()" syntax is (as defined in lua doc) "syntactical sugar" for obj.function(obj), so no, there is no way to bypass this. The syntactic sugar is aimed to a very specific situation.