mb_get_userdata |
void* mb_get_userdata( mb_interpreter_t* s )
The interpreter structure has a void* user value reserved to be used by the user for any purpose. This can be a pointer to a data structure on any other value that the user assigns to it. To retrieve this, use mb_get_userdata. This is normally used to exchange data such as pointer to classes etc. between the calling code and callbacks such as error and I/O handlers.
Example
///////////////////////////////////////////////////////////////////////////// // Simple PRINT handler that uses AfxMessageBox to output the supplied strings // int CMyBASIC2View::_printstring( mb_interpreter_t* s, const char* pStr, ... ) { char pBuffer[2048];
va_list params;
va_start( params, pStr ); sprintf( pBuffer, pStr, va_arg( params, void* ) ); va_end( params );
CMyBASIC2View* pCurrentView = (CMyBASIC2View*)mb_get_userdata( s );
if ( pCurrentView && ( pCurrentView->GetDocument()->GetRunMode() == eWindowsApp ) ) { AfxMessageBox( pBuffer ); } endif
return strlen( pStr ); } endfunc
///////////////////////////////////////////////////////////////////////////// // Constructor // CMyBASIC2View::CMyBASIC2View() { m_bas = NULL;
// Init My Basic Interpreter
mb_init(); mb_open( &m_bas );
// Setup callback handlers
mb_set_error_handler( m_bas, CMyBASIC2View::_on_error ); mb_set_inputer_ex( m_bas, CMyBASIC2View::_getstring ); mb_set_printer_ex( m_bas, CMyBASIC2View::_printstring ); mb_set_check_keyboard_handler_ex( m_bas, CMyBASIC2View::_check_keyboard );
// Set userdata to point to this class
mb_set_userdata( m_bas, this ); } endfunc
|