How would I set the type of self?

I have been writing a few methods and I am now wondering if there is a way to set the type of the self parameter since it is automatically defined in methods. Probably pretty simple, but I haven’t found a way to do it yet.

Just use the dot operator instead of colon to declare the self explicitly:

function module.foo(self)
     -- code here
     print(self)
end

-- Test it!
module:foo()

However, if you’re wondering about type-checking. There are hacky ways to go about it which I think other topics have covered on.

I’ve just come up with a different method since all I needed from that was autocomplete. I’ve found it a bit easier to just manually declare self like you said, and the remove it after im finished scripting so I get the autocomplete and I know everything is referenced right, but it also doesn’t give any errors after i’ve finished.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.