File tree Expand file tree Collapse file tree 2 files changed +18
-0
lines changed
Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Original file line number Diff line number Diff line change 11// SPDX-License-Identifier: Apache-2.0
22
33#include " variableblocks.h"
4+ #include " ../engine/compiler.h"
45
56using namespace libscratchcpp ;
67
78VariableBlocks::VariableBlocks ()
89{
910 // Blocks
11+ addCompileFunction (" data_setvariableto" , &VariableBlocks::compileSetVariable);
12+ addCompileFunction (" data_changevariableby" , &VariableBlocks::compileChangeVariableBy);
1013 addBlock (" data_setvariableto" , &VariableBlocks::setVariable);
1114 addBlock (" data_changevariableby" , &VariableBlocks::changeVariableBy);
1215
@@ -22,6 +25,18 @@ std::string VariableBlocks::name() const
2225 return " Variables" ;
2326}
2427
28+ void VariableBlocks::compileSetVariable (Compiler *compiler)
29+ {
30+ compiler->addInput (VALUE);
31+ compiler->addInstruction (vm::OP_SET_VAR, { compiler->variableIndex (compiler->field (VARIABLE)->valuePtr ()) });
32+ }
33+
34+ void VariableBlocks::compileChangeVariableBy (Compiler *compiler)
35+ {
36+ compiler->addInput (VALUE);
37+ compiler->addInstruction (vm::OP_CHANGE_VAR, { compiler->variableIndex (compiler->field (VARIABLE)->valuePtr ()) });
38+ }
39+
2540Value VariableBlocks::setVariable (const BlockArgs &args)
2641{
2742 auto variable = std::static_pointer_cast<Variable>(args.field (VARIABLE)->valuePtr ());
Original file line number Diff line number Diff line change @@ -25,6 +25,9 @@ class LIBSCRATCHCPP_EXPORT VariableBlocks : public IBlockSection
2525
2626 std::string name () const override ;
2727
28+ static void compileSetVariable (Compiler *compiler);
29+ static void compileChangeVariableBy (Compiler *compiler);
30+
2831 static Value setVariable (const BlockArgs &args);
2932 static Value changeVariableBy (const BlockArgs &args);
3033};
You can’t perform that action at this time.
0 commit comments