Sign in to follow this  

Simplest way to get variable type

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

What is the simplest way to get a variable's type as declared in a script, when the variable is received by a system function declared to take any input?

 

For example, given the following function declaration:

void Function(?& in)

How would i determine what type is passed in?

 

If i were to pass in this:

array<dictionary@>@ pArray = array<dictionary@>();

I want to get that declaration, including namespace if present. Whatever method would be used would have to take into account whether the input is a primitive type, reference or value type, enum, handle, or funcdef.

I know it's possible to get the information needed to form the declaration for all except funcdefs, which seem to be inaccessible on a module level. Only system declared funcdefs are available for iteration through the engine, as far as i know.

Share this post


Link to post
Share on other sites

How about this?

 

extern asIScriptEngine *engine;
 
// Registered as "void Function(?&in)"
void Function(void *ref, int typeId)
{
   std::string decl = engine->GetTypeDeclaration(typeId, true);
}

Share this post


Link to post
Share on other sites

That works for funcdefs, but arrays are given as "::::dictionary@[]". Unless GetFunctionByDecl supports this syntax i can't use it.

 

EDIT:

As i feared, GetFunctionByDecl doesn't support the array syntax. Is there an easy way to convert it to the common template format?

 

EDIT2:

Ok, by setting the engine property asEP_EXPAND_DEF_ARRAY_TO_TMPL it returns a template declaration, which works. Problem solved.

Edited by Solokiller

Share this post


Link to post
Share on other sites

The problem reported about GetTypeDeclaration returning an invalid syntax is not present in the latest WIP. This was fixed in an earlier modification.

 

If you prefer not to use asEP_EXPAND_DEF_ARRAY_TO_TMPL, then you can if you upgrade your version of AngelScript.

Share this post


Link to post
Share on other sites

This topic is 1104 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this