Menu
Coddy logo textTech

요약: 테이블 셰이프 정의하기

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

challenge icon

챌린지

중급

다음 조건을 만족하는 Computer라는 이름의 타입 별칭(type alias)을 생성하세요:

  • number 타입의 id
  • string 타입의 brand
  • number? 타입의 ramInGB (선택 사항)
  • (self: Computer) -> () 메소드인 boot

두 개의 컴퓨터를 생성하세요 (콜론 구문을 사용하여 boot를 연결하세요):

  • workstation — id 1001, brand "Dell", ramInGB 16; 해당 boot[brand] is booting up...을 출력합니다.
  • laptop — id 1002, brand "MacBook", ramInGB 없음; 해당 boot[brand] is starting...을 출력합니다.

Computer를 매개변수로 받고 string을 반환하는 함수 specs를 작성하세요. RAM을 알 수 있는 경우 [brand] with [ramInGB] GB of RAM을 반환하고, 그렇지 않으면 [brand] with unknown RAM을 반환합니다.

그런 다음, 순서대로 진행하세요:

  1. workstation:boot() 호출
  2. laptop:boot() 호출
  3. specs(workstation) 출력
  4. specs(laptop) 출력
  5. workstation의 id 출력

직접 해보기

-- 여기에 코드를 작성하세요
-- 1) Computer 타입 정의 (선택적 ramInGB, boot 메서드)
-- 2) workstation과 laptop 생성, 콜론 구문으로 boot 연결
-- 3) ramInGB에 대한 nil 검사와 함께 specs 작성
-- 4) 둘 다 boot, 둘 다 specs 출력, workstation.id 출력

Luau 소개의 모든 레슨