Parameters and Local Keywords
The passed in parameters and keyword values are accessed as attributes (properties) of the created Pike dynamic parameter object (__args in the above example). This preserves the variable names of the original IDL routine, while allowing Pike to manage output parameter values.
In IDL:
if(n_elements(kw1))then $
kw1 = kw1 + 1
if (pike.n_elements(__args.kw1)):
__args.kw1 = __args.kw1 + 1
_EXTRA Keyword Support
IDL supports dynamic keyword argument support using the special keyword name _EXTRA, which IDL maps to a structure where each field maps to an unhanded keyword passed in to the routine.
Pike provides the same functionality, creating a structure (a Pike library implementation of an IDL structure) where each unassigned keyword is mapped to a field, and assigning that structure to the local _EXTRA variable exposed as an attribute on the dynamic parameter object.
The following example, the keyword “cow” is used when calling the function t_keyword_extra.
In IDL:
function t_keyword_extra, cow, pig, _extra=_eE
if( _EE.coW ne cow)then $
return, 1
def t_keyword_extra(*args, **argk):
__args = pike.routineParameters(args, argk, parameters=['cow', 'pig'],
keywords={"_extra":"_eE"}, outparams=[], outkeys=[])
if (__args._eE.cow != __args.cow):
return __args.returnValues(1)
Return Values
As noted earlier, for Python, all output values from a function are returned as the value from a function. Python supports the ability to return multiple values from a function through the use of its builtin tuple data type.
For IDL, all routine parameters and keywords support output value functionality. As such, Pike must identify and add output values to the return statements of the Python implementation. Pike does this using the capabilities of the aforementioned dynamic argument object.
The Pike dynamic argument object implements a method that appends all output parameters to the return values of function. Written as part of the pikex translation output, this method, returnValues(), is passed in the original return value of a function, if one exists, where it appends all output values for the routine and returns a Python tuple value which is returned from the function.
The translated call to this function is written such to support multiple return values from the routine.
The following example shows how and IDL function with multiple output parameters:
In IDL:
function t_outargs_func, one, two, three, four, kwone=kw1, kwtwo=kw2
;; ... routine logic, with a return value of 0
return, 0
;; And the function is called like:
result = t_outargs_func(p1, p2, p3, p4, kwtwo=3)
def t_outargs_func(*args, **argk):
_args = pike.routineParameters(args, argk, parameters=['one', 'two', 'three', 'four'],
keywords={"kwone":"kw1", "kwtwo":"kw2"}, outparams=[2, 4],
outkeys=['kwone'])
# ... routine logic, with a return value of 0
return __args.returnValues(0)
# And the function is called like (note the multiple return values):
result, p2, p4 = t_outargs_func(p1, p2, p3, p4, kwtwo=3)
Inline Functions
In Python, if a function supports multiple return values, the functions output cannot be used as input to another routine or in a control statement. To manage this in the translation process, Pike will pull the function from it’s original use, assign the output value to a temporary variable, and use this temporary value as input.
In IDL:
if( t_outargs_func(kwtwo=44, kwone=key1) ne 1)then begin
__tmp0, key1 = t_outargs_func(kwone=key1, kwtwo=44)
if (__tmp0 != 1):