Node-RED for code generation

Has anyone else thought of, or attempted to use NR as a visual code generator for an external language?

In my case of interest that would be Lua. However the application for this I have in mind might work if Node-RED could produce Typescript as there is a transpilation layer made available.

The inspiration for this is first, having completed a project with NR and been inspired by the possibilities, and second watching my kids learn to 'code' with Scratch.

Incidentally, my searches brought me right back here when I found this really fun and clever hack to break open Scratch and connect it to node:

Maybe there's even something possible that could recruit / hijack Scratch into this plan for its UI/codegen.

Separate but related concern, is Node-RED going to hit blockers as a code gen tool? Scratch has been designed to create code and might be the minimum level of similarity to code, but what I see in NR is the possibility at least to craft one or two page scripts where everything is neatly packaged into functions.

and flipping it round there is the scratch like blockly node for coding within Node-RED :slight_smile:

1 Like

Beat me to it! Was going to say exactly the same thing.

1 Like

Well that was a slam dunk, awesome stuff. Something to bottom out for sure, thanks chaps. Will report back how I get on with this,

Note that the node-red-contrib-blockly node only generates Javascript code, which is then executed in a NodeJs vm (identical to the function-node). There is no way to generate other languages with it, like you can do with standard Blockly. I only developed the blockly node, to allow people (with less Javascript knowledge) to develop their own custom functions, and execute the generated Javascript code automatically.

1 Like

Oops, deleted my post by mistake. Nevermind it was a load of waffle but did help me think about things a bit. TLDR, I'm going to experiment with your excellent solution @BartButenaers.

It may be possible to transpile from JS to Lua quite reliably, but first I'm going to need to look at how to add library modules to node-red-contrib-blockly. Happy to get into the code, so we'll see what can be achieved

At the time being I have implelented this issue, to allow people to create their own blocks. And those blocks are added to the toolbar. So I assume you can create your own blocks, which generate code. So I assume you can generate code for another language.

However that is only about code generation. From here on the generated code is injected into the vm. And to be honest I want the code and the config screen of this node as simple as possible. So please discuss your proposals before you start implementing.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.