17 void SetMethods::registerConstants(
MinitScript* minitScript) {
33 minitScript(minitScript) {}
34 const string getMethodName()
override {
38 if (arguments.size() == 0) {
39 returnValue.
setType(MinitScript::TYPE_SET);
56 { .type = MinitScript::TYPE_SET, .name =
"set", .optional =
false, .reference =
false, .nullable =
false }
58 MinitScript::TYPE_INTEGER
60 minitScript(minitScript) {}
61 const string getMethodName()
override {
62 return "Set::getSize";
65 if (arguments.size() == 1 &&
66 arguments[0].getType() == MinitScript::TYPE_SET) {
67 returnValue.
setValue(
static_cast<int64_t
>(arguments[0].getSetSize()));
84 { .type = MinitScript::TYPE_SET, .name =
"set", .optional =
false, .reference =
false, .nullable =
false }
86 MinitScript::TYPE_BOOLEAN
88 minitScript(minitScript) {}
89 const string getMethodName()
override {
90 return "Set::isEmpty";
93 if (arguments.size() == 1 &&
94 arguments[0].getType() != MinitScript::TYPE_SET) {
95 returnValue.
setValue(arguments[0].getSetSize() == 0);
112 { .type = MinitScript::TYPE_SET, .name =
"set", .optional =
false, .reference =
true, .nullable =
false },
113 { .type = MinitScript::TYPE_STRING, .name =
"key", .optional =
false, .reference =
false, .nullable =
false }
115 MinitScript::TYPE_NULL
117 minitScript(minitScript) {}
118 const string getMethodName()
override {
119 return "Set::insert";
123 if (arguments.size() == 2 &&
124 arguments[0].getType() == MinitScript::TYPE_SET &&
125 MinitScript::getStringValue(arguments, 1, key) ==
true) {
126 arguments[0].insertSetKey(key);
143 { .type = MinitScript::TYPE_SET, .name =
"set", .optional =
false, .reference =
false, .nullable =
false },
144 { .type = MinitScript::TYPE_STRING, .name =
"key", .optional =
false, .reference =
false, .nullable =
false }
146 MinitScript::TYPE_BOOLEAN
148 minitScript(minitScript) {}
149 const string getMethodName()
override {
150 return "Set::contains";
154 if (arguments.size() == 2 &&
155 arguments[0].getType() == MinitScript::TYPE_SET &&
156 MinitScript::getStringValue(arguments, 1, key) ==
true) {
157 returnValue.
setValue(arguments[0].hasSetKey(key));
174 { .type = MinitScript::TYPE_SET, .name =
"set", .optional =
false, .reference =
true, .nullable =
false },
175 { .type = MinitScript::TYPE_STRING, .name =
"key", .optional =
false, .reference =
false, .nullable =
false }
177 MinitScript::TYPE_NULL
179 minitScript(minitScript) {}
180 const string getMethodName()
override {
181 return "Set::remove";
185 if (arguments.size() == 2 &&
186 arguments[0].getType() == MinitScript::TYPE_SET &&
187 MinitScript::getStringValue(arguments, 1, key) ==
true) {
188 arguments[0].removeSetKey(key);
205 { .type = MinitScript::TYPE_SET, .name =
"set", .optional =
false, .reference =
false, .nullable =
false },
207 MinitScript::TYPE_ARRAY
209 minitScript(minitScript) {}
210 const string getMethodName()
override {
211 return "Set::getKeys";
215 if (arguments.size() == 1 &&
216 arguments[0].getType() == MinitScript::TYPE_SET) {
217 auto keys = arguments[0].getSetKeys();
218 returnValue.
setType(MinitScript::TYPE_ARRAY);
219 for (
const auto& key: keys) {
238 { .type = MinitScript::TYPE_SET, .name =
"set", .optional =
false, .reference =
true, .nullable =
false }
240 MinitScript::TYPE_NULL
242 minitScript(minitScript) {}
243 const string getMethodName()
override {
247 if (arguments.size() == 1 &&
248 arguments[0].getType() == MinitScript::TYPE_SET) {
249 arguments[0].clearSet();
266 { .type = MinitScript::TYPE_SET, .name =
"set", .optional =
false, .reference =
false, .nullable =
false },
267 { .type = MinitScript::TYPE_FUNCTION_ASSIGNMENT, .name =
"callbackFunction", .optional =
false, .reference =
false, .nullable =
false },
268 { .type = MinitScript::TYPE_PSEUDO_MIXED, .name =
"cookie", .optional =
true, .reference =
true, .nullable =
false }
270 MinitScript::TYPE_NULL
272 minitScript(minitScript) {}
273 const string getMethodName()
override {
274 return "Set::forEach";
277 string callbackFunction;
278 int callbackFunctionScriptIdx;
279 if ((arguments.size() == 2 || arguments.size() == 3) &&
280 arguments[0].getType() == MinitScript::TYPE_SET &&
281 MinitScript::getFunctionValue(arguments, 1, callbackFunction, callbackFunctionScriptIdx) ==
true) {
282 auto setPtr = arguments[0].getSetPointer();
283 if (setPtr !=
nullptr) {
284 if (callbackFunction.empty() ==
false && callbackFunctionScriptIdx == MinitScript::SCRIPTIDX_NONE) {
287 if (callbackFunctionScriptIdx == MinitScript::SCRIPTIDX_NONE) {
290 for (
auto setEntry: *setPtr) {
292 if (arguments.size() == 3) functionArguments.push_back(arguments[2]);
293 span functionArgumentsSpan(functionArguments);
295 minitScript->
call(callbackFunctionScriptIdx, functionArgumentsSpan, functionReturnValue);
299 if (result ==
true)
break;
#define MINITSCRIPT_METHODUSAGE_COMPLAINM(methodName, message)
#define MINITSCRIPT_METHODUSAGE_COMPLAIN(methodName)
void pushArrayEntry(const Variable &value)
Push entry to array.
bool getBooleanValue(bool &value, bool optional=false) const
Get boolean value from given variable.
void setType(VariableType newType)
Set type.
void setValue(const Variable &variable)
Set value from given variable into variable.
void registerMethod(Method *method)
Register method.
int getFunctionScriptIdx(const string &function)
Return function script index by function name.
bool call(int scriptIdx, span< Variable > &arguments, Variable &returnValue, bool pushScriptState)
Call function.
MinitScript script set methods.