/* * This tests the example given in the documentation. */ void test() { struct SEE_interpreter interp_storage, *interp; struct SEE_input *input; SEE_try_context_t try_ctxt; struct SEE_value result; char *program_text = "Math.sqrt(3 + 4 * 7) + 9"; TEST_DESCRIBE("the simple example from the documentation"); /* Initialise the SEE library */ SEE_init(); /* Initialise an interpreter */ SEE_interpreter_init(&interp_storage); interp = &interp_storage; /* Create an input stream that provides program text */ input = SEE_input_utf8(interp, program_text); TEST_NOT_NULL(input); /* Establish an exception context */ SEE_TRY(interp, try_ctxt) { /* Call the program evaluator */ SEE_Global_eval(interp, input, &result); /* Print the result */ TEST(SEE_VALUE_GET_TYPE(&result) == SEE_NUMBER); if (SEE_VALUE_GET_TYPE(&result) == SEE_NUMBER) TEST_EQ_FLOAT(result.u.number, sqrt(3+4*7.)+9); }
static void SeeLogErrorObj(SEE_interpreter* interpr_, SEE_value* errorValue) { // is the value an object? if( errorValue==NULL || SEE_VALUE_GET_TYPE(errorValue) != SEE_OBJECT ) return; // is the object an array? SEE_object* errorObj = errorValue->u.object; if( errorObj == NULL ) return; // get what to get ... wxString errorName, errorMsg, tempStr; long lineno = -1; // ... get the error name SEE_value tempVal; SEE_OBJECT_GET(interpr_, errorObj, str_name, &tempVal); if( SEE_VALUE_GET_TYPE(&tempVal) == SEE_STRING ) errorName = SeeValueToWxString(interpr_, &tempVal); errorName.Trim(true); errorName.Trim(false); if( errorName.IsEmpty() ) errorName = wxT("Error"); // ... get the error message, this is formatted as "<string>:<lineno>:msg" SEE_OBJECT_GET(interpr_, errorObj, str_message, &tempVal); if( SEE_VALUE_GET_TYPE(&tempVal) == SEE_STRING ) { errorMsg = SeeValueToWxString(interpr_, &tempVal); if( errorMsg.Find(wxT(":")) >= 0 ) { tempStr = errorMsg.BeforeFirst(wxT(':')); errorMsg = errorMsg.AfterFirst(wxT(':')); } if( errorMsg.Find(wxT(":")) >= 0 ) { tempStr = errorMsg.BeforeFirst(wxT(':')); if( !tempStr.ToLong(&lineno, 10) ) lineno = -1; errorMsg = errorMsg.AfterFirst(wxT(':')); } errorMsg.Trim(true); errorMsg.Trim(false); } if( errorMsg.IsEmpty() ) errorMsg = wxT("Unknown error"); // ... get the line number if( lineno >= 1 ) tempStr.Printf(wxT("%i"), (int)lineno); else tempStr = wxT("?"); // ... format the line wxLogError(wxT("Line %s: %s: %s [%s]"), tempStr.c_str(), errorName.c_str(), errorMsg.c_str(), HOST_DATA->m_executionScope.c_str() ); // old stuff #if 0 { SEE_value errorObjAsStr; SEE_ToString(interpr_, errorValue, &errorObjAsStr); wxString error = ::SeeValueToWxString(interpr_, &errorObjAsStr); if( error.IsEmpty() ) error = wxT("Unknown error."); wxLogError(wxT("%s [%s]"), error.c_str(), HOST_DATA->m_executionScope.c_str()); } #endif }