File tree Expand file tree Collapse file tree 3 files changed +19
-1
lines changed
Expand file tree Collapse file tree 3 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -36,6 +36,7 @@ class LIBSCRATCHCPP_EXPORT Script
3636 void setLists (const std::vector<List *> &lists);
3737
3838 std::shared_ptr<VirtualMachine> start ();
39+ std::shared_ptr<VirtualMachine> start (Target *target);
3940
4041 private:
4142 spimpl::unique_impl_ptr<ScriptPrivate> impl;
Original file line number Diff line number Diff line change @@ -35,7 +35,13 @@ void Script::setBytecode(const std::vector<unsigned int> &code)
3535/* ! Starts the script (creates a virtual machine). */
3636std::shared_ptr<VirtualMachine> Script::start ()
3737{
38- auto vm = std::make_shared<VirtualMachine>(impl->target , impl->engine , this );
38+ return start (impl->target );
39+ }
40+
41+ /* ! Starts the script (creates a virtual machine). */
42+ std::shared_ptr<VirtualMachine> Script::start (Target *target)
43+ {
44+ auto vm = std::make_shared<VirtualMachine>(target, impl->engine , this );
3945 vm->setBytecode (impl->bytecode );
4046 vm->setProcedures (impl->procedures );
4147 vm->setFunctions (impl->functions );
Original file line number Diff line number Diff line change @@ -81,4 +81,15 @@ TEST_F(ScriptTest, Start)
8181 ASSERT_EQ (vm->constValues ()[0 ].toString (), constValues[0 ].toString ());
8282 ASSERT_EQ (vm->variables ()[0 ], variables[0 ]);
8383 ASSERT_EQ (vm->lists ()[0 ], lists[0 ]);
84+
85+ Target target;
86+ vm = script3.start (&target);
87+ ASSERT_TRUE (vm);
88+ ASSERT_EQ (vm->target (), &target);
89+ ASSERT_EQ (vm->bytecode ()[0 ], bytecode[0 ]);
90+ ASSERT_EQ (vm->procedures ()[0 ], procedures[0 ]);
91+ ASSERT_EQ (vm->functions ()[0 ], functions[0 ]);
92+ ASSERT_EQ (vm->constValues ()[0 ].toString (), constValues[0 ].toString ());
93+ ASSERT_EQ (vm->variables ()[0 ], variables[0 ]);
94+ ASSERT_EQ (vm->lists ()[0 ], lists[0 ]);
8495}
You can’t perform that action at this time.
0 commit comments