/* * 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); }
void evaluate( struct SEE_interpreter *interp, struct SEE_value *res, struct SEE_input *input) { SEE_try_context_t try_ctxt; /* Establish an exception context */ SEE_TRY(interp, try_ctxt) { /* Call the program evaluator */ SEE_Global_eval(interp, input, res); }
bool SjSee::Execute(const wxString& script__) { wxASSERT( !m_executionScope.IsEmpty() ); // very first, do some garbarge collection (if needed) // this must be done _before_ we create SjGcLocker /*if( SjGcNeedsCleanup() ) { SjGcCleanup(); -- done in SjGcLocker }*/ // lock the garbage collector SjGcLocker gclocker; // init the interpreter, if not yet done if( !m_interprInitialized ) { // init some global function pointers static bool SEE_system_initialized = false; if( !SEE_system_initialized ) { SEE_system.abort = SjSee_abort; SEE_system.malloc = SjSee_malloc; SEE_system.malloc_string = SjSee_malloc_string; SEE_system.malloc_finalize = SjSee_malloc_finalize; SEE_system.free = SjSee_free; SEE_system_initialized = true; SEE_system_add_my_strings (); } // init the interpreter instance and our objects SEE_interpreter_init(m_interpr); Player_init(); Program_init(); Rights_init(); Dialog_init(); Database_init(); File_init(); HttpRequest_init(); m_interprInitialized = true; } // do what to do bool success = true; SEE_input* input; SEE_try_context_t tryContext; /* Create an input stream that provides program text */ { wxString script(script__); if( script.Find(wxT("\r")) != -1 ) // no "\r" - otherwise, the line numbers get out of order { if( script.Find(wxT("\n")) != -1 ) script.Replace(wxT("\r"), wxT(" ")); else script.Replace(wxT("\r"), wxT("\n")); } input = SEE_input_string(m_interpr, WxStringToSeeString(m_interpr, script)); } /* Establish an exception context */ SEE_TRY(m_interpr, tryContext) { /* Call the program evaluator */ SEE_Global_eval(m_interpr, input, m_executeResult); }