Advertisement

Simplest way to get variable type

Started by December 04, 2014 11:34 PM
3 comments, last by WitchLord 9 years, 11 months ago

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.

How about this?

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

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Advertisement

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.

:)

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

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

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.

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