xrsh-com/com/isoterminal/feat/javascript.js

30 lines
812 B
JavaScript
Raw Normal View History

ISOTerminal.addEventListener('init', function(){
this.addEventListener('emulator-started', function(e){
const emulator = this.emulator
// unix to js device
this.readFromPipe( '/mnt/js', async (data) => {
const buf = await emulator.read_file("js")
2024-09-23 16:58:48 +02:00
const script = this.convert.Uint8ArrayToString(buf)
2024-09-05 19:09:40 +02:00
let PID="?"
try{
2024-09-05 19:09:40 +02:00
if( script.match(/^PID/) ){
PID = script.match(/^PID=([0-9]+);/)[1]
}
let res = (new Function(`${script}`))()
if( res && typeof res != 'string' ) res = JSON.stringify(res,null,2)
2024-09-05 19:09:40 +02:00
// write output to 9p with PID as filename
// *FIXME* not flexible / robust
2024-09-23 16:58:48 +02:00
emulator.create_file(PID, this.convert.toUint8Array(res) )
}catch(e){
console.error(e)
}
})
})
})