Jump to content
  • Advertisement
Sign in to follow this  
iraxef

debug checking of script-function params before executing

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

I have a codepath where I receive a vector of parameters from client code, intended for passing as parameters to a script-function call. In debug mode, I'd like to do some sanity checking on these parameters (like making sure that the number of values matches the number of parameters the script-function expects).

 

 

I currently have the following code (for each param):

if ( (funcParamTypeId & asTYPEID_SCRIPTOBJECT) )
{
  // no way to pass a script object from C++ to a script function call.. this is an error condition
}
else if ( (funcParamTypeId & asTYPEID_MASK_OBJECT) )
{
  // check whether script-function param is a known application-registered type such as 'string' or 'Vector2' and ensure that that's what we got
}
else if ( (funcParamTypeId & asTYPEID_MASK_SEQNBR) )
{
  // check whether script-function param is a script primitive type
}

I realize based on the GC comment here that this is an incorrect use of asTYPEID_MASK_SEQNBR and it's just happening to work. (I don't have a lot of experience with GC yet because all my application-registered types are the NOCOUNT variety so far... the 'number' portion of the name confused me at the time.)

 

Is the proper way to rewrite that condition:

else if ( funcParamTypeId >= asTYPEID_BOOL && funcParamTypeId <= asTYPEID_DOUBLE )

?

 

Thank you very much.

Share this post


Link to post
Share on other sites
Advertisement

It's funny how you associated the sequence number mentioned in the GC thread with the asTYPEID_MASK_SEQNBR you were using for the typeid checks. They are completely unrelated, but it was a good thing you made that association because using asTYPEID_MASK_SEQNBR like you did is definitely not correct.

 

asTYPEID_MASK_SEQNBR just masks out the sequence number, and since all types have a sequence number this condition would always be true (except for void that uses the sequence number 0).

 

Yes, you can use the condition ( funcParamTypeId >= asTYPEID_BOOL && funcParamTypeId <= asTYPEID_DOUBLE ) to determine if the type is a primitive. The typeids for the built-in primitive types are fixed for this very purpose.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!