Jump to content
  • Advertisement
Michael Mahn

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
  • 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

Share this post


Link to post
Share on other sites
Advertisement

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.

Edited by Solokiller

Share this post


Link to post
Share on other sites

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

I'll correct the documentation.

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!