Skip to content

표준출력(보여주기)과 오류(stderr) 받아오기

약속 코드에서 보여주기로 출력된 값은 기본적으로는 console.log로 출력됩니다. config 객체를 사용하여 출력 방식을 변경할 수 있습니다.

typescript
import { SessionConfig, YaksokSession } from "@dalbit-yaksok/core";

const code = `
"안녕, 세상!" 보여주기
`;

const config: Partial<SessionConfig> = { 
  stdout(message: string) { 
    alert("[보여주기] " + message); 
  }, 
}; 

const session = new YaksokSession(config);
session.addModule("main", code);
await session.runModule("main");

오류(stderr) 출력하기

stdout과 마찬가지로 stderr도 출력 방식을 변경할 수 있습니다. 기본적으로 stderrconsole.error로 출력됩니다.

typescript
import { SessionConfig, YaksokSession } from "@dalbit-yaksok/core";

const code = `
"안녕, 세상!" / 10 보여주기
`; // 오류가 발생할 코드

const config: Partial<SessionConfig> = { 
  stderr(message: string) { 
    alert("[오류] " + message); 
  }, 
}; 

const session = new YaksokSession(config);
session.addModule("main", code);
await session.runModule("main");

자세한 내용은 다음 문서를 참조하세요: