Re: eGui idea: Iup Pre-Installed with Euphoria

new topic     » goto parent     » topic index » view thread      » older message » newer message

if IupGetParam was redesigned as here, it would be more accessible to beginners.

public function IupGetParam(object title = NULL, atom action, atom user_data, sequence fields, sequence default, atom param_extra=0) 
  sequence params = {} 
  sequence empty = repeat( 0, 255 )   -- an empty string to pad memory  
 
  if sequence(title) then title = allocate_string(title) end if 
  if not length(fields) then return 0 end if 
  atom format = allocate_string(stdseq:join(fields, "\n")) 
  atom param_count = length(fields) 
  sequence param_data = {} 
  for i = 1 to param_count do 
    if match("%s", fields[i]) then 
      param_data = append(param_data, allocate_string( empty, 1 )) 
      poke( param_data[$], default[i] )  
    elsif match("%o", fields[i]) then 
      param_data = append(param_data, allocate_data( 4, 1 )) 
      poke4( param_data[$], default[i] )  
    elsif match("%i", fields[i]) then 
      param_data = append(param_data, allocate_data( 4, 1 )) 
      poke4( param_data[$], default[i] )  
    end if 
  end for 
  atom p_param_data = allocate_pointer_array(param_data) 
  atom result = c_func( xIupGetParam, {title,action,user_data,format,param_count,param_extra,p_param_data} ) 
  free(p_param_data) 
  if result = 0 then return 0 end if  
  for i = 1 to param_count do 
    if match("%s", fields[i]) then 
      params = append(params, peek_string( param_data[i] )) 
    elsif match("%o", fields[i]) then 
      params = append(params, peek4u( param_data[i] )) 
    elsif match("%i", fields[i]) then 
      params = append(params, peek4u( param_data[i] )) 
    end if 
  end for 
  return params 
end function 

Example of use (tested)

  sequence greetings = { "Hello", "Goodbye", "What's Up?", "Cya" } 
 
  object result = IupGetParam( "Say Hello", NULL, NULL,  
    {  
      "Greeting: %o|Hello|Goodbye|What's Up?|Cya|",  
      "Name: %s",  
      "Times: %i"  
    }, 
    {0, "Text", 5} 
  )  
 
  if sequence(result) then 
    atom num = result[1] 
    sequence text  = result[2]  
    atom nb = result[3] 
    for i = 1 to nb do 
      printf(1, "%s, %s!\n", { greetings[num + 1], text }) 
    end for 
  end if 
new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu