Dictionary

Started by
2 comments, last by WitchLord 15 years, 5 months ago
Hi, I wantto use the dictionary addon. The problem is this: The dictionary is using string as a key. I think I need to have a string representation for every time or every object. I tried to use the asBEHAVE_VALUE_CAST and asBEHAVE_IMPLICIT_VALUE_CAST. Is this correct? which will allow script to convert that type of object into a string representation. But when I tried, the script does not call the value cast behaviour, it give me the error msg instead. One of the example is: I have my own _string, register as asOBJ_APP_CLASS_CDA | asOBJ_VALUE. The value cast is register as:

nRet = (asERetCodes) pScriptEngine->RegisterObjectBehaviour("_String", asBEHAVE_VALUE_CAST, "string@ f()", asMETHOD(_String, operator string), asCALL_THISCALL); //asFUNCTION(flexGrid_castScriptObject), asCALL_GENERIC); 
assert( nRet >= 0 );

nRet = (asERetCodes) pScriptEngine->RegisterObjectBehaviour("_String", asBEHAVE_IMPLICIT_VALUE_CAST , "string@ f()", asMETHOD(_String, operator string) , asCALL_THISCALL); 
assert( nRet >= 0 );
if I used string instead of string@, it will give me error. when I called: dictionary dict; dict.set(_String("abc"), 100); it failed. error message is:

ExecuteString (1, 23): Err : No matching signatures to 'dictionary::set(_String &, const uint)'
I believe this means the script does not know how to convert _String into string. isn't it? Do I do anything wrong here? or any other suggestion?
Advertisement
I'll look into this. The script compiler may be failing to perform the implicit cast because the parameter is expecting a reference. You also don't need to register both the explicit value cast and the implicit value cast, just the implicit value cast is enough.

However, perhaps rather than registering an implicit cast to string, why don't you modify the code for the dictionary to take your own string type as input?

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

To modify dictionary is another option here. But I believe if every type can convert to string, then we can have a implicit value cast for every type, which can enable all type directly using dictionary instead of writing another dictionary function. Which is why I need the value cast.

By the way, I saw this sentence in the script:
r = engine->RegisterObjectMethod("dictionary", "void set(const string &in, ?&in)", asFUNCTION(ScriptDictionarySet_Generic), asCALL_GENERIC); assert( r >= 0 );    r = engine->RegisterObjectMethod("dictionary", "bool get(const string &in, ?&out)", asFUNCTION(ScriptDictionaryGet_Generic), asCALL_GENERIC); assert( r >= 0 );

?&in and ?&out mean any type? can I used in other function declearation?

Can I overwrite the index operator using:
"?&out f(const string &in)"


Also, can I use function to declear a implicit cast? can you give me a example? somehow, it always give me error code for registration.

Thanks.

Quote:Original post by WitchLord
I'll look into this. The script compiler may be failing to perform the implicit cast because the parameter is expecting a reference. You also don't need to register both the explicit value cast and the implicit value cast, just the implicit value cast is enough.

However, perhaps rather than registering an implicit cast to string, why don't you modify the code for the dictionary to take your own string type as input?

Regards,
Andreas


The ? is not the any type, though it is related, as without it, the any type wouldn't exist. It is the variant argument type, documented here: http://www.angelcode.com/angelscript/sdk/docs/manual/index.html

And no, you can't register functions that return this type, it can only be used with parameter references.

The implicit value cast behaviour can only be registered as an object behaviour (documentation) but you can use a global function, if you register it with the calling convention asCALL_CDECL_OBJLAST or asCALL_CDECL_OBJFIRST.

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