🎉 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!

debug checking of script-function params before executing

Started by
0 comments, last by WitchLord 10 years, 3 months ago

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.

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.

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