Page 1 of 1

a "run code" block!

Posted: Jul 26th, '17, 21:36
by MSandro
Hi, it would be nice if you can add a block to GP wich can execute any code. It can be helpful maybe to read a text file and run this as a script with this block. And maybe the block should have a dropdown to choice between the GP-Syntax or other languages like VBScript, Batch, or C#...

Thank you very much.

Re: a "run code" block!

Posted: Jul 28th, '17, 10:13
by SimpleSi
My take on this request would be (if doing it at all) that it should just allow a call to an underlying OS/shell command line and then let programmer deal with stuff afterwards

I do this in my ScratchGPIO that runs on a RaspberryPi - users can

broadcast "run xxxxxxxxxxxxxx" and it just does a call to the shell and executes xxxxxxxxxxxxx
0.png
0.png (2.33 KiB) Viewed 17516 times

Re: a "run code" block!

Posted: Jul 29th, '17, 16:25
by JohnM
GP itself can only run GP code, just like the Java virtual machine can only run Java code, the Python interpreter can only run Python code, and the C++ compiler can only compile C++ code. That said, as SimpleSi points out, on platforms that support an OS shell (Mac/Linux/Windows but probably not Android, ChromeOS, or iOS) it would be possible to create a block that runs programs written in other languages via the OS shell. That might be a useful feature to add to GP at some point. (It's also potentially dangerous, so perhaps GP should ask the user's permission before running that command...)

It *is* possible to load and run GP code using the developer mode menu command "load source file...". For example, you can create a file named "tmp.gp" containing the line:

Code: Select all

showText 'Hello, GP!'
then enter developer mode and select "load source file..." from the right-click menu on the stage. A Workspace (text) window will pop up the given text in it.

What applications were you thinking of that would need this feature?

-- John