Example #1
0
	// parse Flash vars and create _root variables
	// Flash vars come in the format:
	// myvar1=value1,myvar2=value2,myvar3=value3,...
	void root::set_flash_vars(const tu_string& vars)
	{
		for (const char* word = vars.c_str(); *word; )
		{
			bool nullDel = false;
			const char* delimiter = strchr(word, '=');
			if (delimiter == NULL)
			{
				// no value
				return;
			}
			tu_string varname(word, int(delimiter - word));

			word = delimiter + 1;
			delimiter = strchr(word, ',');
			if (delimiter == NULL)
			{
				delimiter = vars.c_str() + vars.size();
				nullDel = true;
			}
			tu_string value(word, int(delimiter - word));
		
			get_root_movie()->set_member(varname, value.c_str());

			if (nullDel)
				return;

			word = delimiter + 1;
			
		}

	}
Example #2
0
const char* get_gameswf_version()
{
#ifdef WIN32
    static tu_string s_gameswf_version("WIN "__DATE__" "__TIME__);
#else
    static tu_string s_gameswf_version("LINUX "__DATE__" "__TIME__);
#endif

    return s_gameswf_version.c_str();
}
	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() ) );
		}
	}
	// Should be highly optimized !!!
	bool	as_environment::parse_path ( const tu_string &var_path, tu_string *path, tu_string *var )
	// See if the given variable name is actually a sprite path
	// followed by a variable name.  These come in the format:
	//
	// 	/path/to/some/sprite/:varname
	//
	// (or same thing, without the last '/')
	//
	// or
	//	path.to.some.var
	//
	// If that's the format, puts the path part (no colon or
	// trailing slash) in *path, and the varname part (no color)
	// in *var and returns true.
	//
	// If no colon, returns false and leaves *path & *var alone.
	{
		// Search for colon.
		const char *colon = strrchr ( var_path.c_str(), ':' );

		if ( colon )
		{
			// Make the subparts.
			*var = colon + 1;

			// delete prev '/' if it is not first character
			if ( colon > var_path.c_str() + 1 && * ( colon - 1 ) == '/' )
			{
				colon--;
			}

			*path = var_path;
			path->resize ( int ( colon - var_path.c_str() ) );
			return true;
		}

		else
		{
			// Is there a dot?  Find the last one, if any.
			colon = strrchr ( var_path.c_str(), '.' );

			if ( colon )
			{
				// Make the subparts.
				*var = colon + 1;
				*path = var_path;
				path->resize ( int ( colon - var_path.c_str() ) );
				return true;
			}
		}

		return false;
	}
Example #5
0
	void as_object::dump(tu_string& tabs)
	// for debugging, used from action script
	// retrieves members & print them
	{
		tabs += "  ";
		printf("%s*** object 0x%p ***\n", tabs.c_str(), this);
		for (stringi_hash<as_value>::const_iterator it = m_members.begin(); 
			it != m_members.end(); ++it)
		{
			const as_value& val = it->second;
			if (val.is_property())
			{
				printf("%s%s: <as_property 0x%p, target 0x%p, getter 0x%p, setter 0x%p>\n",
								tabs.c_str(), 
								it->first.c_str(), val.to_property(), val.get_property_target(),
								val.to_property()->m_getter.get_ptr(), val.to_property()->m_setter.get_ptr());
			}
			else
			if (val.is_function())
			{
				if (cast_to<as_s_function>(val.to_object()))
				{
					printf("%s%s: <as_s_function 0x%p>\n", tabs.c_str(), 
						it->first.c_str(), val.to_object());
				}
				else
				if (cast_to<as_3_function>(val.to_object()))
				{
					printf("%s%s: <as_3_function 0x%p>\n", tabs.c_str(), 
						it->first.c_str(), val.to_object());
				}
				else
				{
					printf("%s%s: <as_c_function 0x%p>\n", tabs.c_str(), 
						it->first.c_str(), val.to_object());
				}
			}
			else if (val.is_object())
			{
				printf("%s%s: <as_object 0x%p>\n",
					tabs.c_str(), 
					it->first.c_str(), val.to_object());
			}
			else
			{
				printf("%s%s: %s\n", 
					tabs.c_str(), 
					it->first.c_str(), it->second.to_string());
			}
		}

		// dump proto
		if (m_proto != NULL)
		{
			m_proto->dump(tabs);
		}
		tabs.resize(tabs.size() - 2);
	}
	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::add_local ( const tu_string &varname, const as_value &val )
	// Add a local var with the given name and value to our
	// current local frame.  Use this when you know the var
	// doesn't exist yet, since it's faster than set_local();
	// e.g. when setting up args for a function.
	{
		assert ( varname.length() > 0 );
		m_local_frames.push_back ( frame_slot ( varname, val ) );
	}
Example #8
0
file::file(player* player, const tu_string& path, const tu_string& mode) :
    as_object(player),
    m_file(NULL)
{
    // is path relative ?
    tu_string file_name = get_player()->get_workdir();
    if (strstr(path.c_str(), ":") || *path.c_str() == '/')
    {
        file_name = "";
    }
    file_name += path;

    m_file = new tu_file(file_name.c_str(), mode.c_str());

    // methods
    builtin_member("read", file_read);
    builtin_member("write", file_write);
    builtin_member("eof", as_value(file_get_eof, as_value()));	// readonly property
    builtin_member("error", as_value(file_get_error, as_value()));	// readonly property

}
Example #9
0
void membuf::append(const tu_string& str)
{
	append(str.c_str(), str.length());
}
Example #10
0
const char* get_proxy()
{
	return s_proxy.c_str();
}
Example #11
0
	as_value	as_environment::get_variable_raw (
	    const tu_string &varname,
	    const array<with_stack_entry>& with_stack ) const
	// varname must be a plain variable name; no path parsing.
	{
		as_value	val;

		// First check the with-stack.
		for ( int i = with_stack.size() - 1; i >= 0; i-- )
		{
			as_object	*obj = with_stack[i].m_object.get_ptr();

			if ( obj && obj->get_member ( varname, &val ) )
			{
				// Found the var in this context.
				return val;
			}
		}

		// Then check locals.
		int	local_index = find_local ( varname, true );

		if ( local_index >= 0 )
		{
			return m_local_frames[local_index].m_value;
		}

		// Check movie members.
		if ( m_target != NULL && m_target->get_member ( varname, &val ) )
		{
			return val;
		}

		// Check this, _global, _root
		as_standard_member	varname_id = get_standard_member ( varname );

		switch ( varname_id )
		{
			default:
				break;

			case M_GLOBAL:
				val.set_as_object ( get_player()->get_global() );
				return val;

			case MTHIS:
				val.set_as_object ( get_target() );
				return val;

			case M_ROOT:
			case M_LEVEL0:
				val.set_as_object ( get_root()->get_root_movie() );
				return val;
		}

		// check _global.member
		if ( get_player()->get_global()->get_member ( varname, &val ) )
		{
			return val;
		}

		// Fallback.
		IF_VERBOSE_ACTION ( log_msg ( "get_variable_raw(\"%s\") failed, returning UNDEFINED.\n", varname.c_str() ) );
		return val;
	}