[Swfdec] variable scope

Nguyen Thai Ngoc Duy pclouds at gmail.com
Tue Jun 12 03:24:11 PDT 2007


On 6/12/07, Benjamin Otte <otte at gnome.org> wrote:
> On 6/12/07, Nguyen Thai Ngoc Duy <pclouds at gmail.com> wrote:
> > Setting variables seem not that simple. The attached script was compiled with
> > ming 0.4.0.beta4: makeswf -v 6 -s 200x150 -r 1 -o a.swf a.as
> >
> Awesome. This looks a lot like a test we should immediately put in the
> testsuite (well, imeediately after we've fixed Swfdec to pass it :)).
> I guess SetVariable takes the current target in this case, we should
> probably add tests that check that (by using SetTarget). And one that
> uses With, just to be sure.

Well, I guess you're right. gnash falls back to the target when
setting new vars. I tried to add new vars to the current target
tonight but my swfdec-foo was not strong enough, I couldn't retrieve
the vars after adding them :P

void
as_environment::set_variable_raw(
    const tu_string& varname,
    const as_value& val,
    const std::vector<with_stack_entry>& with_stack)
{
	// 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	dummy;
		if (obj && obj->get_member(varname, &dummy)) {
		    // This object has the member; so set it here.
		    obj->set_member(varname, val);
		    return;
		}
	}

    // Check locals.
    int	local_index = find_local(varname);
    if (local_index >= 0) {
	// Set local var.
	m_local_frames[local_index].m_value = val;
	return;
    }

    assert(m_target);

    m_target->set_member(varname, val);
}


> > With swfplay commit 0.4.4-377-g7246ed3 (hacked in swfdec_action_trace
> > to print out), I got:
> >
> The swfplay app has quite some command line switches, including -t to
> print traces to stdout.
> You should try swfplay --help at some time. :)

Dammit! :-< Should have read the docs before hacking away.

> Btw: If there's a useful command line switch you're missing to swfplay
> or any of the other tools, feel free to add it. All the current
> switches came out of (sometimes weird) need for them. They weren't
> designed in.

Not really a switch. I wanted swfdec to print out every swf commands
it executed. Turning SWFDEC_DEBUG=6 was not enough. For example, when
pushing a value to stack, it only printed "push type %u", not the real
value. Attempt to add swfdec_as_value_to_printable in
swfdec_action_push failed badly because it ended up with
g_assert_not_reached() inside swfdec_as_value_to_string. Maybe some
bad pointers, I haven't looked at it yet.

> Benjamin
>


-- 
Duy


More information about the Swfdec mailing list