Sign in to follow this  

Single reference type

This topic is 3301 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

Here is code to register a single reference type
nRet = (asERetCodes) pScriptEngine->RegisterObjectType("Single", 0,    asOBJ_REF | asOBJ_NOHANDLE);
assert( nRet >= 0 );
nRet = (asERetCodes) pScriptEngine->RegisterObjectMethod("Single", "bool isRepeat()", asMETHOD(Single, isRepeat), asCALL_THISCALL);
assert( nRet >= 0);
After I register another methods, which is to return the reference:
nRet = (asERetCodes) pScriptEngine->RegisterObjectMethod("Test", "Single @getSingle()", asMETHOD(Test, getSingle), asCALL_THISCALL);
assert( nRet >= 0);
Above got compiling error, which is said to be invalid declearion.
nRet = (asERetCodes) pScriptEngine->RegisterObjectMethod("Test", "Single &getSingle()", asMETHOD(Test, getSingle), asCALL_THISCALL);
assert( nRet >= 0);
Above is passed. And then I register a global variable, which is Test type. I called following sentense:
MobyKeys@ a = gTest.getSingle();
It gave me error message as return value -1. Can u point out wat's wrong? I want to register a reference type, and the script engine won't create or delete the object. And it can only get from functions or methods as reference type. I think Single reference type is suitable for this. What's wrong with my above?

Share this post


Link to post
Share on other sites
I don't think the single reference type is what you want. For what you describe you really want an uninstanciable reference type, i.e. the scripts are allowed to store references to the type, but it cannot instanciate the type itself. With the single reference type, the scripts may not even store references, not even as temporary variables, they will only be able to access a reference provided by the application as a property.

The uninstanciable refernence type is registered as a normal reference type, except that it has no factory behaviours.

Regards,
Andreas

Share this post


Link to post
Share on other sites
It passed when I register it as uninstanciable reference.
Thanks Andreas.

By the way, is that a good idea to have a reference type, which does not require the asBEHAVE_ADDREF and asBEHAVE_RELEASE and factory?

My arguement is this:
applicaiton -> script -> back to application. If inside of script, we only do some actions on the reference of object, but we never free it. It unnecessary to register the addref and release and the application also does not care about the counter inside of script, since we sure that the script won't free it.

what do u think?


Quote:
Original post by WitchLord
I don't think the single reference type is what you want. For what you describe you really want an uninstanciable reference type, i.e. the scripts are allowed to store references to the type, but it cannot instanciate the type itself. With the single reference type, the scripts may not even store references, not even as temporary variables, they will only be able to access a reference provided by the application as a property.

The uninstanciable refernence type is registered as a normal reference type, except that it has no factory behaviours.

Regards,
Andreas


Share this post


Link to post
Share on other sites
If you can also make sure that all scripts are destroyed before the actual instance is destroyed (or that none of the existing scripts keep a reference to the instance that has been destroyed by the application) then there is no need to use the reference counting.

However, AngelScript still requires you to register the Addref/Release behaviours (I'll change this in a future version). The Addref/Release behaviour can be implemented with a dummy function though, i.e. a function that doesn't do anything.

Regards,
Andreas

Share this post


Link to post
Share on other sites
:) Yeah. I can.

Thanks for ur help

Cheers.

Quote:
Original post by WitchLord
If you can also make sure that all scripts are destroyed before the actual instance is destroyed (or that none of the existing scripts keep a reference to the instance that has been destroyed by the application) then there is no need to use the reference counting.

However, AngelScript still requires you to register the Addref/Release behaviours (I'll change this in a future version). The Addref/Release behaviour can be implemented with a dummy function though, i.e. a function that doesn't do anything.

Regards,
Andreas


Share this post


Link to post
Share on other sites

This topic is 3301 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this