1st of all I'm a newbie to ChucK (Many thanks to Steve who brought me here).
I bumped into a problem regarding static strings, which would really
not have been in my way if I designed it another way, but I still feel it important
enough. Here is the story.
I wanted to create a function in a stand-alone .ck module to load my instrument
samples from disk. So I designed my loader class in
instr_loader.ck like this:
public class Instr_loader
{
"path/to/instrument" => static string m_p_instr;
fun static string get_instr {return m_p_instr;}
}
For some reason I just wanted to test the static flavor of ChucK, there is really no
reason to use a static member here I must confess.
Then my client code
main.ck looks like this:
Instr_loader.get_instr() => string path_instr;
when I run both .ck's, I will get:
[Instr_loader.ck]:line(3): cannot declare static non-primitive objects (yet)...
[Instr_loader.ck]:line(3): ...(hint: declare as ref (@) & initialize outside for now)
Then I change the code with the reference to:
"some/path" => static string @ m_p_loop
Then I run
chuck Instr_loader.ck main.ck
and get this:
[Instr_loader.ck]:line(3): cannot declare references (@) of primitive type 'string'...
[Instr_loader.ck]:line(3): ...(primitive types: 'int', 'float', 'time', 'dur')
So is there a reason why string is not part of primitive types?
BTW: it works perfectly using string as normal class member. I'm just interested
in this problem here.
Thank you and hope ChucK will chuck it all up~!
BeinanOn Sun, Dec 7, 2008 at 8:09 PM, Stephen Sinclair <
sinclair@music.mcgill.ca> wrote:
> Yeah, but you have to make it a static function of a public class.
> The class model in ChucK is still a little awkward, but public classes
> can be instantiated in other files. Only one public class can be
> defined per file!
>
> Steve
>
>
> On Sun, Dec 7, 2008 at 7:51 PM, Beinan Li <
li.beinan@gmail.com> wrote:
>> Hi Steve,
>>
>> Should be a newbie question:
>> In ChuCK, can you define a function in a single .ck file
>> and call it from another .ck like in Matlab?
>>
>> Thanks.
>>
>> Beinan
>>
>>
>>
>