Explorar o código

ncd: NCDModule: add NCDModuleProcess_SetNoArgs()

ambrop7 %!s(int64=13) %!d(string=hai) anos
pai
achega
dd1df990c6
Modificáronse 2 ficheiros con 32 adicións e 10 borrados
  1. 22 10
      ncd/NCDModule.c
  2. 10 0
      ncd/NCDModule.h

+ 22 - 10
ncd/NCDModule.c

@@ -510,6 +510,9 @@ int NCDModuleProcess_Init (NCDModuleProcess *o, NCDModuleInst *n, const char *te
     // set state
     o->state = PROCESS_STATE_INIT;
     
+    // set not no args
+    o->no_args = 0;
+    
     // clear interp functions so we can assert they were set
     o->interp_func_event = NULL;
     o->interp_func_getobj = NULL;
@@ -558,6 +561,13 @@ void NCDModuleProcess_SetSpecialFuncs (NCDModuleProcess *o, NCDModuleProcess_fun
     o->func_getspecialobj = func_getspecialobj;
 }
 
+void NCDModuleProcess_SetNoArgs (NCDModuleProcess *o)
+{
+    DebugObject_Access(&o->d_obj);
+    
+    o->no_args = 1;
+}
+
 void NCDModuleProcess_Continue (NCDModuleProcess *o)
 {
     DebugObject_Access(&o->d_obj);
@@ -669,16 +679,18 @@ int NCDModuleProcess_Interp_GetSpecialObj (NCDModuleProcess *o, const char *name
     ASSERT(name)
     ASSERT(out_object)
     
-    if (!strcmp(name, "_args")) {
-        *out_object = NCDObject_Build(NULL, o, (NCDObject_func_getvar)process_args_object_func_getvar, NULL);
-        return 1;
-    }
-    
-    size_t len;
-    uintmax_t n;
-    if ((len = string_begins_with(name, "_arg")) && parse_unsigned_integer(name + len, &n) && n < NCDValue_ListCount(&o->args)) {
-        *out_object = NCDObject_Build2(NULL, o, NCDValue_ListGet(&o->args, n), (NCDObject_func_getvar2)process_arg_object_func_getvar2, NULL);
-        return 1;
+    if (!o->no_args) {
+        if (!strcmp(name, "_args")) {
+            *out_object = NCDObject_Build(NULL, o, (NCDObject_func_getvar)process_args_object_func_getvar, NULL);
+            return 1;
+        }
+        
+        size_t len;
+        uintmax_t n;
+        if ((len = string_begins_with(name, "_arg")) && parse_unsigned_integer(name + len, &n) && n < NCDValue_ListCount(&o->args)) {
+            *out_object = NCDObject_Build2(NULL, o, NCDValue_ListGet(&o->args, n), (NCDObject_func_getvar2)process_arg_object_func_getvar2, NULL);
+            return 1;
+        }
     }
     
     if (!o->func_getspecialobj) {

+ 10 - 0
ncd/NCDModule.h

@@ -317,6 +317,7 @@ typedef struct NCDModuleProcess_s {
     NCDModuleProcess_func_getspecialobj func_getspecialobj;
     BPending event_job;
     int state;
+    int no_args;
     void *interp_user;
     NCDModuleProcess_interp_func_event interp_func_event;
     NCDModuleProcess_interp_func_getobj interp_func_getobj;
@@ -531,6 +532,15 @@ void NCDModuleProcess_AssertFree (NCDModuleProcess *o);
  */
 void NCDModuleProcess_SetSpecialFuncs (NCDModuleProcess *o, NCDModuleProcess_func_getspecialobj func_getspecialobj);
 
+/**
+ * Makes the process itself not resolve the _args and _argN special objects.
+ * After calling this, the only special objects the interpreter can resolve
+ * are those provided by the creator of the process via {@link NCDModuleProcess_SetSpecialFuncs}.
+ * 
+ * @param o the process
+ */
+void NCDModuleProcess_SetNoArgs (NCDModuleProcess *o);
+
 /**
  * Continues the process after the process went down.
  * The process must be in waiting state.