@@ -193,7 +193,7 @@ void Engine::startScript(std::shared_ptr<Block> topLevelBlock, std::shared_ptr<T
193193 }
194194}
195195
196- void libscratchcpp:: Engine::broadcast (unsigned int index, VirtualMachine *sourceScript, bool wait)
196+ void Engine::broadcast (unsigned int index, VirtualMachine *sourceScript, bool wait)
197197{
198198 bool previousSkipFrame = m_skipFrame;
199199 skipFrame ();
@@ -305,7 +305,7 @@ void Engine::breakFrame()
305305 m_breakFrame = true ;
306306}
307307
308- bool libscratchcpp:: Engine::breakingCurrentFrame ()
308+ bool Engine::breakingCurrentFrame ()
309309{
310310 return m_breakFrame;
311311}
@@ -337,6 +337,16 @@ void Engine::registerSection(std::shared_ptr<IBlockSection> section)
337337 }
338338}
339339
340+ std::vector<std::shared_ptr<IBlockSection>> Engine::registeredSections () const
341+ {
342+ std::vector<std::shared_ptr<IBlockSection>> ret;
343+
344+ for (const auto &[key, value] : m_sections)
345+ ret.push_back (key);
346+
347+ return ret;
348+ }
349+
340350unsigned int Engine::functionIndex (BlockFunc f)
341351{
342352 auto it = std::find (m_functions.begin (), m_functions.end (), f);
@@ -346,39 +356,39 @@ unsigned int Engine::functionIndex(BlockFunc f)
346356 return m_functions.size () - 1 ;
347357}
348358
349- void libscratchcpp:: Engine::addCompileFunction (IBlockSection *section, const std::string &opcode, BlockComp f)
359+ void Engine::addCompileFunction (IBlockSection *section, const std::string &opcode, BlockComp f)
350360{
351361 auto container = blockSectionContainer (section);
352362
353363 if (container)
354364 container->addCompileFunction (opcode, f);
355365}
356366
357- void libscratchcpp:: Engine::addHatBlock (IBlockSection *section, const std::string &opcode)
367+ void Engine::addHatBlock (IBlockSection *section, const std::string &opcode)
358368{
359369 auto container = blockSectionContainer (section);
360370
361371 if (container)
362372 container->addHatBlock (opcode);
363373}
364374
365- void libscratchcpp:: Engine::addInput (IBlockSection *section, const std::string &name, int id)
375+ void Engine::addInput (IBlockSection *section, const std::string &name, int id)
366376{
367377 auto container = blockSectionContainer (section);
368378
369379 if (container)
370380 container->addInput (name, id);
371381}
372382
373- void libscratchcpp:: Engine::addField (IBlockSection *section, const std::string &name, int id)
383+ void Engine::addField (IBlockSection *section, const std::string &name, int id)
374384{
375385 auto container = blockSectionContainer (section);
376386
377387 if (container)
378388 container->addField (name, id);
379389}
380390
381- void libscratchcpp:: Engine::addFieldValue (IBlockSection *section, const std::string &value, int id)
391+ void Engine::addFieldValue (IBlockSection *section, const std::string &value, int id)
382392{
383393 auto container = blockSectionContainer (section);
384394
@@ -398,6 +408,9 @@ void Engine::setBroadcasts(const std::vector<std::shared_ptr<Broadcast>> &broadc
398408
399409std::shared_ptr<Broadcast> Engine::broadcastAt (int index) const
400410{
411+ if (index < 0 || index >= m_broadcasts.size ())
412+ return nullptr ;
413+
401414 return m_broadcasts[index];
402415}
403416
@@ -423,7 +436,7 @@ int Engine::findBroadcastById(const std::string &broadcastId) const
423436 return -1 ;
424437}
425438
426- void libscratchcpp:: Engine::addBroadcastScript (std::shared_ptr<Block> whenReceivedBlock, std::shared_ptr<Broadcast> broadcast)
439+ void Engine::addBroadcastScript (std::shared_ptr<Block> whenReceivedBlock, std::shared_ptr<Broadcast> broadcast)
427440{
428441 auto id = findBroadcast (broadcast->name ());
429442 if (m_broadcastMap.count (id) == 1 ) {
@@ -459,6 +472,9 @@ void Engine::setTargets(const std::vector<std::shared_ptr<Target>> &newTargets)
459472
460473Target *Engine::targetAt (int index) const
461474{
475+ if (index < 0 || index >= m_targets.size ())
476+ return nullptr ;
477+
462478 return m_targets[index].get ();
463479}
464480
0 commit comments