Using %attribute with non-builtin type which is wrapped as builtin

Rokas Kupstys via Swig-user <[email protected]> Sun, 31 Jan 2021 10:13:55 +0200
Newsgroups gmane.comp.programming.swig
Message-ID <[email protected]>
Simply put, i have a type "StringHash" which wrapps a single "unsigned 
int". So i have typemaps that use ctype=unsigned. Everything works 
great. Now i want to expose a "StringHash GetType()" getter as an 
attribute. And here everything breaks.

What i get when i use %attribute():

> #define Urho3D_PhysicsWorld2D_Type_get(self_) self_->GetType()    // 
> Signature: StringHash PhysicsWorld2D::GetType()
>
> SWIGEXPORT unsigned SWIGSTDCALL 
> CSharp_Urho3DNet_PhysicsWorld2D_Type_get(void * jarg1) {
>   Urho3D::StringHash *result = 0 ;
>   result = (Urho3D::StringHash *) &Urho3D_PhysicsWorld2D_Type_get(arg1);
>   jresult = result->Value();
>   return jresult;
> }
Wrapper tries to take an address of getter result, but since it is 
returned as an lvalue it is not possible.

What i really need is for wrapper to do something like this:

> SWIGEXPORT int SWIGSTDCALL CSharp_Urho3DNet_Variant_Int_get(void * 
> jarg1) {
>   int result;
>   result = (int)Urho3D_Variant_Int_get(arg1);
>   jresult = result;
>   return jresult;
> }
SWIG already does a right thing for builtin types, and my StringHash 
also acts like a builtin type. It makes no sense to allocate an object 
only to free it immediately. Is there any way i could force wrapper 
generation similar to what i get for int? Namely i need to turn 
"Urho3D::StringHash *" to "Urho3D::StringHash" and get rid of & in 
"&Urho3D_PhysicsWorld2D_Type_get()". As i understand pointer appears 
here because injected member fields are wrapped as T&. It is not 
something i want for this particular type.


-- 
-- Rokas Kupstys




_______________________________________________
Swig-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/swig-user