Menu
Coddy logo textTech

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

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

challenge icon

챌린지

중급

Computer라는 타입 별칭을 다음과 같이 만드세요:

  • idnumber 타입
  • brandstring 타입
  • ramInGBnumber? 타입 (optional)
  • boot: (self: Computer) -> () method

두 개의 컴퓨터를 만드세요 (colon definition syntax를 사용하여 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 function을 만드세요. RAM을 알고 있는 경우에는 [brand] with [ramInGB] GB of RAM을 반환하고, 그렇지 않은 경우에는 [brand] with unknown RAM을 반환합니다.

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

  1. workstation:boot()을 호출합니다.
  2. laptop:boot()을 호출합니다.
  3. specs(workstation)을 print합니다.
  4. specs(laptop)을 print합니다.
  5. workstation의 id를 print합니다.

직접 해보기

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

Luau 소개의 모든 레슨

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