0

Is there any way to change the access to my C# object methods in Lua by turning two dots into one? I want to change this:

Object:DoSomething();

Into this:

Object.DoSomething();

Without getting any errors. Any ideas? Thanks in advance.

2 Answers2

2

The two lines do different things. Object:DoSomething() is syntax sugar for Object.DoSomething(Object). It's what turns a regular object lookup+function call into a method call.

So no, there's no way to do this.

Colonel Thirty Two
  • 23,953
  • 8
  • 45
  • 85
  • So, maybe, I can parse my script with regex before running it, replacing ".DoSomething(" with ":DoSomething(Object," ? – Vasiliy Pupkin Sep 29 '14 at 16:03
  • 1
    What happens if you have `SomeOtherObject.DoSomething()` where `DoSomething` is a static method (i.e. it doesn't take a self parameter)? That will screw it up. Why are you trying so hard to avoid `:`? – Colonel Thirty Two Sep 29 '14 at 16:06
0

No. Here's an alternative...

You can consider Object:DoSomething() to be a .NET extension method. Just like a .NET extension method, you can choose to call it like the "static" method it is:

Object.DoSomething(Object);
Tom Blodget
  • 20,260
  • 3
  • 39
  • 72