🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Single reference type

Started by
3 comments, last by dxj19831029 15 years, 7 months ago
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?
Advertisement
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

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

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


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

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

:) 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


This topic is closed to new replies.

Advertisement