[chuck-users] Static data problem (arrays, floats)
signal.automatique at gmail.com
Tue Sep 15 08:33:35 EDT 2009
> [Rational_io.ck]:line(16): cannot declare static non-primitive objects
> [Rational_io.ck]:line(16): ...(hint: declare as ref (@) & initialize
> outside for now)
Yeah, that's a bit tricky. Have a look at this;
static float foo;
//fill it and return it
fun static float bar()
for (int n; n< foo.cap(); n++) n => foo[n];
//initiate the array outside of the class
new float @=> war.foo;
// test, should print "3.0000"
<<< war.bar() >>>;
With arrays of primitives the syntax somehow becomes a bit differently from
the more regular
static Event @ my_event;
...and we have to define them as normal except not set the length, the
length will be set at initiation, which seems somewhat logical considering
the nature of the issue but it took me a while to figure it out as well.
We might consider having some examples in the /examples/ dir to illustrate
this kind of thing as it leads to a lot of questions.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the chuck-users