Old local copy issue
Hi,
When a script make a local copy of an object, it does not always call the copy constructor, sometimes it is calling the equal operator.
I just wonder if it is possible to let it always call copy constructor?
I have a state inside of that object, it only init the state when it create object, it can modify the state by state modification function, but not from equal operator, therefore which always bring me a problem with script local copying.
Cheers.
I intend to make this change for optimization reasons. But it will probably be a while before I get to implement this change.
However, I have to wonder if it is really wise to have the copy operator work differently than the assignment operator. Wouldn't that be a potential cause for hard to find bugs in your application?
However, I have to wonder if it is really wise to have the copy operator work differently than the assignment operator. Wouldn't that be a potential cause for hard to find bugs in your application?
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game
My condition is this:
You have a number: 12345.00
you can format this number to be 12,345.00 or +12,345.0000 or some others.
Also, you got date, and string state inside.
The format is initilised by constructor and also set by setFormat method.
Now, when I do this: 12,345.00 = +12.0000, the result should keep the same format as 12.00, not changed into +12.0000.
Now the question is: default type format is string, not a number. when you said temp variable = +12.0000, it will said to be a string. with the string type, the operation is underdefined within different condition. So....... (PS: instead of use regular expression to test which type is belongs to, it's really good if we know at start, that's y, the temp variable copy using equal operator will cause problems to my data type).
Cheers
You have a number: 12345.00
you can format this number to be 12,345.00 or +12,345.0000 or some others.
Also, you got date, and string state inside.
The format is initilised by constructor and also set by setFormat method.
Now, when I do this: 12,345.00 = +12.0000, the result should keep the same format as 12.00, not changed into +12.0000.
Now the question is: default type format is string, not a number. when you said temp variable = +12.0000, it will said to be a string. with the string type, the operation is underdefined within different condition. So....... (PS: instead of use regular expression to test which type is belongs to, it's really good if we know at start, that's y, the temp variable copy using equal operator will cause problems to my data type).
Cheers
Quote: Original post by WitchLord
I intend to make this change for optimization reasons. But it will probably be a while before I get to implement this change.
However, I have to wonder if it is really wise to have the copy operator work differently than the assignment operator. Wouldn't that be a potential cause for hard to find bugs in your application?
Question, is this type of yours registered as a value type or a reference type with AngelScript?
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game
value type.
Since we don't do the reference counting, instead of that, we have smartpointer template to keep the counting.
I feel it is not easy to register as a reference type, since you need reference counter.
Any suggestion on the easy way to convert value type into reference type?
PS:
I was thinking if it is possible to let script engine to have a wrap counting class on top of value registeration for the reference type, if we are not specified a reference counting method.
Cheers
Since we don't do the reference counting, instead of that, we have smartpointer template to keep the counting.
I feel it is not easy to register as a reference type, since you need reference counter.
Any suggestion on the easy way to convert value type into reference type?
PS:
I was thinking if it is possible to let script engine to have a wrap counting class on top of value registeration for the reference type, if we are not specified a reference counting method.
Cheers
Quote: Original post by WitchLord
Question, is this type of yours registered as a value type or a reference type with AngelScript?
I wasn't suggesting that you register the type as a reference type. It may have dimishined the problem a bit, but it wouldn't solve it, as the type is copied if the function parameter takes it by value or in reference.
If you're still interested in adding reference counting to the type, you can do so similarly to how I added reference counting to std::string in the CScriptString add-on. Doing it like that most of the time the original functions that take a std::string by reference can still be registered directly with the engine. Only when the type is returned from a function by value do you have to create function wrappers.
Having AngelScript provide automatic reference count wrapper might be possible for types that are only meant to live within the script. But as soon as the object instances start crossing over to the application and back it will be difficult to keep the reference counting correct. Still, it is something that I'll investigate for a future version.
Regards,
Andreas
If you're still interested in adding reference counting to the type, you can do so similarly to how I added reference counting to std::string in the CScriptString add-on. Doing it like that most of the time the original functions that take a std::string by reference can still be registered directly with the engine. Only when the type is returned from a function by value do you have to create function wrappers.
Having AngelScript provide automatic reference count wrapper might be possible for types that are only meant to live within the script. But as soon as the object instances start crossing over to the application and back it will be difficult to keep the reference counting correct. Still, it is something that I'll investigate for a future version.
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement