Jump to content

  • Log In with Google      Sign In   
  • Create Account


- - - - -

Pointers in AngelScript: Really necessary?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
33 replies to this topic

#1 Andreas Jonsson   Moderators   -  Reputation: 3268

Like
0Likes
Like

Posted 26 October 2004 - 05:55 AM

I've come to think of the pointers in AngelScript as a great burden that I would rather remove. I realize that in some situations they can be useful, and that some of you are already using pointers in the script. Therefore I want to ask your opinion before removing the pointers. If it was possible I would make it a compile time option, with the default turned of (just like I've done with AS_DEPRECATED). Instead of native pointers the application would register a special type, e.g. float_ptr. The library will also allow registration of the -> operator so that the pointer can be emulated. Another advantage of this is that the application would be able to register an indexing operator so that it could work exactly like normal C arrays. instead of:
void function()
{
   Object *obj = GetObject();
   if( obj->property )
      obj->Method();
}
it will be:
void function()
{
   Object_ptr obj = GetObject();
   if( obj->property )
      obj->Method();
}
What do you think? Can I do this without disrupting your projects too much? It would really help me improve the library even further. Let me know what you think. Please. Regards, Andreas
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Sponsor:

#2 Aggrav8d   Members   -  Reputation: 133

Like
0Likes
Like

Posted 26 October 2004 - 07:54 AM

Well I can only speak for myself but I've got pointers all over my script files. However, I do not do any pointer arithmetic and I do not anticipate anything quite so dangerous. Why would this change help? Is it a parsing problem?

Dan Royer, OwnerMarginally Clever Games

#3 Aggrav8d   Members   -  Reputation: 133

Like
0Likes
Like

Posted 26 October 2004 - 08:02 AM

Actually, I wonder if this might be related to a problem I'm having. I

SoundRecording *[] records(5);

// initialization of pointers, etc...

int vi=3;

// void PlaySoundNow(SoundRecording *sr,float volume,bool loop);
PlaySoundNow(records[vi],1.0f,false);



and I get an error on PlaySoundNow because

No matching operator that takes the type 'int&' found

and the column offset is the first '[' on the PlaySoundNow line.

update: It appears to be an array indexing problem, not a pointer problem. I can replace vi with a constant and it works fine.

Dan Royer, OwnerMarginally Clever Games

#4 Andreas Jonsson   Moderators   -  Reputation: 3268

Like
0Likes
Like

Posted 26 October 2004 - 08:59 AM

Pointers complicate the code in several places, the parser, the compiler, engine functions etc. To support pointers I need to do a lot of special cases. Removing the pointers would clean up the library code, and make further enhancements easier.

But that's ok, I'll try to clean up the code in another way.

I'll probably only be able to remove the pointers by making a different scripting library.

In the meantime I will implement everything that is necessary to remove the pointers, e.g. the overloaded ->. So that it will be possible to at least optionally remove the pointers from the syntax.

---

The indexing operator is declared to take an uint, so declaring the vi as uint, or casting it to uint, should let you work around the problem.

I've discovered and fixed a few bugs with the implicit cast of types. I'll soon release WIP 6 with these fixes.

A future version of AngelScript will also have much improved rules for implicit type conversions.
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

#5 Aggrav8d   Members   -  Reputation: 133

Like
0Likes
Like

Posted 26 October 2004 - 09:35 AM

i suppose i could run a "replace in all files" because as far as i'm concerned it's just the declaration that's changed. Tho if you create this pointer system then how would you implement

int **ptr2;

?

thank you for fixing the implicit type conversions! Those were really starting to annoy me. Will you be supporting the alternate syntax (type)var as well as type(var) ?

Dan Royer, OwnerMarginally Clever Games

#6 zola   Members   -  Reputation: 122

Like
0Likes
Like

Posted 26 October 2004 - 11:26 AM

As far as I'm concerned it only looks like a different notation.

I only use pointers to pass values by reference from my app to the script I don't think it will be a big change for me.

#7 desertcube   Members   -  Reputation: 514

Like
0Likes
Like

Posted 26 October 2004 - 11:59 AM

So far in my scripts I have been able to simply use references, but I haven't tried passing objects to/from the script that inherit from a base class, so not really sure if pointers are needed for polymorphism (but surly references will get round this?)

So, I won't miss pointers if you do decide to remove them, but I'm not using AS to it's full capacity yet!

#8 Deyja   Members   -  Reputation: 920

Like
0Likes
Like

Posted 26 October 2004 - 12:07 PM

I think some clarification is in order.

By 'no pointers' you mean that the * type modifier will no longer exist. That does not mean we can't use pointers! I generally prefer thin handle classes over raw pointers. I probably won't miss them much. If it makes the library better, go for it. Understand that by better I mean more robust and faster.

#9 Andreas Jonsson   Moderators   -  Reputation: 3268

Like
0Likes
Like

Posted 26 October 2004 - 01:23 PM

Aggrav8d:

A pointer to a pointer would need yet another type. But I can't think of any place where you actually need to store a pointer to a pointer. It is mostly used in parameters, where a reference to a pointer type would work just as well.

I don't think I will support the alternate casting style, (type)expression. But then again, nothing is set in stone. It would be necessary for casting between pointer types, if I decide to keep the pointers.

desertcube:

Once AngelScript supports polymorphism, the references will be work just as well for this purpose.

Deyja:

Exactly, by no pointers in AngelScript I mean that the scripting language won't have the * type modifier. The C++ application will still be able to pass a pointer to the script, which would then have to store it in another type. This replacement type can be a registered type where the application freely chooses the name.

---

In my opinion, since the scripting language don't allow for taking the address of a variable, dereferencing a pointer, or any pointer arithmetic, the pointers don't really bring any advantage to the language.

I thank you all for your support, and your help in deciding the future of AngelScript.

I've not yet made a final decision, so keep writing your comments.


AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

#10 kaysik   Members   -  Reputation: 382

Like
0Likes
Like

Posted 26 October 2004 - 01:37 PM

Pointers should go! From what you've said I think getting rid of pointerss would make your life and the lib better, as well as not taking away much functionality (if any). Registering an Obj_ptr type would take a good 5 seconds, and with references I can't see a situation where you'd need the * explicity. Sure for people who've already got a heap of scripts that use pointers heavily it would be a pain to convert but and afternoon with Find and Replace should be enough for them to convert over. Backwards compatability is nice, but sometimes its worth breaking, and when the break is this easy (changing Obj * to Obj_ptr) then it doesn't seem like there is any real reason not to!

Quote:
Pointers complicate the code in several places, the parser, the compiler, engine functions etc. To support pointers I need to do a lot of special cases. Removing the pointers would clean up the library code, and make further enhancements easier.


Sounds like its definatly worth it!

#11 MichaelT   Members   -  Reputation: 214

Like
0Likes
Like

Posted 26 October 2004 - 01:52 PM

Just scrap it. It is not the end of the world, people just need to go over the code once. No big deal. Just make it clear and explain how to use the new method. It is better to do it now, before it becomes a big problem and your scripting library is used by far too many people.


#12 Andreas Jonsson   Moderators   -  Reputation: 3268

Like
0Likes
Like

Posted 26 October 2004 - 02:32 PM

It seems that there are no real objections to the removal of the pointers.

That makes me relieved, and makes it much easier to make the decision.

Still I will leave the question open a while longer before making the final decision. Only one day is too short to let everyone interested leave their comments.






AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

#13 Desdemona   Members   -  Reputation: 158

Like
0Likes
Like

Posted 26 October 2004 - 04:32 PM

My whole approach to AS has been a black box. It does what I need it to do, its familiar, and it has consistantly moved it a good direction. From my point of view, removing pointers is really just a cosmetic change, and if that helps the library move forward, then so much the better.

I'm also one for going with the bare minimum. Less syntax means that the scripts will be more simple and easy to understand and write.

I have the unfortunate feeling that the change will wrack with my current game since it is so dependant on AS. I am using 1.9.2 and am almost finished with my engine. Everything is working perfectly so I have not had any intentions of upgrading, but I'd probebly take a stab at it for simpler syntax.

Joe

#14 Desdemona   Members   -  Reputation: 158

Like
0Likes
Like

Posted 26 October 2004 - 05:25 PM

Of course, I suppose it wouldnt be necessary to upgrade to take advantage of the change as I can just make all my objects pointerless right now, but hey, I'd still give it a try... :)


#15 GunderWulde   Members   -  Reputation: 122

Like
0Likes
Like

Posted 26 October 2004 - 08:49 PM

Maybe can use arrays like pointers.

Objects[] MyObjects = GetObjectsArray();

I thinks is enought.

Gunder

#16 LogicalError   Members   -  Reputation: 241

Like
0Likes
Like

Posted 26 October 2004 - 09:02 PM

Is an operator-> really necesarry?
only having an operator. would be enough, imho..


#17 abrken   Members   -  Reputation: 130

Like
0Likes
Like

Posted 26 October 2004 - 10:49 PM

This is how I feel after reading the question.

#18 Andreas Jonsson   Moderators   -  Reputation: 3268

Like
0Likes
Like

Posted 27 October 2004 - 03:09 AM

GunderWulde:

Yes, a C++ pointer can be treated as an array object by AngelScript by registering the proper behaviours.

LogicalError:

The -> operator is necessary and even useful. Basically it will be used to convert the variable into another type in order to access the properties and methods of the contained type. Look at how iterators are implemented in C++, they use the . to access the iterators methods, and -> to access the element that the iterator is pointing to.

abrken:

An angry face doesn't really explain why you feel like you do. Would you mind explaining your objections?


AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

#19 Deyja   Members   -  Reputation: 920

Like
0Likes
Like

Posted 27 October 2004 - 11:22 AM

If your engine is already near completion, and you are using AS heavily, it's probably in your best interest NOT to update your copy of AS until you are ready for your next project. I know once I actually start working on the GAME part of my game, I will take whatever versions my standard libs are at at the time and will not update them again.

#20 jetro   Members   -  Reputation: 144

Like
0Likes
Like

Posted 27 October 2004 - 11:36 AM

When I noticed I basically had to use pointers in scripting API, I thought that was a bit sucky but let it be that way then.

Pointers and syntax stuff related to them are hard to understand for beginning/novice coders. Because of this I'd also like the '->' operator go away and have just '.' instead - it works pretty well with Java already. :)

If you can remove pointers, especially if you can do it without sacrificing the simpleness of making app binding code for scripting stuff, go for it. Just remember to make a simple and easy to follow guide on how to upgrade old scripts for the new system.

--Jetro Lauha - tonic - http://jet.ro




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS