trying to setup python code generator

75 views
Skip to first unread message

Jhinmainksta

unread,
Sep 18, 2024, 11:27:29 AM9/18/24
to Blockly
Hello everyone.
Is build-in python generator not complete?
Get blockly code Create-package script way from here:
https://developers.google.com/blockly/guides/get-started/get-the-code

Make changes here:
Снимок экрана 2024-09-16 174155.png
But for some blocks an error appears
Снимок экрана 2024-09-16 175210.png
Снимок экрана 2024-09-16 175333.png
Then, after i refresh page, code generator stops working and each further refresh brings me back to the blocks config that caused error. When i roll back index.js changes and refresh page - blockly start to work again. What am i doing wrong? 

Christopher Allen

unread,
Sep 18, 2024, 3:25:11 PM9/18/24
to blo...@googlegroups.com
Hi Jhinmainksta,

Is build-in python generator not complete?

It is.
 
Get blockly code Create-package script way from here: …
Make changes here: …
But for some blocks an error appears…

Then, after i refresh page, code generator stops working and each further refresh brings me back to the blocks config that caused error. When i roll back index.js changes and refresh page - blockly start to work again. What am i doing wrong?

You will see you have changed the code to read (emphasis added):

import {forBlock} from './generators/javascript';
// ...
Object.assign(pythonGenerator.forBlock, forBlock);

…which adds block generator functions for the demo's custom blocks, which generate JavaScript code, to the Python generator.  This… is something you can do… but will generate code containing a mix of Python and JavaScript which is unlikely to be valid in either language.

And your changes also result in:

  const code = pythonGenerator.workspaceToCode(ws);
  // ...
  eval(code);

… which will result in mostly-Python code being evaluated as JavaScript, which is again unlikely to work as you expect.

If you delete the eval statement (which you should do anyway—it's just there for demo purposes) and provide alternative versions of block generator functions in generators/javascript.js that produce Python instead then you should find things working as expected.


Best wishes,

Christopher



 

--
You received this message because you are subscribed to the Google Groups "Blockly" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blockly+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/blockly/b784360d-accd-4557-9b2f-a51aec2ef73en%40googlegroups.com.

Jhinmainksta

unread,
Sep 19, 2024, 9:20:20 AM9/19/24
to Blockly
Seems like it's all because of eval() trying do execute python code. Find out that it's javascript method while searched how to execute python code earlier, but somehow didn't think of it 😊. Tywm,  Christopher!
Reply all
Reply to author
Forward
0 new messages