Skip to content

Commit b1c63d6

Browse files
committed
Add a getter for block functions to IEngine
1 parent 23b8a95 commit b1c63d6

File tree

5 files changed

+12
-0
lines changed

5 files changed

+12
-0
lines changed

include/scratchcpp/iengine.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,9 @@ class LIBSCRATCHCPP_EXPORT IEngine
217217
/*! Returns the index of the given block function. */
218218
virtual unsigned int functionIndex(BlockFunc f) = 0;
219219

220+
/*! Returns the list of block functions. */
221+
virtual const std::vector<BlockFunc> &blockFunctions() const = 0;
222+
220223
/*!
221224
* Call this from IBlockSection#registerBlocks() to add a compile function to a block section.
222225
* \see <a href="blockSections.html">Block sections</a>

src/engine/internal/engine.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -887,6 +887,11 @@ unsigned int Engine::functionIndex(BlockFunc f)
887887
return m_functions.size() - 1;
888888
}
889889

890+
const std::vector<BlockFunc> &Engine::blockFunctions() const
891+
{
892+
return m_functions;
893+
}
894+
890895
void Engine::addCompileFunction(IBlockSection *section, const std::string &opcode, BlockComp f)
891896
{
892897
auto container = blockSectionContainer(section);

src/engine/internal/engine.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ class Engine : public IEngine
103103
void registerSection(std::shared_ptr<IBlockSection> section) override;
104104
std::vector<std::shared_ptr<IBlockSection>> registeredSections() const;
105105
unsigned int functionIndex(BlockFunc f) override;
106+
const std::vector<BlockFunc> &blockFunctions() const override;
106107

107108
void addCompileFunction(IBlockSection *section, const std::string &opcode, BlockComp f) override;
108109
void addHatPredicateCompileFunction(IBlockSection *section, const std::string &opcode, HatPredicateCompileFunc f) override;

test/engine/engine_test.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,8 @@ TEST(EngineTest, Functions)
905905
ASSERT_EQ(engine.functionIndex(&testFunction2), 1);
906906
ASSERT_EQ(engine.functionIndex(&testFunction1), 0);
907907
ASSERT_EQ(engine.functionIndex(&testFunction2), 1);
908+
909+
ASSERT_EQ(engine.blockFunctions(), std::vector<BlockFunc>({ &testFunction1, &testFunction2 }));
908910
}
909911

910912
void compileTest1(Compiler *)

test/mocks/enginemock.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ class EngineMock : public IEngine
8484

8585
MOCK_METHOD(void, registerSection, (std::shared_ptr<IBlockSection>), (override));
8686
MOCK_METHOD(unsigned int, functionIndex, (BlockFunc), (override));
87+
MOCK_METHOD(const std::vector<BlockFunc> &, blockFunctions, (), (const, override));
8788

8889
MOCK_METHOD(void, addCompileFunction, (IBlockSection *, const std::string &, BlockComp), (override));
8990
MOCK_METHOD(void, addHatPredicateCompileFunction, (IBlockSection *, const std::string &, HatPredicateCompileFunc), (override));

0 commit comments

Comments
 (0)