Menu
Coddy logo textTech

Project Setup

Part of the Object Oriented Programming section of Coddy's Lua journey — lesson 19 of 70.

challenge icon

Challenge

Easy

Let's build the foundation for a Shape Manager system! This project will grow over the next several lessons, so we'll start by setting up a clean file structure with a base Shape class.

You'll create two files to organize your code:

  • Shape.lua: Define a base Shape class using the prototype pattern. Every shape has a name attribute (like "Circle" or "Rectangle"). Include a :new(name) constructor that accepts the shape's name, and a :getName() method that returns it.
  • main.lua: Bring your Shape class to life by requiring the module and creating a shape instance. Read a shape name from input, create a Shape with that name, and print the result of calling :getName().

This base class will serve as the parent for specific shapes like Rectangle and Circle in upcoming lessons. For now, focus on getting the class structure right—the __index setup, the constructor pattern, and the getter method.

Input: A single line containing the shape name (a string).

Output: The shape's name returned by :getName().

Try it yourself

-- Require the Shape module
local Shape = require('Shape')

-- Read the shape name from input
local shapeName = io.read()

-- TODO: Create a new Shape instance with the given name

-- TODO: Print the result of calling :getName() on your shape

All lessons in Object Oriented Programming