ソースを参照

ncd: modules: list: get length variable

ambrop7 14 年 前
コミット
9b9ce297d2
1 ファイル変更14 行追加0 行削除
  1. 14 0
      ncd/modules/list.c

+ 14 - 0
ncd/modules/list.c

@@ -34,6 +34,7 @@
  * 
  * Variables:
  *   (empty) - list containing elem1, ..., elemN
+ *   length - number of elements in list
  * 
  * Synopsis: list::append(arg)
  * 
@@ -43,6 +44,7 @@
  * Synopsis: list::length()
  * Variables:
  *   (empty) - number of elements in list at the time of initialization
+ *             of this method
  * 
  * Synopsis: list::get(string index)
  * Variables:
@@ -207,6 +209,18 @@ static int func_getvar (void *vo, const char *name, NCDValue *out)
         return 1;
     }
     
+    if (!strcmp(name, "length")) {
+        char str[50];
+        snprintf(str, sizeof(str), "%"PRIuMAX, (uintmax_t)NCDValue_ListCount(&o->list));
+        
+        if (!NCDValue_InitString(out, str)) {
+            ModuleLog(o->i, BLOG_ERROR, "NCDValue_InitString failed");
+            return 0;
+        }
+        
+        return 1;
+    }
+    
     return 0;
 }