# Calling a Script Function with Variable Parameter Type

This topic is 2105 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I have a function registered as:

engine->RegisterGlobalFunction("void MyFunction(const ?&in)", ..., asCALL_GENERIC);


I would like to call that function from within my application.  I would be happy to either call it with a context:

http://www.angelcode.com/angelscript/sdk/docs/manual/doc_call_script_func.html

or to call it directly by creating an asIScriptGenric-compatible object.

Calling the function with a context seems to work, but I cannot figure out how to establish the argument's type.

I am calling:

context->SetArgAddress(0, &myArg);


but then the call to asIScriptGeneric::GetArgTypeId(0, ...) returns asTYPEID_VOID.

It looks like there is a secret "typeid" argument at the next stack position, but the following calls do not work:

context->SetArgAddress(0, &myArg);
context->SetArgDWord(1, myTypeId);


because the function only takes one argument.

Should there be a "SetArgTypeId" function, a "SetArgQuestion" function, or am I missing something?

Thanks.

##### Share on other sites

I think you just hit a gap in the solution. I haven't thought about how to call a function with the generic calling convention and variable argument types from the application side. To do this the context would need to have a SetArgAndType() so that you can inform both the value and its type at the same time. I'll have to implement that for a future version.

If you instead implement your C++ function using native calling convention you can call it directly. The variable arg ? in AngelScript is represented by a pair of arguments in C++, first a void * to the value and then a int for the typeId.

You can take a look at the any add-on or dictionary add-ons to see how to implement these type of functions.

• 18
• 19
• 11
• 21
• 16