mb_translate_reference |
![]() ![]() |
status_t mb_translate_reference( mb_interpreter_t* s, void** l, void* pReference, void** pValue, mb_data_e* type )
This will return the value and the type of the variable pointed to by the supplied reference. the type parameter will return the type and the pValue parameter will point to the value upon return. You need need to cast the pointer to the correct type depending on the returned type.
Example
///////////////////////////////////////////////////////////////////////////// // This will return the type pointed to by the reference param int _get_reference_type( mb_interpreter_t* s, void** l ) { // Parse Parameter BEGIN_PARSE( s, l ) POP_REFERENCE( ref ) END_PARSE
// Translate the Reference mb_value_e type; void* pValue;
mb_translate_reference( s, l, ref, &pValue, &type );
// Need a buffer to hold output from mb_make_value_t char buffer[256];
// Copy to output string that we can return COPY_STRING( pOutput, mb_value_e_to_string( type, buffer ) );
// Return the type as string RETURN_STRING( pOutput ); }
///////////////////////////////////////////////////////////////////////////// // This will return the value of a reference as mb_value_t int _get_reference_value( mb_interpreter_t* s, void** l ) { // Parse Parameter BEGIN_PARSE( s, l ) POP_REFERENCE( ref ) END_PARSE
// Translate the Reference mb_value_e type; void* pValue;
mb_translate_reference( s, l, ref, &pValue, &type );
// Need to create a mb_value_t return value mb_value_u uval; mb_value_t val;
switch ( type ) { case MB_DT_INT: uval.integer = *(int_t*)pValue; break; case MB_DT_REAL: uval.float_point = *(real_t*)pValue; break; case MB_DT_STRING: uval.string = *(char*)pValue; break; default: // This is always a pointer of some kind uval.pointer = *(void*)pValue; }
mb_make_value_t( &val, uval, type, NULL );
// Return the value RETURN_VALUE( val ); }
|