Menu
Coddy logo textTech

요약: Luau 방식의 Enum

Coddy Lua 여정의 Luau 소개 섹션에 포함된 레슨. 73개 중 56번째.

challenge icon

챌린지

중급

"pending", "shipped", "delivered""cancelled"를 멤버로 갖는 리터럴 유니온 타입 OrderStatus를 생성하세요.

다음 항목을 포함하는 shape 별칭 Order를 생성하세요.

  • 타입이 numberid
  • 타입이 stringcustomerName
  • 타입이 OrderStatusstatus

세 개의 order를 생성하세요.

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

Order를 인수로 받아 Order #[id] for [customerName] is [status]를 출력하는 함수 displayOrderInfo를 생성하세요.

Low = 1, Normal = 2, High = 3을 포함하는 frozen constant table Priority를 생성하세요.

그런 다음, 다음 순서대로 수행하세요.

  1. 세 order 각각에 대해 displayOrderInfo를 호출하세요.
  2. order2의 status를 출력하세요.
  3. Priority.High를 출력하세요.
  4. Priority가 frozen인지 출력하세요.

직접 해보기

-- 여기에 코드를 작성하세요
-- 1) 타입 OrderStatus (리터럴 유니온)과 타입 Order (형태)를 정의하세요
-- 2) order1, order2, order3을 생성하세요
-- 3) displayOrderInfo를 작성하세요
-- 4) 동결된 Priority 테이블을 생성하세요
-- 5) 요청된 여섯 줄을 출력하세요

Luau 소개의 모든 레슨

직접 연습해 보세요: 온라인 Lua 컴파일러