Advanced Lua Scripting: Object Oriented Programming

Overview

In this thread we will be learning about Object Oriented Programming for Roblox Lua. This is a relatively advanced subject, so I’d recommend you have some programming experience before jumping into this thread.

By the end of this thread, you should be able to create your own Object Oriented System / Engine for use in Roblox games.

WIP

Please stand by as I construct the rest of this post.

just had to get this out of my drafts, I may or may not actually finish this thread.

yes please fill us up with your precious scripting knowledge

How do you metatables?

Advanced AI brainchip, set a reminder for this topic.

Metatables hold extra functionality for other tables, in the form of metamethods. It’s a bit hard to explain but it isn’t all that hard to understand.

Lets say you want to print a table. You could do this by setting the table’s metatable to another table that has the metamethod .__print(), which will handle it.

Example:

myTable = {
   ["name"] = "hello",
}

myMetatable = {
   ["__print"] = function(self)
      return self.name
   end,
}

setmetatable(myTable,myMetatable)

print(myTable) -- prints "hello"
1 Like