Skip to content
Browse files

results in the repl

  • Loading branch information...
1 parent 400b987 commit 0d8117588905f5aa5b4f4fafe66efcc9e8da9dc6 @substack substack committed Nov 11, 2012
Showing with 12 additions and 6 deletions.
  1. +4 −0 browser/ui/world.js
  2. +8 −6 init.js
View
4 browser/ui/world.js
@@ -65,6 +65,10 @@ function World(model) {
var repl = PlayerRepl(row)
var entity = renderPlayer(paper, center, row)
+ row.on('change', function (ch) {
+ if (ch.error) world.emit('log', 'error: ' + ch.error)
+ if (ch.result) world.emit('log', 'result: ' + ch.result)
+ })
entity.on("click", function () {
world.emit("examine", row)
View
14 init.js
@@ -1,6 +1,7 @@
var model = require('./model')
var api = require('./logic')
var vm = require('vm')
+var inspect = require('util').inspect
var idle = require('idle')
@@ -26,7 +27,7 @@ model.on('create', function (row) {
var timer
var _fn
row.on('change', function (ch) {
- var fn
+ var res
if((ch.source || ch.cast) && row.state.run !== false) {
clearTimeout(timer)
console.log(ch, row.id)
@@ -35,18 +36,19 @@ model.on('create', function (row) {
console.log('\n'+JSON.stringify([ 'start', row.id ]))
try {
- fn = vm.runInNewContext(ch.source || ch.cast, {
+ res = vm.runInNewContext(ch.source || ch.cast, {
self : row.api
})
} catch (err) {
- row.set('message', {
- text: err.toString(),
- stroke: 'red', fill: 'black'
- })
+ row.set('error', String(err))
console.log('\n'+JSON.stringify([ 'error', row.id, String(err) ]))
return
}
console.log('\n'+JSON.stringify([ 'end', row.id ]))
+ try {
+ row.set('result', inspect(res))
+ }
+ catch (e) { row.set('error', String(e)) }
}, 100)
}

0 comments on commit 0d81175

Please sign in to comment.
Something went wrong with that request. Please try again.