It should be possible to implement a ref cast behaviour that receives the desired type as a hidden parameter (similar to the variable arg ?). This would then allow the container to return the handle of the right type, or null if it is not supported. If (when?) I implement this it should be possible to use the any type as follows:
{ CObject @obj; // Store the handle of an object in the any container any c; c = @obj; // Retrieve the handle through a ref cast @obj = cast<CObject>(c);}
Maybe the current CScriptAny type is not the most adequate for this usage. Perhaps something a bit most specific, like a generic handle type so it can be seen as if it was just a handle, thus allow handle assignment to work as it should. It would be necessary to allow the registration of a specific behaviour that overloads the handle assignment operator, and probably also the handle comparison operators. Likewise, another type more directed towards value types may be needed.