Jump to content
  • Advertisement
Sign in to follow this  
Solokiller

Simplest way to get variable type

This topic is 1386 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
Advertisement

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

:)

 

I'll look into the problem with the GetTypeDeclaration returning the wrong syntax for arrays. That is clearly a bug in the library.

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
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!