PDA

View Full Version : Does coffee support structs?


Scott Ayers
03-27-2010, 07:01 PM
I'm learning about using structs in C++ and when I try to use them in coffee I can't get it to work.
Coffee typically has as a slightly different way of implementing the C++ syntax.
So I'm wondering if the problem is that I'm not writing the coffee syntax properly. Or if using structs is even possible?

-ScottA

Darter
03-27-2010, 09:23 PM
The COFFEE SDK has an example showing the declaration and use of a struct.

Scott Ayers
03-27-2010, 10:29 PM
Thanks Darter,

I thought I saw it in there once before. But I could not for the life of me find the darn thing.
Since you confirmed it's in there. I looked again and finally found it.
The problem I was having is that structs in coffee get initialized in the prepass section the same way as C++. But they also have to be created inside the main section with this kind of thing: new(myStruct).
That's where coffee is different from C++. And that's what was tripping me up.
Creating new Arrays work the same way in coffee. And I have to say as a beginner that difference really makes it hard to transpose things I learn from C++ to coffee.
But I'm still liking coffee. Even with it's quirks and limitations.

BTW.
I know that there are lots of other coding newbies here like me. And the SDK about this probably doesn't make sense to you. And if you try to compile the example it won't work: // This example is from the SDK and won't compile

struct myStruct
{
var x,y;
}

// Using a structure:

function()
{
var point = new(myStruct);

point->x = 5;
point->y = 6;

// Outputs 5.
println(point->x);
}

The SDK examples do this kind of thing a lot.
They have spelling and punctuation errors, use reserved words, and either insert things they expect you to know how to strip out or edit for the examples to work. Or they just plain get really lazy and say this "insert code here..."
In other words. The SDK is not newbie friendly, and is written for people that already know enough about coding to fix their examples so they will actually work.
So for you people out there who are new and learning like me. And bashing your head on your keyboards every time you look at the SDK. Here's the same SDK example about structs.
Only this one will actually compile and run correctly: // This example will compile and run when pasted into the script manager

struct myStruct
{
var x,y;
}
main(doc,op)
{
var point = new(myStruct);
point->x = 5;
point->y = 6;

// Outputs 5.
println(point->x);
}


ScottA

rui_mac
03-28-2010, 08:51 PM
The first one will not compile because it lacks the main() function.
It is just an example of definition of a struct and its use inside a function.

Rui Batista

Scott Ayers
03-28-2010, 10:31 PM
Yes. That's true.
There are actually very few examples in the SDK that are written so that they will compile and run. They seem to be written more in an abstract type of manner. Where the reader already needs to have some basic coding skills under their belt to understand how to use it.
That's a big problem.

Not to mention all of the mistakes in it.
Like declaring a function called "Add()" in the prepass section.
Then calling that function with "add()" later on in the body of the main function.:argh:
Errors like that bring new people to a grinding and frustrating halt when trying to learn the language.

-ScottA

CGTalk Moderation
03-28-2010, 10:31 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.