Menu
Coddy logo textTech

Recap: Enums, the Luau Way

Part of the Introduction To Luau section of Coddy's Lua journey — lesson 56 of 73.

challenge icon

Challenge

Medium

Create a literal union type OrderStatus with members "pending", "shipped", "delivered" and "cancelled".

Create a shape alias Order with:

  • id of type number
  • customerName of type string
  • status of type OrderStatus

Create three orders:

  • order1 — id 1001, "Alice Johnson", status "pending"
  • order2 — id 1002, "Bob Smith", status "shipped"
  • order3 — id 1003, "Carol Davis", status "delivered"

Create a function displayOrderInfo that takes an Order and prints Order #[id] for [customerName] is [status].

Create a frozen constant table Priority with Low = 1, Normal = 2, High = 3.

Then, in order:

  1. call displayOrderInfo for each of the three orders
  2. print the status of order2
  3. print Priority.High
  4. print whether Priority is frozen

Try it yourself

-- Write code here
-- 1) define type OrderStatus (literal union) and type Order (shape)
-- 2) create order1, order2, order3
-- 3) write displayOrderInfo
-- 4) create the frozen Priority table
-- 5) print the six requested lines

All lessons in Introduction To Luau