Пример #1
0
inline const MenuArgs AWE2STL(const awe_jsarray* awearr)
{
	MenuArgs args;
	const size_t alen = awe_jsarray_get_size( awearr );
	args.resize( alen );

	for( size_t i = 0; i < alen; ++i )
	{
		const awe_jsvalue* value = awe_jsarray_get_element( awearr, i );
		awe_jsvalue_type type = awe_jsvalue_get_type( value );
		switch ( type )
		{
		case JSVALUE_TYPE_NULL:
			args[i] = 0;
			break;
		case JSVALUE_TYPE_BOOLEAN:
			args[i] = awe_jsvalue_to_boolean( value );
			break;
		case JSVALUE_TYPE_INTEGER:
			{
				args[i] = awe_jsvalue_to_integer( value );
			}
			break;
		case JSVALUE_TYPE_DOUBLE:
			{
				args[i] = (float)awe_jsvalue_to_double( value );
			}
			break;
		case JSVALUE_TYPE_STRING:
			args[i] = AWE2STL( awe_jsvalue_to_string(value) );
			break;

		// Unsupported cases
		case JSVALUE_TYPE_OBJECT:
		case JSVALUE_TYPE_ARRAY:
			VCN_ASSERT_FAIL( VCNTXT("Not supported") );
			args[i] = 0;
			break;
		default:
			VCN_ASSERT_FAIL( VCNTXT("Not supported") );
			args[i] = 0;
			break;
		}
	}
	
	return args;
}
Пример #2
0
	void callback_UI(awe_webview *view, const awe_string  *object_name, const awe_string *callback_name, const awe_jsarray *args)
	{		
		char buff_object_name[BUFFER_LEN_CALLBACKS] = {0};
		char buff_callback_name[BUFFER_LEN_CALLBACKS] = {0};
		char buff_args[BUFFER_LEN_CALLBACKS] = {0};		
		const awe_jsvalue *temp = awe_jsarray_get_element(args,0);

		// Get the strings
		awe_string_to_utf8(object_name, buff_object_name, BUFFER_LEN_CALLBACKS);
		awe_string_to_utf8(callback_name, buff_callback_name, BUFFER_LEN_CALLBACKS);
		awe_string_to_utf8(awe_jsvalue_to_string(temp), buff_args, BUFFER_LEN_CALLBACKS);

		std::string s_obj_name(buff_object_name);
		std::string s_call_name(buff_callback_name);
		std::string s_args(buff_args);

		// Callback example: Javascript triggered this function -> chat.message("Test message") -> the output is the following:
		add_logA("Callback executed");
		add_logA((char*)s_obj_name.c_str());      // s_obj_name == name of the callback object ( chat )
		add_logA((char*)s_call_name.c_str());     // s_call_name == the function used by the callback object ( message )		
		add_logA((char*)s_args.c_str());		  // s_args == arguments given to the callback method ( Test message ) 
			
		// do whatever you like with the arguments ( s_args ) but check which GUI window triggered the callback by comparing s_obj_name with the object names defined while initializing the GUI
	}