Skip to content

Commit 75edf4b

Browse files
committed
Thread: Add runReporter() method
1 parent c92cd6a commit 75edf4b

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

include/scratchcpp/thread.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#pragma once
44

5-
#include "global.h"
5+
#include "valuedata.h"
66
#include "spimpl.h"
77

88
namespace libscratchcpp
@@ -27,6 +27,7 @@ class LIBSCRATCHCPP_EXPORT Thread
2727
Script *script() const;
2828

2929
void run();
30+
ValueData runReporter();
3031
bool runPredicate();
3132
void kill();
3233
void reset();

src/engine/thread.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,15 @@ void Thread::run()
6060
string_pool_set_thread(nullptr);
6161
}
6262

63+
/*! Runs the reporter and returns its return value. */
64+
ValueData Thread::runReporter()
65+
{
66+
string_pool_set_thread(this);
67+
ValueData ret = impl->code->runReporter(impl->executionContext.get());
68+
string_pool_set_thread(nullptr);
69+
return ret;
70+
}
71+
6372
/*! Runs the hat predicate and returns its return value. */
6473
bool Thread::runPredicate()
6574
{

test/thread/thread_test.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <scratchcpp/script.h>
33
#include <scratchcpp/executioncontext.h>
44
#include <scratchcpp/promise.h>
5+
#include <scratchcpp/value.h>
56
#include <targetmock.h>
67
#include <enginemock.h>
78
#include <executablecodemock.h>
@@ -50,6 +51,13 @@ TEST_F(ThreadTest, Run)
5051
m_thread->run();
5152
}
5253

54+
TEST_F(ThreadTest, RunReporter)
55+
{
56+
Value v = "test";
57+
EXPECT_CALL(*m_code, runReporter(m_ctx.get())).WillOnce(Return(v.data()));
58+
ASSERT_EQ(Value(m_thread->runReporter()).toString(), v.toString());
59+
}
60+
5361
TEST_F(ThreadTest, RunPredicate)
5462
{
5563
ASSERT_FALSE(m_thread->runPredicate());

0 commit comments

Comments
 (0)