Advertisement

Call function with primitive ref parameter from C++

Started by January 15, 2018 10:26 PM
3 comments, last by Michael Mahn 6 years, 10 months ago

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
  • using SetArgObject instead

OS: Ubuntu16.04 64 bit

Compiler: Gnu C++ Compiler

Angelscript version: 2.32.0

Can somebody help me on this?

Thanks and Regards

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;
ctx->SetArgAddress(3, &val);

 

I use SetArgAddress for these arguments.

Advertisement

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

I'll correct the documentation.

 

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

Oh wow, totally missed that.

Thanks

This topic is closed to new replies.

Advertisement