AS 2.0: handle syntax a little strange
Angel Script 2.0 syntax seems a little too odd to me (being used with C++). Here is a quick example of a script:
Obj obj1;
Obj@ hobj1, hobj2;
@hobj1 = @GetHandle();
if(@hobj1 == null)
{
Print(“error …”);
return;
}
@hobj2 = @obj;
if(@hobj2 == @hobj1)
Print(“equal…”);
Oughh, that’s a lot of @, it makes my head hurts. I’m using a lot of pointers (now handles) in my scripts pointing to the engine objects and all the scripts are full of @. Now, what’s wrong with a more C++ like syntax?
Obj obj;
Obj *hobj1, *hobj2; // Uninitiated handles.
hobj1 = GetHandle();
if(hobj1 == NULL) // Compare with NULL handle.
{
Print(“error …”);
return;
}
hobj2 = &obj // Get a handle to the obj1.
if(hobj2 == hobj1) // Ore use if (&obj == hobj1)
Print(“equal…”);
I don’t see any problems with that syntax and the script is much clear (and familiar). Use * for handles (like for pointers in C), use & to get a handle to an object.
To copy handle use:
hobj1 = hobj2;
hobj1 = &obj
Copy by value:
*hobj1 = *hobj1;
*hobj1 = obj;
All like in C (C++) (don’t know why you have to use @). The only difference is that you cannot use multiple pointer indirections (**), and a pointer is more like a smart pointer (handle) than a standard C++ pointer. Use *, & parameters like in C.
I don’t know if it’s only me but I find the new syntax (at least when you have to use a lot of handles) ugly.
I understand you. I'm not completely happy with the syntax either. However, I have my reasons for going with this syntax, even though I'm also an avid C++ fan.
I don't want to use the * for object handles, because it is not real pointers. Using * could lead to confusion when application functions try to work with the handles just like normal pointers (could lead to memory leaks and invalid pointers).
I also wanted to have the syntax work so that the object handle is simply an alias for the real object, which I believe is easier for non-programmers. Calling the objects methods, or doing an assign by value works the exact same way wether you're using object handles or not.
This is my reason for doing the syntax as I did. But I will improve the syntax, so that you will not have to write so many @. The compiler will implicitly add the @ operator where it is necessary. This will make your code have the following appearance:
It's a little better, isn't it?
I don't want to use the * for object handles, because it is not real pointers. Using * could lead to confusion when application functions try to work with the handles just like normal pointers (could lead to memory leaks and invalid pointers).
I also wanted to have the syntax work so that the object handle is simply an alias for the real object, which I believe is easier for non-programmers. Calling the objects methods, or doing an assign by value works the exact same way wether you're using object handles or not.
This is my reason for doing the syntax as I did. But I will improve the syntax, so that you will not have to write so many @. The compiler will implicitly add the @ operator where it is necessary. This will make your code have the following appearance:
Obj obj1;Obj@ hobj1, hobj2;@hobj1 = GetHandle(); if( hobj1 == null ) { Print(“error …”); return;}@hobj2 = obj; if(@hobj2 == hobj1) Print(“equal…”);
It's a little better, isn't it?
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game
Well, I guess is better. Anyway * will not create any confusion for programmers (since they know the differences between AS and native C++), neither for non programmer script writters (since they don't know C++ at all).
But I can leave with these modifications
Thanks
But I can leave with these modifications
Thanks
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement