I feel a bit stupid right now, but…
Is there anyway to iterate over all values (or keys) of a proplist?
In case you tell me that there is nothing, I will implement it. (I'm still thinking whether I want to provide an interface to loop over the keys.
Is there anyway to iterate over all values (or keys) of a proplist?
for(var p in ps)
doesn't seem to work…In case you tell me that there is nothing, I will implement it. (I'm still thinking whether I want to provide an interface to loop over the keys.
for((var k, var p) in ps)
and for(var k in keys ps)
are floating in my head. Also, whether that syntax should work on arrays…)
GetKeys or something like that. I am not at home so I can't check atm :)
GetProperties
. Found it by grepping over C4Script.cpp for functions that use C4PropList for anything else but _this.But I'll still implement
for(… in …)
for proplists.[Edit:]
GetProperties
is a very interesting function anyway.-> GetProperties({a:true, Prototype: {a: false}})
= ["a", "a"]
> GetProperties is a very interesting function anyway.
Well that's obviously a bug.
> But I'll still implement for(… in …) for proplists.
Do you think that's necessery? To me it seems like it would be only marginally shorter than just using GetProperties(), while still making the scripting language more complex. E.g.:
func DupProplist(p)
{
var dup = {};
for (var key in GetProperties(list))
dup[key] = p[key];
return dup;
}
func DupProplist2(p)
{
var dup = {};
for (var key,value in list)
dup[key] = value;
return dup;
}
>Do you think that's necessery?
The real benefit is that you can use one function for arrays and proplists.
I'm thinking that I may be too lazy to do so though. Turns out it's not exactly easy (as oposed to fixing GetProperties).
>The real benefit is that you can use one function for arrays and proplists.
Might be good from an "we want a very sleek programming language"-point of view.
But I doubt it has ANY benefits for a complete beginner in C4Script OR actually for us experienced developers.
The beginner would just be confused that in arrays you'd iterate over the contents and in proplists over the keys or whatever. I can't really see the benefits :)
It'd be contents on both of them, obviously.
And even if I'm not doing it with for, I'd still like an efficient method to iterate over a proplist.
And even if I'm not doing it with for, I'd still like an efficient method to iterate over a proplist.
> Turns out it's not exactly easy (as oposed to fixing GetProperties).
Why? You'd just check if the type is proplist, and if so, create a temporary array and use the same iteration code that's used for arrays now.
It would be more complicated if you tried it without the temporary copy though.
Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill