DEV Community

Discussion on: The power of Lua's tables and metatables

Collapse
 
tilkinsc profile image
Cody Tilkins • Edited

I once created a fun little demon. Which took advantage of certain features of lua and most importantly - metatables and setfenv.
You can remove the ()'s to a function call when supplying a string or a table.
func({param = value}) -> func{param = value}
func("param") -> func "param"

class "some_class" {
  public = {
    some_var = 5;
    print_var = function(self)
      print(self.some_var)
    end;
  };
  protected = {
    some_var2 = 10;
  };
  private = {
    some_var3 = 15;
  };
  constructor = function(self)

  end;
  destructor = function(self)

  end;
}
register_class("some_class")

local abc = class_some_class.new()
abc.print_var()
Enter fullscreen mode Exit fullscreen mode

It even had full polymorphism.