Jump to content
  • Advertisement
Sign in to follow this  
p_k

AngelScript - Don't support passing type 'X' by value to application

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm exposing this API to the scriptable environment:


struct Argb
{
uint32_t v;
};

struct Image
{
err_t clear(Argb);
};



Is this possible without wrappers? When registering Image::clear() method I get an error:


ERR : (0, 0) : Don't support passing type 'Argb' by value to application


I'm using this to register Argb and Image:


_TYPE("Argb", Argb, asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_CA);
_TYPE("Image", Image, asOBJ_VALUE | asOBJ_APP_CLASS_CDA);

_METHODM("err clear(Argb)", Image, clear, err_t, (Argb));

// The _TYPE and _METHODM are macros.
#define _REG(code) do { int _Result = (code); assert(_Result >= 0); } while (0)

#define _TYPE(name, type, flags) _REG(engine->RegisterObjectType(name, sizeof(type), flags))

#define _METHODM(prototype, c, m, r, p) _REG(engine->RegisterObjectMethod(_T, prototype, asMETHODPR(c, m, p, r), asCALL_THISCALL))



Problem is that it's passed as a value, on x64 platform this means passing it through register.

Share this post


Link to post
Share on other sites
Advertisement
The author of as_callfunc_x64_gcc.cpp (gargltk) put in a comment that describes well, why this is not supported on this target platform:


/* I currently know of no way we can predict register usage for passing complex
objects by value when the compiler does not pass them by reference instead. I
will quote the example from the AMD64 ABI to demonstrate this:

(http://www.x86-64.org/documentation/abi.pdf - page 22)

------------------------------ BEGIN EXAMPLE -------------------------------

Let us consider the following C code:

typedef struct {
int a, b;
double d;
} structparm;

structparm s;
int e, f, g, h, i, j, k;
long double ld;
double m, n;

extern void func (int e, int f,
structparm s, int g, int h,
long double ld, double m,
double n, int i, int j, int k);

func (e, f, s, g, h, ld, m, n, i, j, k);

Register allocation for the call:
--------------------------+--------------------------+-------------------
General Purpose Registers | Floating Point Registers | Stack Frame Offset
--------------------------+--------------------------+-------------------
%rdi: e | %xmm0: s.d | 0: ld
%rsi: f | %xmm1: m | 16: j
%rdx: s.a,s.b | %xmm2: n | 24: k
%rcx: g | |
%r8: h | |
%r9: i | |
--------------------------+--------------------------+-------------------
*/







To make it possible for AngelScript to know how to pass these kind of objects by value to the host application it would be necessary to tell AngelScript the exact type of each member in the structure. Only then would AngelScript be able to know how to load each member into the correct register as expected by the application.

For the simple Argb type that you have, you may experiment with fooling AngelScript into believing the type is a simple UINT, i.e.


_TYPE("Argb", Argb, asOBJ_VALUE | asOBJ_POD | asOBJ_APP_PRIMITIVE);


Regards,
Andreas

Share this post


Link to post
Share on other sites
Thanks for hint!

asOBJ_APP_PRIMITIVE didn't helped, but it's not issue for me. I only wanted to know if I'm doing something wrong or whether there is limitation I should know about.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!