Jump to content
  • Advertisement
Sign in to follow this  

Prevent Reassignment Of Handle

This topic is 864 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have registered a type in angelscript with a property that is a handle to an object:


RegisterObjectProperty("SomeType", "Object@ obj", 0);


That object's memory is handled by the application.


I would like to prevent script writers from assigning another object to that handle, without making the object constant. For example:


SomeType@ a = ...;

SomeType@ b = ...;


a.obj.value = 4; // Script can edit obj


a.obj = b.obj; // I want this to fail


It needs to be a handle, because SomeType.obj may refer to another SomeType's obj. I just don't want the script to be able to change which object it refers to. Is there a way I can do this?

Share this post

Link to post
Share on other sites

Well one thought comes to mind. In C/C++ you can define an objects assignment operator to be private. In angel script the syntax I pulled from their docs looks something like this:

obj@ opAssign(const obj &in other)
    // Do the proper assignment
    // Return a handle to self, so that multiple assignments can be chained
    return this;

So you could try something like this: (Treat this as psuedocode as I am not sure if the syntax is correct)

class myObj
    private myObj opAssign(const obj &in other) { return this; } 

I'm guessing for the most part here as to the functionality of the code I have just given you. Since I've never written a line of AngelScript ever before :P

I'm viewing this from a C++ perspective, but according to the docs, and what it seems your asking for is well within the scope of the language.


In case my explanation is not par, take a gander from where I sourced it.





Marcus Hansen

Edited by markypooch

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!