Like asked in the title, lets say I want to add a custom method to the table
type, lets say table:printContent()
, is there any way in Lua to achieve this? I mean only, pure, Lua. In C#, for example, you can use extensions to do that:
using System;
namespace Main {
public static class Extension {
public static void printContent(this table mytable) {
foreach(var content in mytable) {
Console.WriteLine(content.ToString());
}
}
}
}
Now is the same possible, only in Lua?
The question I inspired me from (that question didn‘t tought me what I wanted to learn, and yes I want OOP, if I want to mod for example in Lua)
A class is always implemented using Lua tables.
Minimum example:
If you want to add a new method to MyClass simply implement it
The same way can of course be used to overwrite existing methods.