bartbutenaers / node-red-contrib-blockly

A Node Red node for visual programming a function using Blockly
Apache License 2.0
89 stars 22 forks source link

buffer loop is NaN #42

Closed cymplecy closed 5 years ago

cymplecy commented 5 years ago

image

is converted to

var chars, i;

chars = (Buffer.from('ABCDE', "utf8"));
var i_end = (chars.length);
var i_inc = 1;
if (1 > i_end) {
  i_inc = -i_inc;
}
for (i = 1; i_inc >= 0 ? i <= i_end : i >= i_end; i += i_inc) {
  chars[NaN] = 32;
}
bartbutenaers commented 5 years ago

Hi Simon (@cymplecy ),
can you please post your flow here. Then I will have a look at it this evening.

cymplecy commented 5 years ago

[{"id":"66bc3268.122b1c","type":"Blockly","z":"e94b6576.d50958","language":"en","func":"var chars, i;\n\n\nchars = (Buffer.from('ABCDE', \"utf8\"));\nvar i_end = (chars.length);\nvar i_inc = 1;\nif (1 > i_end) {\n i_inc = -i_inc;\n}\nfor (i = 1; i_inc >= 0 ? i <= i_end : i >= i_end; i += i_inc) {\n chars[NaN] = 32;\n}\n","workspaceXml":"<xml xmlns=\"http://www.w3.org/1999/xhtml\"><variables><variable type=\"\" id=\"Z@/+I,dmOljwGn4?XJ0I\">chars</variable><variable type=\"\" id=\")jU4tpD],qwF{9((T=aQ\">i</variable></variables><block type=\"variables_set\" id=\"wJ/D93bJ;|gdG~?|L,/H\" x=\"13\" y=\"13\"><field name=\"VAR\" id=\"Z@/+I,dmOljwGn4?XJ0I\" variabletype=\"\">chars</field><value name=\"VALUE\"><block type=\"buffer_from_string\" id=\"f3?w#.F64L_OOAYVbfg4\"><field name=\"ENCODING\">utf8</field><value name=\"STRING_INPUT\"><shadow type=\"text\" id=\"i2gJ@Gsq|ZDIR;eZ}22X\"><field name=\"TEXT\">ABCDE</field></shadow></value></block></value><next><block type=\"controls_for\" id=\"72W^Os8#a(]IlVj1+jT\"><field name=\"VAR\" id=\")jU4tpD],qwF{9((T=aQ\" variabletype=\"\">i<value name=\"FROM\"><shadow type=\"math_number\" id=\"i?3V#e$$}/I=-OFV#I!\"><field name=\"NUM\">1</field></shadow></value><value name=\"TO\"><shadow type=\"math_number\" id=\"v26dbbrZ_@l%NSSJ_/E4\"><field name=\"NUM\">10</field></shadow><block type=\"buffer_length\" id=\"@uq@R7ZPh2dtP.0z_$^m\"><value name=\"BUFFER_INPUT\"><shadow type=\"buffer_empty\" id=\"T5a[G!R=bDqFkfxGo;?]\"></shadow><block type=\"variables_get\" id=\"J|Z.COZ;1^gCQ,yYGK\"><field name=\"VAR\" id=\"Z@/+I,dmOljwGn4?XJ0I\" variabletype=\"\">chars<value name=\"BY\"><shadow type=\"math_number\" id=\"IlAF2YElS|h!0CYpGX-\"><field name=\"NUM\">1</field></shadow></value><statement name=\"DO\"><block type=\"buffer_set_index\" id=\"@wY2ZqDb,]{v6poOthCW\"><value name=\"INDEX\"><shadow type=\"math_number\" id=\"tmZ:1rmRM.VwKgMt#r6\"><field name=\"NUM\">1<block type=\"variables_get\" id=\".-jJ)8+!:KeZ^Dd+i#\"><field name=\"VAR\" id=\")jU4tpD],qwF{9((T=aQ\" variabletype=\"\">i</field></block></value><value name=\"BUFFER\"><shadow type=\"buffer_empty\" id=\"F/~|i}J1DHT69p!C^v+\"><block type=\"variables_get\" id=\".GK_wq;=Jm#1Ysl}355Y\"><field name=\"VAR\" id=\"Z@/+I,dmOljwGn4?XJ0I\" variabletype=\"\">chars<value name=\"VALUE\"><shadow type=\"buffer_byte\" id=\"!z2ElQinieWsA]pHP8Z3\"><field name=\"BYTE_VALUE\">32","outputs":1,"name":"parseColours","x":690,"y":540,"wires":[[]]}] `

I don't think Blockly flows copy and paste OK so here is pastebin link

https://pastebin.com/MD3N7NGy

cymplecy commented 5 years ago

Fixed it in get and set - pull request made

var chars, i;

chars = (Buffer.from('ABCDE', "utf8"));
var i_end = (chars.length);
var i_inc = 1;
if (1 > i_end) {
  i_inc = -i_inc;
}
for (i = 1; i_inc >= 0 ? i <= i_end : i >= i_end; i += i_inc) {
  chars[(i - 1)] = 32;
}