File tree Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ void ListBlocks::registerBlocks(IEngine *engine)
24
24
{
25
25
engine->addCompileFunction (this , " data_addtolist" , &compileAddToList);
26
26
engine->addCompileFunction (this , " data_deleteoflist" , &compileDeleteOfList);
27
+ engine->addCompileFunction (this , " data_deletealloflist" , &compileDeleteAllOfList);
27
28
}
28
29
29
30
CompilerValue *ListBlocks::compileAddToList (Compiler *compiler)
@@ -91,3 +92,14 @@ CompilerValue *ListBlocks::compileDeleteOfList(Compiler *compiler)
91
92
92
93
return nullptr ;
93
94
}
95
+
96
+ CompilerValue *ListBlocks::compileDeleteAllOfList (Compiler *compiler)
97
+ {
98
+ auto list = compiler->field (" LIST" )->valuePtr ();
99
+ assert (list);
100
+
101
+ if (list)
102
+ compiler->createListClear (static_cast <List *>(list.get ()));
103
+
104
+ return nullptr ;
105
+ }
Original file line number Diff line number Diff line change @@ -133,3 +133,24 @@ TEST_F(ListBlocksTest, DeleteOfList)
133
133
ASSERT_EQ (list2->toString (), " Hello false abc" );
134
134
ASSERT_TRUE (list3->empty ());
135
135
}
136
+
137
+ TEST_F (ListBlocksTest, DeleteAllOfList)
138
+ {
139
+ auto target = std::make_shared<Sprite>();
140
+
141
+ auto list = std::make_shared<List>(" " , " " );
142
+ list->append (" Lorem" );
143
+ list->append (" ipsum" );
144
+ list->append (" dolor" );
145
+ list->append (123 );
146
+ list->append (true );
147
+ target->addList (list);
148
+
149
+ ScriptBuilder builder (m_extension.get (), m_engine, target);
150
+ builder.addBlock (" data_deletealloflist" );
151
+ builder.addEntityField (" LIST" , list);
152
+ builder.build ();
153
+
154
+ builder.run ();
155
+ ASSERT_TRUE (list->empty ());
156
+ }
You can’t perform that action at this time.
0 commit comments