How do a generate a JavaScript function scoped variable with Blockly? - blockly

I have a function block in my Blockly workspace, but I can't seem to find a way to add a variable that is scoped to a function. Adding a variable to the workspace generates a variable defined at the top of my generated code.
Is there a way with the pre-built blocks to create a variable within a function block?

Unfortunately, not really; all of the variables in Blockly are global. One thing you can do is have the function block in some way know which variables it's using and then redefine it with 'let' inside the function such that it won't be modified outside of the function, but variable selectors will still be able to select the variable regardless of location.

Related

How do I find a variable in NODEJS

Good day,
I am trying to read a variable from a process. With javascript, I know, you can use console.log(window['variable-name']) to find a variable's contents using a string.
However, for NodeJs, I know you can use console.log(global['variable-name']), but the variable needs to be global, how can I read module local variables?
Short answer: only by exporting them (module.exports.your_var = your_var) or by setting the variable on global (global.your_var = your_var).
Longer answer:
Modules, when loaded by Node.js, are being wrapped within a Javascript function and then called when required the first time. Function variables belong to the function's scope and they are unaccessible from outside.

Any way to redefine global variable in .gitlab-ci.yml?

I've changed the value of the variable defined in my .gitlab-ci.yml, but I've noticed, that the old value is still used.
After a few retries I've checked the global configuration to find out, that the variable with the same name is defined in the global CI settings, and my pipeline is not taking the 'old' value defined in .gitlab-ci.yml, but that defined in the global scope.
Is there any way to override the globally defined variables, or at least get warned when the global value gets the precedence?
Some commands are very strict about what variables they use, and if someone defined the global defaults, that need to be changed in my case, I have a little problem here.

How to inline assembly into file scope passing Rust-defined constants?

I need the same behavior as the global_asm! macro, but passing constants defined in my Rust code. The obvious choice would be to use a (private) naked function that contains inline asm! instruction, but I don't see any way to prevent such a function from being removed by linker as unused. Can you suggest a proper way of doing that?

how to create global nanoc variable between preprocessor and rule

I create variable #foo in preprocessor block. It is global for the time of preprocessing, i.e. different methods can access it. However, in compilation time, i.e. in Rules, this variable is not available.
Currently, I use #config map to store such variables. How to create global variable that will be shared without using the #config map?

How can I append to a construction variable in a Program() call?

I have a custom environment set up for my tests:
test_env = env.Clone()
test_env.Append(LIBS=['boost_unit_test_framework'])
But for one of my tests, I want to link against an additional library:
test_env.Program('foo_tests',
source='foo/tests.cpp',
LIBS=['extralib'],
LIBPATH=['.'])
Sadly this overrides the LIBS from the environment, when I'd like it to just add to it. Is there a better (i.e. more canonical) way to do this than LIBS=test_env['LIBS'] + ['extralib']?
Specifying a new value for an environment variable in a Builder call (like Program) is always interpreted as an "override". So there is no way around compiling the full replacement value, as you did in your example above.
The other option would be to Clone the environment "test_env" again, and then use Append to add the "extralib" to LIBS...
It's possible to do it like this:
test_env.Program('foo_tests',
source='foo/tests.cpp',
LIBS=['$LIBS', 'extralib'],
LIBPATH=['$LIBPATH', '.'])
SCons is clever enough to properly expand the variable into a list there.

Resources