summaryrefslogtreecommitdiff
path: root/sourcemod/scripting/include/GlobalAPI/iterable.inc
diff options
context:
space:
mode:
authornavewindre <nw@moneybot.cc>2023-12-04 18:06:10 +0100
committernavewindre <nw@moneybot.cc>2023-12-04 18:06:10 +0100
commitaef0d1c1268ab7d4bc18996c9c6b4da16a40aadc (patch)
tree43e766b51704f4ab8b383583bdc1871eeeb9c698 /sourcemod/scripting/include/GlobalAPI/iterable.inc
parent38f1140c11724da05a23a10385061200b907cf6e (diff)
bbbbbbbbwaaaaaaaaaaa
Diffstat (limited to 'sourcemod/scripting/include/GlobalAPI/iterable.inc')
-rw-r--r--sourcemod/scripting/include/GlobalAPI/iterable.inc55
1 files changed, 55 insertions, 0 deletions
diff --git a/sourcemod/scripting/include/GlobalAPI/iterable.inc b/sourcemod/scripting/include/GlobalAPI/iterable.inc
new file mode 100644
index 0000000..585873b
--- /dev/null
+++ b/sourcemod/scripting/include/GlobalAPI/iterable.inc
@@ -0,0 +1,55 @@
+// ================== DOUBLE INCLUDE ========================= //
+
+#if defined _GlobalAPI_Iterable_included_
+#endinput
+#endif
+#define _GlobalAPI_Iterable_included_
+
+// =========================================================== //
+
+#include <json>
+
+// =========================================================== //
+
+/*
+ Helper methodmap for JSON_Object arrays
+*/
+methodmap APIIterable < JSON_Object
+{
+ /**
+ * Creates a new APIIterable
+ *
+ * @param hItems JSON_Object array handle
+ * @return A new APIIterable handle
+ */
+ public APIIterable(JSON_Object hItems)
+ {
+ if (hItems.HasKey("result"))
+ {
+ return view_as<APIIterable>(hItems.GetObject("result"));
+ }
+ return view_as<APIIterable>(hItems);
+ }
+
+ /*
+ Gets count of the items in the array
+ */
+ property int Count
+ {
+ public get() { return this.Length; }
+ }
+
+ /**
+ * Gets an object from the array by index
+ *
+ * @note This is an alias to GetObjectIndexed
+ * @param index Index of the object we want to retrieve
+ * @return JSON_Object handle to the object retrieved
+ */
+ public JSON_Object GetById(int index)
+ {
+ return this.GetObjectIndexed(index);
+ }
+}
+
+// =========================================================== // \ No newline at end of file