Embed Lua Script
if( ((String)langCombo.getSelectedItem()).equalsIgnoreCase("lua") ) {
SwingUtilities.invokeLater(() -> {
try {
ScriptEngine luaScript;
luaScript = new ScriptEngineManager().getEngineByName("luaj");
luaScript.put("write", new print());
luaScript.put("writeln", new println());
outputPrintLn("<START Lua>");
luaScript.eval(textTab.getSelectedTextView().getText());
outputPrintLn("<END Lua>");
} catch (Exception e) {
e.printStackTrace();
outputPrintLn("error\n" + e.getMessage());
}
});
}
public void outputPrint(String text) {
SwingUtilities.invokeLater( () -> {
output.append(text );
});
}
public void outputPrintLn(String text) {
SwingUtilities.invokeLater( () -> {
output.append(text + "\n");
});
}
class print extends OneArgFunction {
@Override
public LuaValue call(LuaValue lv) {
outputPrint(lv.checkstring().tojstring());
return LuaValue.valueOf(0);
}
}
class println extends OneArgFunction {
@Override
public LuaValue call(LuaValue lv) {
outputPrintLn(lv.checkstring().tojstring());
return LuaValue.valueOf(0);
}
}
댓글 없음:
댓글 쓰기