Clarity Service Management

Expand all | Collapse all

Spel to get array from function

Jump to Best Answer
  • 1.  Spel to get array from function

    Posted 09-01-2015 04:34 AM

    Hi,

    I would like to call spel function from another spel function. Called function should return array of strings. Maybe someone is aware how to do this?



  • 2.  Re: Spel to get array from function

    Posted 09-01-2015 07:32 AM

    Hi,

    when you return array from function, only first string passed (arr[0]).

    This might sounds strange but I have tried to reach the same this morning,

    I'll give more info if I find something useful.

    Regards



  • 3.  Re: Spel to get array from function

    Posted 09-01-2015 07:55 AM

    Construction like this didnt work:

    string func(...) {

    string arr[2];

    retunr arr;

    }

     

    printf(func[1]);

    anyway if it will work you need to know length of array or you'll get an overbounds error,

    so this method have more questions than answers.

     

    I think that there is a chance to get correct values using msg array.

    Do you know how to call custom function via send_wait?



  • 4.  Re: Spel to get array from function
    Best Answer

    Posted 09-01-2015 08:05 AM

    I have found the solution, I have defined method on my change object then I call this method:

     

    object new_obj;  
    send_wait(0, top_object(), "call_attr", "chg", "dob_by_persid", 0, "chg:400055");  
    new_obj = msg[0];  
    int j; 
    
    send_wait(0, new_obj, "mymethod");  
     for (j=0;j<msg_length();j++) {  
     printf("child[%d]: '%s'", j, msg[j]);  
      } 
    

     

    in mymethod I return information in the following way:

     

    for (j=0;j<chg_count;j++) { 
        set_return_data(j,msg[j]);
      }
    


  • 5.  Re: Spel to get array from function

    Posted 09-01-2015 08:23 AM

    hmm, nice!

    I've got stuck on this:

    send_wait(0, this, "test_arr"); // have tried to place group_leader or top_object instead of this.
    
    

    Where "this" was a current chg object and method was "chg::test_arr".

     

    Update:

    Method become valid after I've declared it in mod file:

    OBJECT chg {   METHODS {   test_arr( ... );   }; };


  • 6.  Re: Spel to get array from function

    Posted 09-01-2015 09:59 AM

    Yes the only way I found is declare method on some object, it would be nice to know how to define it on top_object



  • 7.  Re: Spel to get array from function

    Posted 02-18-2017 01:03 AM

    Hi guys,

    cdtj, Gutis, giedrius,

     

    I found a way to declare and create a object in top_object.

    void z_myMethod()
    {
        object zo_obj;
        zo_obj = z_createObject();
        
        printf("Object: '%s'\n", (string) zo_obj);
        printf("# '%s'\n", zo_obj.attr1);
        printf("# '%s'\n", zo_obj.attr2);
    }

     

    object z_createObject(...)
    {
        send_wait(0, this, "call_attr", 'attr1', "set_val", 'test1');
        send_wait(0, this, "call_attr", 'attr2', "set_val", 'test2');
        return this;
    }

    Have fun.



  • 8.  Re: Spel to get array from function

    Posted 09-01-2015 09:17 AM

    How did you know that set_return_data have multiple arguments?



  • 9.  Re: Spel to get array from function

    Posted 09-01-2015 09:58 AM

    I would say intuition