Advertisement

Calling a Script Function with Variable Parameter Type

Started by October 14, 2013 02:05 PM
0 comments, last by WitchLord 11 years, 1 month ago

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.

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.

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