2022년 4월 30일 토요일

[Java] How to embed Bean Shell

Embed Bean Shell

if( ((String)langCombo.getSelectedItem()).equalsIgnoreCase("java") ) {
    SwingUtilities.invokeLater( () -> {
        try {
            bsh.Interpreter bshScript;
            bshScript = new bsh.Interpreter();
            bshScript.set("instance", this);
            bshScript.eval("void write(text) { instance.outputPrint(text); }");
            bshScript.eval("void writeln(text) { instance.outputPrintLn(text); }");
            outputPrintLn("<START Java>");
            bshScript.eval(textTab.getSelectedTextView().getText());
            outputPrintLn("<END Java>");
        } catch (Exception e) {
            e.printStackTrace();
            outputPrintLn("error\n" + e.getMessage());
        }   
    }); 
}

댓글 없음:

댓글 쓰기