Advertisement

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

Started by July 18, 2010 10:38 PM
1 comment, last by p_k 14 years, 4 months ago
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.
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

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

Advertisement
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.

This topic is closed to new replies.

Advertisement