# Pointers in AngelScript: Really necessary?

## Recommended Posts

WitchLord    4677
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

##### Share on other sites
Aggrav8d    133
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?

##### Share on other sites
Aggrav8d    133
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.

##### Share on other sites
WitchLord    4677
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.

##### Share on other sites
Aggrav8d    133
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) ?

##### Share on other sites
zola    122
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.

##### Share on other sites
desertcube    514
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!

##### Share on other sites
Deyja    920
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.

##### Share on other sites
WitchLord    4677
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.

##### Share on other sites
kaysik    382
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!

##### Share on other sites
MichaelT    214
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.

##### Share on other sites
WitchLord    4677
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.

##### Share on other sites
Desdemona    158
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

##### Share on other sites
Desdemona    158
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... :)

##### Share on other sites
GunderWulde    122
Maybe can use arrays like pointers.

Objects[] MyObjects = GetObjectsArray();

I thinks is enought.

Gunder

##### Share on other sites
LogicalError    293
Is an operator-> really necesarry?
only having an operator. would be enough, imho..

##### Share on other sites
abrken    130
This is how I feel after reading the question.

##### Share on other sites
WitchLord    4677
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?

##### Share on other sites
Deyja    920
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.

##### Share on other sites
jetro    144
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.

##### Share on other sites
kaysik    382
Quote:
 Original post by jetroPointers 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 I'm not mistaken then when pointers are removed you can simple use the '.' operator as normal with your Obj_ptr class instead of overloading the '->' operator which will give you exactly what your after while letting anyone who wants it, access to the '->' operator.

but i could be wrong :P

##### Share on other sites
abrken    130
Quote:
 Original post by jetroPointers 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. :)

That's why in my application when the user type '.' it is automaticaly changed to '->' if needed.

To express myself on this subject more than with a angry face, this is my full point of view, and why it make me "monter la moutarde aux nez quand je lis ce genre de truc" sorry I cant translate.

Why did I choose AS :
I have tried LUA with ToLUA++. The integration of LUA in my project was pretty easy. Everything was working well when there come time to make script. The LUA language make me search for another scripting library that was much "natural" to write script with.
I have integrated the VBScript engine in another project, and definitively this was not the solution, or I had to write COM handler for all the classes I wanted to insert into VBScript.
So, as I was looking for AS for longtime ago, I have decided to give it a try.
The integration of AS was pretty easy, and script was also easy to write. So I have choosed it (from 1.8.x).

Then time passed, and AS has become to change.
The library has changed the include path to angelscript.h . Of course this is not a pb, but with a source controled project this is not good. So now every time I want to integrate a new version, I have to change the include of as_xxxxx files that point to the new path.
This is not a pb ...

Time has passed and I have integrated AS in a much closer way than more of AS user has did (I think). I have make my own asIScriptEngine derived class to be able to process registered func/var/class/method that let the script write get tool tips that help to write script with syntax hilight and other feature.
The library then has change the asISScriptEngine interface !

Nowaday, I've got a fully working application, with lot of script using it and it's about to change a CORE functionnality !

Quote:
 Original post by DesdemonaI 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.

This resume perfectly my feeling.

No library is perfect. This is a fact !

AbrKen

##### Share on other sites
WitchLord    4677
abrken:

well, I'm aware that removing the pointers will break some existing functionality. But I don't think it will break that much.

In fact, without the pointers in the scripting language, your application could be simplified as well, can't it?

If you wanted a stable library for your project then I'm afraid AngelScript wasn't the right choice.

---------

Well, in either case. I've decided to not remove the pointers for AngelScript 1.10.0. Though the future is still unsure.

I'm still trying to decide on how to go on from this. I may even start a derivative project, that will take all that is good in AngelScript and remove the bad stuff. I would also make all objects work with references like Java. This will simplify doing context serialization, and also make it easier to introduce classes declared in the script language.

Maybe I'll start on AngelScript 2, for this. I could keep supporting AngelScript 1.10.0 with bug fixes and minor improvements. After all, AngelScript 1.10.0 will be a complete scripting language with almost everything except script defined structures or classes.

##### Share on other sites
Lioirc    142
Hi WitchLord

Im using AS with tons of pointers functionality (but as you know, a very modified AS 1.8.2b1 version as well, so im not using the as a lib but more like an engine integrated directly in my project), but here we need to look for what is best for the library future, so i know that changing how pointers are handled will make the library better/easy for new features to implement. So pointers need to be changed, and what you are saying is a good way of handle them in a script (im a little worried about the perfomance, well you know me :) )

Most of the users of a script library will use it for giving his application the ability of be modified/improved by final users, and here is where pointers are a bit of a problem, as new users or non-technical users can have problems

I dont know why there are complaints about changing pointers, if what is going to change is mostly the interface, not the CORE, and if this change will benefit the library as well the end users/script writters, this is a good direction to go, because at the end, this (end users) will be the factor that make our projects a success

Changing them in AS 1 or implementing in a new AS 2, either way, but its some that have to be done

Best Regards,

Lioric

##### Share on other sites
kaysik    382
I'd hate to see you keep supporting something thats holding the library back - people don't have to updated if you remove a feature they really like or they can write their own scripting engine. I'm not trying to make your remove points, just don't like to see good ideas goto waste. Rewriting a bit of code to accomodate new changes to AS seems like a small price to pay for such a sweet scripting lib to me. I doubt I'll ever vote against something that would improve the lib even if it meant a rewrite to my own code. It is your lib though so you have the final word but most people in this thread voted to drop pointers:

Drop - myself, Lioirc, jetro, desertcube, Desdemona, MichaelT, zola, Deyja
Keep - abrken

With a few people such as Aggrav8d and LogicalError not espressing an strong oppinion either way. I do understand your concerns for backwards compatability, and I see abrken's point but sometimes improving things is worth the effort. Still I like the idea of AS2 - it sounds cool :D