/// Convert an AS object to an XML string. std::string ExternalInterface::_toXML(const as_value &val) { // GNASH_REPORT_FUNCTION; std::stringstream ss; if (val.is_string()) { ss << "<string>" << val.to_string() << "</string>"; } else if (val.is_number()) { ss << "<number>" << val.to_string() << "</number>"; } else if (val.is_undefined()) { ss << "<void/>"; } else if (val.is_null()) { ss << "<null/>"; // Exception isn't listed in any docs, but we'll use it for // marshallExceptions. } else if (val.is_exception()) { ss << "<exception>" << val.to_string()<< "</exception>"; } else if (val.is_bool()) { ss << (val.to_bool(8) ? "<true/>" : "<false/>"); // Function also isn't listed, but it's the only other type // supported by as_value, so leaving it out doesn't seem right. } else if (val.is_function()) { ss << "<function>" << val.to_string() << "</function>"; } else if (val.is_object()) { as_object *obj = val.get_object(); ss << _objectToXML(obj); } else { log_error(_("Can't convert unknown type %d"), val.to_string()); } return ss.str(); }
void as_environment::set_variable ( const tu_string &varname, const as_value &val, const array<with_stack_entry>& with_stack ) // Given a path to variable, set its value. { IF_VERBOSE_ACTION ( log_msg ( "-------------- %s = %s\n", varname.c_str(), val.to_string() ) ); //xxxxxxxxxx // Path lookup rigamarole. character *target = get_target(); tu_string path; tu_string var; if ( parse_path ( varname, &path, &var ) ) { target = cast_to<character> ( find_target ( path.c_str() ) ); if ( target ) { target->set_member ( var, val ); } } else { set_variable_raw ( varname, val, with_stack ); } }
void as_environment::set_variable_raw ( const tu_string &varname, const as_value &val, const array<with_stack_entry>& with_stack ) // No path rigamarole. { // Check the with-stack. for ( int i = with_stack.size() - 1; i >= 0; i-- ) { as_object *obj = with_stack[i].m_object.get_ptr(); as_value unused; if ( obj && obj->get_member ( varname, &unused ) ) { // This object has the member; so set it here. obj->set_member ( varname, val ); return; } } // Check locals. int local_index = find_local ( varname, true ); if ( local_index >= 0 ) { // Set local var. m_local_frames[local_index].m_value = val; return; } if ( m_target != NULL ) { m_target->set_member ( varname, val ); } else { // assume local var // This case happens for example so // class myclass // { // function myfunc() // { // for (i=0;...) should be for (var i=0; ...) // { // } // } // } add_local ( varname, val ); IF_VERBOSE_ACTION ( log_error ( "can't set_variable_raw %s=%s, target is NULL, it's assumed as local\n", varname.c_str(), val.to_string() ) ); IF_VERBOSE_ACTION ( log_error ( "probably you forgot to declare variable '%s'\n", varname.c_str() ) ); } }
void as_environment::set_target ( as_value &target, character *original_target ) { if ( target.is_string() ) { tu_string path = target.to_tu_string(); IF_VERBOSE_ACTION ( log_msg ( "-------------- ActionSetTarget2: %s", path.c_str() ) ); if ( path.size() > 0 ) { character *tar = cast_to<character> ( find_target ( path.c_str() ) ); if ( tar ) { set_target ( tar ); return; } } else { set_target ( original_target ); return; } } else if ( target.is_object() ) { IF_VERBOSE_ACTION ( log_msg ( "-------------- ActionSetTarget2: %s", target.to_string() ) ); character *tar = cast_to<character> ( find_target ( target ) ); if ( tar ) { set_target ( tar ); return; } } IF_VERBOSE_ACTION ( log_msg ( "can't set target %s\n", target.to_string() ) ); }
void as_environment::set_register ( int reg, const as_value &val ) { IF_VERBOSE_ACTION ( log_msg ( "-------------- set_register(%d): %s at %p\n", reg, val.to_string(), val.to_object() ) ); *local_register_ptr ( reg ) = val; }