File tree Expand file tree Collapse file tree 4 files changed +48
-0
lines changed
Expand file tree Collapse file tree 4 files changed +48
-0
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ target_sources(scratchcpp
1111 operatorblocks.cpp
1212 variableblocks.cpp
1313 listblocks.cpp
14+ customblocks.cpp
1415 PUBLIC
1516 motionblocks.h
1617 looksblocks.h
@@ -21,4 +22,5 @@ target_sources(scratchcpp
2122 operatorblocks.h
2223 variableblocks.h
2324 listblocks.h
25+ customblocks.h
2426)
Original file line number Diff line number Diff line change 1+ // SPDX-License-Identifier: Apache-2.0
2+
3+ #include " customblocks.h"
4+ #include " ../engine/compiler.h"
5+
6+ using namespace libscratchcpp ;
7+
8+ CustomBlocks::CustomBlocks ()
9+ {
10+ // Blocks
11+ addHatBlock (" procedures_definition" );
12+ addCompileFunction (" procedures_call" , &compileCall);
13+ }
14+
15+ std::string CustomBlocks::name () const
16+ {
17+ return " Custom blocks" ;
18+ }
19+
20+ void CustomBlocks::compileCall (Compiler *compiler)
21+ {
22+ const std::string &code = compiler->block ()->mutationPrototype ()->procCode ();
23+ compiler->addInstruction (vm::OP_CALL_PROCEDURE, { compiler->procedureIndex (code) });
24+ }
Original file line number Diff line number Diff line change 1+ // SPDX-License-Identifier: Apache-2.0
2+
3+ #pragma once
4+
5+ #include " ../engine/iblocksection.h"
6+
7+ namespace libscratchcpp
8+ {
9+
10+ class CustomBlocks : public IBlockSection
11+ {
12+ public:
13+ CustomBlocks ();
14+
15+ std::string name () const override ;
16+
17+ static void compileCall (Compiler *compiler);
18+ };
19+
20+ } // namespace libscratchcpp
Original file line number Diff line number Diff line change 1010#include " operatorblocks.h"
1111#include " variableblocks.h"
1212#include " listblocks.h"
13+ #include " customblocks.h"
1314
1415using namespace libscratchcpp ;
1516
@@ -39,4 +40,5 @@ void StandardBlocks::registerSections(Engine *engine)
3940 engine->registerSection (std::make_shared<OperatorBlocks>());
4041 engine->registerSection (std::make_shared<VariableBlocks>());
4142 engine->registerSection (std::make_shared<ListBlocks>());
43+ engine->registerSection (std::make_shared<CustomBlocks>());
4244}
You can’t perform that action at this time.
0 commit comments