You should be able to do this with a metatable with an __index function ā something like
example = {}
example.methods = {
foo1 = function() ... end
foo2 = function() ... end
}
setmetatable(example, {
__index = function(self, index)
if self.methods[index] ~= nil then
return self.methods[index]()
end
end
})
Accessing the āpseudo-fieldā example.foo1 would call example.methods.foo1() behind the scenes.
Not omitting the parentheses would then be like calling example.methods.foo1()(): calling the function, then calling its return value. I doubt the __index function has any way of knowing whether the field being indexed is going to be called as a function or not, so I donāt think you can make parens and no-parens behave identically (all the methods could return themselves at the end, but then calling them with parens would still mean calling them twice).
edit: if you donāt need them to return anything else, they could all return a dummy function that did nothing (or __index could return it, that would save you a few repeated lines of code). Then example.foo1() would work like example.methods.foo1(); noop()