reading the value of a parameter from within a C++ external function.
XPE parameters are passed to external C++ functions tagged in such a way that the external function can easily determin the type of the parameter that was passed.
The tag contains information indicating wheather or not the parameter is passed by reference or by value and if by value what the type of the value is.
The overhead is actually quite small and in reality is no greater than that of a highly optimised system which translates the actual parameters supplied, to the types required by the called function. In XPE the conversion is postponed until after the external function has been called.
There are two fundamental ways to do a translation
- either you can check to see what the current type of the value is and call a translation function to convert from that type to the type that you actually want
- or you can simply call a function that will always return the type of value that you want.
The advantage of the first case is that sometimes you will not need to do a translation, but you will always have to add the code to do the check and possible translation.
The advantage of the second case is that it is simpler and far less prone to error with only a very small overhead.
- simple access to XPE parameters
- as an integer
- as a float
- as a string
- access to XPE parameter depending on type
- copying the value of a parameter without knowing the type
- to XPE variable
- to XPE value
simple access to XPE parameters
given the standard external C++ function interface
XPE::TOKEN ext_func( XPE::SREF xpe_this, int cnt, XPE::TOKEN arr[] )
access to XPE parameter depending on type
given the standard external C++ function interface
XPE::TOKEN ext_func( XPE::SREF xpe_this, int cnt, XPE::TOKEN arr[] )int xint; float xfloat; const char *xstr; switch (arr[0].get_type()) { case XPE::VALUE_INT: // using parameter 0 as an integer xint = arr[0].get_int(); printf("arg0 is an int (%d)\n", xint); break; case XPE::VALUE_FLOAT: // using parameter 0 as a float xfloat = arr[0].get_float(); printf("arg0 is a float (%f)\n", xfloat) break; case XPE::VALUE_STR: // using parameter 0 as a string xstr = arr[0].get_str(); printf("arg0 is a string (%s)\n", xstr); break; default: // do nothing printf("arg0 is of type %d\n", arr[0].get_type()); }
copying the value of a parameter without knowing the type.
given the standard external C++ function interface
XPE::TOKEN ext_func( XPE::SREF xpe_this, int cnt, XPE::TOKEN arr[] )discuss returning value via parameter passed by reference.