Menu
CoddyTech

Recap: Enums, the Luau Way

Part of the Introduction To Luau section of Coddy's Lua journey. Lesson 60 of 80.

challenge icon

Challenge

Medium

Describe an order with an enum and a frozen table.

  1. Write type OrderStatus = "pending" | "shipped" | "delivered" and type Order = {id: number, status: OrderStatus}.
  2. Write describeOrder(order: Order): string returning `Order #{order.id} is {order.status}`.
  3. Create local Priority = table.freeze({Low = 1, High = 2}), then print describeOrder({id = 1002, status = "shipped"}) and Priority.High.

Press Run Code: the output shows Order #1002 is shipped and 2.

Try it yourself

-- 1) type OrderStatus and type Order
-- 2) describeOrder(order: Order): string
-- 3) the frozen Priority table, then the two prints
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Introduction To Luau

Practice on your own: Online Luau compiler