Skip to content

Commit c6d4834

Browse files
committed
Implement operator_multiply
1 parent 30c4d12 commit c6d4834

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/dev/blocks/operatorblocks.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ void OperatorBlocks::registerBlocks(IEngine *engine)
2121
{
2222
engine->addCompileFunction(this, "operator_add", &compileAdd);
2323
engine->addCompileFunction(this, "operator_subtract", &compileSubtract);
24+
engine->addCompileFunction(this, "operator_multiply", &compileMultiply);
2425
}
2526

2627
CompilerValue *OperatorBlocks::compileAdd(Compiler *compiler)
@@ -32,3 +33,8 @@ CompilerValue *OperatorBlocks::compileSubtract(Compiler *compiler)
3233
{
3334
return compiler->createSub(compiler->addInput("NUM1"), compiler->addInput("NUM2"));
3435
}
36+
37+
CompilerValue *OperatorBlocks::compileMultiply(Compiler *compiler)
38+
{
39+
return compiler->createMul(compiler->addInput("NUM1"), compiler->addInput("NUM2"));
40+
}

test/dev/blocks/operator_blocks_test.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,22 @@ TEST_F(OperatorBlocksTest, Subtract)
6464
ASSERT_EQ(valueList->size(), 1);
6565
ASSERT_EQ(Value(values[0]), 3.2);
6666
}
67+
68+
TEST_F(OperatorBlocksTest, Multiply)
69+
{
70+
auto target = std::make_shared<Sprite>();
71+
ScriptBuilder builder(m_extension.get(), m_engine, target);
72+
73+
builder.addBlock("operator_multiply");
74+
builder.addValueInput("NUM1", 5.7);
75+
builder.addValueInput("NUM2", 2.5);
76+
builder.captureBlockReturnValue();
77+
78+
builder.build();
79+
builder.run();
80+
81+
List *valueList = builder.capturedValues();
82+
ValueData *values = valueList->data();
83+
ASSERT_EQ(valueList->size(), 1);
84+
ASSERT_EQ(Value(values[0]), 14.25);
85+
}

0 commit comments

Comments
 (0)