1. Euphoria 3.1 internals

Im playing with old euphoria 3.1 from RDS.
Was wondering:
Why in this version we cant initialize a variable in declaration? Its a parser issue or style enforcement?
Why i cant subscript expressions and return values? Is this a virtual machine issue? (this seems to be true with Eu 4 too)

new topic     » topic index » view message » categorize

2. Re: Euphoria 3.1 internals

There is no need to add something like this.

Fabio Ramirez showed the way to get the job done in his Wrapper for Wininet (2004).

Pass options that need default values as a sequence of pairs {name, value}. Define default values in the called routine.

Example:

function ParameterValue( sequence Keyword, object Default, sequence CommandString  ) 
  for i = 1 to length( CommandString ) do 
    -- if the parameter is in CommandString 
    if equal( Keyword, CommandString[i][P_INDEX] ) then 
      return CommandString[i][P_VALUE] 
    end if 
  end for 
  return Default  
end function 
 
global function HttpSendRequest( sequence options) 
  atom hRequest, ptrHeaders, ptrOptional 
  integer result, lgHeaders, lgOptional 
 
  hRequest = ParameterValue("request_id", NULL, options) 
  if hRequest = NULL  then 
    net_set_error_vars({0, "EInetlib: Need a request_id handle"}) 
    return FALSE 
  end if 
 
  ptrHeaders = NULL 
  Parameter = ParameterValue("headers", NULL, options) 
  if sequence(Parameter) then 
    ptrHeaders = allocate_string( Parameter ) 
  end if 
... 
 

Parameter hRequest has no default value. Parameter ptrHeaders has default value NULL.

Function is called this way:

ok = HttpSendRequest({ 
          {"request_id", pRequest}, 
          {"headers", NULL}, 
          {"headers_length", 0}, 
          {"optional"  , AData}, 
          {"optional_length", length(AData)} 
        }) 

You don't need to pass all the parameters this way. Only the last ones which need a default value. This way you can also pass optional parameters referred as "..." in C.

Jean-Marc

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu