PauloTinocoo / blockly

Automatically exported from code.google.com/p/blockly
0 stars 0 forks source link

Run in code demo #15

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Is there a way to run code, built in "code demo", and view result of program 
execution?

Original issue reported on code.google.com by roman.ku...@gmail.com on 5 Jun 2012 at 6:40

GoogleCodeExporter commented 9 years ago
I've make a working 'Run in code demo' example in 
http://www.gasolin.idv.tw/public/blockly/demos/code/index.html

all you need is:

1. add a link in demo page

<a href="javascript: return false;" onclick="javascript:runJS()">Run in 
Javascript</a>

2. add a runJS() function below the init(blockly) function

function runJS() {
  console.log("run");
  tabClick("tab_javascript");
  var x=document.getElementById('content_javascript');
  console.log(x.innerHTML);
  eval(x.innerHTML);
}

click the link will be switched to javascript tab and run the script.

Original comment by gasolin on 7 Jun 2012 at 5:34

GoogleCodeExporter commented 9 years ago
a modified version will just run the code without switch to JS tab

function runJS() {
  eval(Blockly.Generator.workspaceToCode('JavaScript'))
}

Original comment by gasolin on 9 Jun 2012 at 5:57

GoogleCodeExporter commented 9 years ago
Good idea, and one that gets mentioned a lot by visitors.  I've pushed revision 
225 which adds a run button and does basic error trapping.

However, unlike the more limited and more complicated execution in the maze 
demo, it does not detect infinite loops and it does not highlight the executed 
blocks.  Doing so would result in unreadable JS code filled with callbacks and 
serial numbers.

Original comment by neil.fra...@gmail.com on 9 Jun 2012 at 7:40

GoogleCodeExporter commented 9 years ago
Have you looked at doing the same thing for playground.html?

Original comment by jkrid...@gmail.com on 17 Sep 2013 at 8:29