mb_set_inputer_ex |
status_t mb_set_inputer_ex( mb_interpreter_t* s, mb_input_func2_t pHandler )
Set the extended input handler. To remove the handler, supply NULL. This format uses the extended handler format.
typedef int (*mb_input_func2_t)( struct mb_interpreter_t* s, char* pBuffer, int nBufSize, const char* pVarName );
Example
///////////////////////////////////////////////////////////////////////////// // 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 );
mb_set_userdata( m_bas, this ); } endfunc
///////////////////////////////////////////////////////////////////////////// // int CMyBASIC2View::_check_keyboard( mb_interpreter_t* s, short int* pKey, short int break_key ) { CMyBASIC2View* pCurrentView = (CMyBASIC2View*)mb_get_userdata( s );
return MB2Console_OnCheckKeyboard( pKey, break_key, pCurrentView->GetSafeHwnd() ); } endfunc
///////////////////////////////////////////////////////////////////////////// // 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
///////////////////////////////////////////////////////////////////////////// // int CMyBASIC2View::_getstring( mb_interpreter_t* s, char* pStr, int nLen, const char* pVarName ) { CMyBASIC2View* pCurrentView = (CMyBASIC2View*)mb_get_userdata( s );
if ( pCurrentView->GetDocument()->GetRunMode() == eWindowsApp ) { return MB2Console_Input( pStr, nLen, pVarName, pCurrentView->GetSafeHwnd() ); } endif
return 0; } endfunc
///////////////////////////////////////////////////////////////////////////// // void CMyBASIC2View::_on_error( mb_interpreter_t* s, mb_error_e err, char* msg, WORD row, WORD col, int abort_code ) { CMyBASIC2View* pCurrentView = (CMyBASIC2View*)mb_get_userdata( s );
if ( pCurrentView ) { static ERRPARAMS errp;
errp.lpBas = s; errp.eErr = err; errp.lpszMsg = msg; errp.nRow = row; errp.nCol = col; errp.nAbortCode = abort_code;
// Need to use SendMessage instead of Post and Wait since we're (currently) // not running the basic script in a thread
CMB2Interface::GUICommand( pCurrentView, GUI_ERROR, (LPARAM)&errp, GUI_Q_SEND ); } endif } endfunc
|