Beispiel #1
0
/*
 * 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);
	}
Beispiel #2
0
int
cgiMain()
{ 
	cgiHeaderContentType("text/html");
	
	int serverside = 0;
	cgiFormInteger("serverside", &serverside, 0);
	
	char function_call[50];
	int callback = 0;
	if (cgiFormString("function_call", &function_call[0], 50) == cgiFormSuccess)
		callback = 1;
	
	if(serverside) {
		/* Initialise the SEE library */
		SEE_init();
		
		/* Initialise an interpreter */
		SEE_interpreter_init(&g_interp_storage);
		g_interp = &g_interp_storage;
	
		/* Bring our native functions into the interpreter */
		SEE_CFUNCTION_PUTA(g_interp, g_interp->Global, "println", g_println, 1, 0);
		SEE_CFUNCTION_PUTA(g_interp, g_interp->Global, "include", g_include, 1, 0);
		SEE_CFUNCTION_PUTA(g_interp, g_interp->Global, "version", g_version, 1, 0);
		
		/* evaluate bootstrapping code, and then script, then transform events */
		evaluate_file(g_interp, &g_result, "/Users/alan/working/golf/boot/serverside.js");
		evaluate_file(g_interp, &g_result, cgiPathTranslated);
		
		/* this is dangerous lol.  should check to make sure the callback is a function */
		if(callback)
			evaluate_string(g_interp, &g_result, function_call);
		
		/* this converts elements with onclick event attributes into links */
		evaluate_file(g_interp, &g_result, "/Users/alan/working/golf/boot/transform.js");
		evaluate_string(g_interp, &g_result, "document.render();");
		
	} else {
		
		fprintf(cgiOut, "<html>\n<head>\n");
		fprintf(cgiOut, "<script type = \"text/javascript\">\n");
		fprintf(cgiOut, "function boot() {\n");
		print_file("/Users/alan/working/golf/boot/clientside.js");
		print_file(cgiPathTranslated);
		fprintf(cgiOut, "\n}\n");
		fprintf(cgiOut, "</script>\n</head>\n");
		fprintf(cgiOut, "<body onload = \"boot();\">\n");
		fprintf(cgiOut, "</body>\n</html>");
		
	}
	
	return EXIT_SUCCESS;
}
Beispiel #3
0
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);
	}