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



  • 10.  RE: Re: Spel to get array from function

    Posted 09-13-2019 02:01 PM

    Look this:

    void zSplit()
    {
    	send_wait(0, spell_object(),			// @|bop_cmd-#8184|doit|0|0
    		"zSplitString",		// method name
    		(string)NULL,		// class name (same as class() ?)
    		(string)NULL,		// event or macro name (same as event() ?)
    		(object)NULL,		// "this" pointer of type object
    		'NAME;ADDRESS;PHONE',	// String to split
    		';',			// String delimiter
    		'[aA0-zZ9]+'				// Regex parser
    		);
    
    	int zi_i;
    	for (zi_i=0;zi_i<msg_length();zi_i++) {
    		printf("#%d: '%s'\n", zi_i, (string) msg[zi_i]);
    	}
    }
    
    void zSplitString(...)
    {
    	string zs_str, zs_value, zs_delim, zs_regex;
    	zs_str = argv[0];
    	zs_delim = argv[1];
    	zs_regex = argv[2];
    	int zi_idx;
    	zi_idx = 0;
    	
    	int zi_idx_start, zi_idx_end;
    	zi_idx_start = sindex(zs_str, zs_regex, 0);
    	zi_idx_end = sindex(zs_str, zs_delim, zi_idx_start+1);
    	if (zi_idx_end == -1) zi_idx_end = strlen(zs_str);
    
    	do {
    		zs_value = substr(zs_str, zi_idx_start, zi_idx_end-zi_idx_start);
    		set_return_data(zi_idx++, zs_value);
    
    		zi_idx_start = sindex(zs_str, zs_regex, zi_idx_end+1);
    		zi_idx_end = sindex(zs_str, zs_delim, zi_idx_start+1);
    		if (zi_idx_end == -1) zi_idx_end = strlen(zs_str);
    	} while (zi_idx_start > -1);
    }
    
    Returns:
    #0: 'NAME'
    #1: 'ADDRESS'
    #2: 'PHONE'
    


    ------------------------------
    CA Service Desk Manager Especialist Developer
    PROCERGS
    ------------------------------