July 2018
Beginner
202 pages
5h 42m
English
A module is just a normal Lua table; a module file is a Lua file which returns a table. For us, this means returning an anonymous table. We are going to create a new file, character.lua, and declare a character class in this file. The definition of the character class is as follows:
-- It's important that the table retuned be local!local character = {}character.health = 20character.strength = 5character.name = ""character.new = function (self, object) object = object or {} -- Use provided table, or create new one local provided = "" if type(object) == "string" then provided = object object = {} end setmetatable(object, self) -- Assign meta table self.__index = self if provided ~= "" then object.name = provided end return ...