# Call function with primitive ref parameter from C++

## Recommended Posts

Hi,

I'm trying to call an AS function from C++ with a ref parameter (signature void main(int&in) or void main(int&out)).

According to the documentation this should work:

Quote

If the parameter type is a reference to a primitive type it is recommended to use the SetArgDWord() method and pass the pointer as the value. For non-primitive types the method SetArgObject() should be used, which will be described in the next section.

This is my C++ code:

asDWORD input;
r = ctx->SetArgDWord(0, (asDWORD)&input);

But it returns asINVALID_TYPE and if I execute the function anyway I get an exception although ctx->GetExceptionString() just gives me null.

So I was wondering what am I doing wrong?

Thing I've tried so far:

• Compiling for 32- and 64-bit respectively linking to the 32- and 64-bit library.
• Changing SetArgDWord to SetArgQWord for 64-bit.
• Changing the AS function to void main(int32&in), void main(int64&in), void main(int32&out), void main(int64&out)
• passing input instead of &input

OS: Ubuntu16.04 64 bit

Compiler: Gnu C++ Compiler

Angelscript version: 2.32.0

Can somebody help me on this?

Thanks and Regards

##### Share on other sites

The documentation seems to disagree with itself, just below that is an example of a reference to an int:

// The context has been prepared for a script
// function with the following signature:
// int function(int, double, bool, int &out)
// Put the arguments on the context stack, starting with the first one
ctx->SetArgDWord(0, 1);
ctx->SetArgDouble(1, 3.141592);
ctx->SetArgByte(2, true);
int val;


I use SetArgAddress for these arguments.

Edited by Solokiller

##### Share on other sites

Indeed. The documentation is wrong. The correct is to use SetArgAddress.

I'll correct the documentation.

##### Share on other sites

Oh wow, totally missed that.

Thanks

## Create an account

Register a new account

1. 1
Rutin
23
2. 2
3. 3
JoeJ
20
4. 4
5. 5

• 29
• 40
• 23
• 13
• 13
• ### Forum Statistics

• Total Topics
631739
• Total Posts
3001957
×