marwenissaoui / blockly

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

add the flexibility to support 'type' in variables #79

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

Though JS/Dart/Python not need 'type' (or use 'var' only) for code generation, 
There are still wide range of languages that needs strong typing declaration.
Current variable subsystem can't fulfill these need.

What is the expected output? What do you see instead?

Add the flexibility to support 'type' in variables. 

Here is one approach to add a strong type language generator with variables:

1. patch to add a type dropdown menu in function 
'Blockly.Language.variables_set' in language/common/variables.js:

{{{
this.appendTitle(Blockly.LANG_VARIABLES_SET_TITLE_1);
     this.appendTitle(new Blockly.FieldVariable(
         Blockly.LANG_VARIABLES_SET_ITEM), 'VAR');
     this.appendTitle("as type");
     this.appendTitle(new Blockly.FieldDropdown([["Boolean", "Boolean"], ["Number", "int"], ["String", "String"]]), "TYPE");
     this.appendTitle("value");
     this.appendInput(Blockly.INPUT_VALUE, 'VALUE', null);
}}}

2. save a variable object (contain name and type) instead of save variable name 
only

3. patch blockly/variables.js to return variable object.

4. update current support generators to reflect this change.

Original issue reported on code.google.com by gasolin on 7 Oct 2012 at 8:02

GoogleCodeExporter commented 9 years ago
It has room for discussion about if its appropriate to add a type dropdown menu 
directly in language/common/variables.js. Maybe it can just left for other 
strong type language specific file.
Otherwise a 'type' metadata can help generator to validate if the block content 
is valid.

I think 'typescript' generator may be a good candidate for the next support 
language
(which is fully javascript compatible, it means we can start from JS generator 
and focus on enhance the variables subsystem)
http://www.typescriptlang.org/tutorial/

Original comment by gasolin on 7 Oct 2012 at 8:11

GoogleCodeExporter commented 9 years ago
Update status:

I've create variable object, with no need to modify current language 
definitions. 

Then I'll try to use the comment symbol as a variable type reference to 
generate code. (show Number as i, String as s,...etc). 

and stocked by Issue #83

Original comment by gasolin on 22 Oct 2012 at 2:38

GoogleCodeExporter commented 9 years ago
Would love to see this!

Original comment by mchldu...@gmail.com on 2 Apr 2013 at 1:59

GoogleCodeExporter commented 9 years ago
I am building generator for Perl language but facing the same issue for 
variable type. I need the block to be able to show which variables are suitable 
according to the neighbor output type.
But still Blockly is very interesting to play with!

Original comment by pembaj...@gmail.com on 23 Apr 2013 at 1:52

GoogleCodeExporter commented 9 years ago
I have implemented custom variable types here; 
https://github.com/RaniSputnik/blockly/tree/feature-variable-types
They are presented as a drop-down on the custom variable blocks, update the 
drop-down on one block and it propagates to the others.

The type checking does nothing for the default generators, but is there to be 
used by any new generators that require a type. You can access the type of the 
variable same as any other block, block.getFieldValue('TYPE').

We require it for our level editor @http://make.gamefroot.com so I expect we 
will be keeping this up-to-date with the Blockly master indefinitely.

Cheers, R,

Original comment by alternat...@gmail.com on 8 Feb 2015 at 11:49

GoogleCodeExporter commented 9 years ago
That scrip is what? Please explain to me, because I want in depth
http://wdfshare.blogspot.com

Original comment by the961be...@gmail.com on 18 Mar 2015 at 5:15