I assume you do this in the init method.  Create the wrappered object
(using either NewPointer() or NewBuffer(), depending on the style that
would work best), anchor the object in the variable CSELF using
SetObjectVariable().  From that point on, you get this object
unwrapped to a void * pointer for you automatically buy specifying an
argument type of CSELF.

The stream class uses this.  For example, here's the code in the init method:

RexxMethod2(RexxObjectPtr, stream_init, OSELF, self, CSTRING, name)
{
    // create a new stream info member
    StreamInfo *stream_info = new StreamInfo(self, name);
    RexxPointerObject streamPtr = context->NewPointer(stream_info);
    context->SetObjectVariable("CSELF", streamPtr);

    return NULLOBJECT;
}

Then the rest of the methods have a similar prolog:

RexxMethod3(size_t, stream_charout, CSELF, streamPtr,
OPTIONAL_RexxStringObject, data, OPTIONAL_int64_t, position)
{
    StreamInfo *stream_info = (StreamInfo *)streamPtr;


Where the native pointer gets passed to the method directly as an argument.

If you have cooperating objects where one object needs to have access
to the native value backing the other, the ObjectToCSelf() API can be
used to obtain the same pointer value that would be passed in to a
method using CSELF.

Rick

On Wed, Jul 30, 2008 at 3:35 PM, David Ashley <[EMAIL PROTECTED]> wrote:
> Rick -
>
> Ok, what I don't get is how to assign a value to CSELF. I create C objects
> in RexxGTK and I need to save the value of the pointer so I can fetch it
> later in other methods. Can you give me an example?
>
> Thanks,
> W. David Ashley
> IBM Systems and Technology Group Lab Services
> Open Object Rexx Team
> Mobile Phone: 512-289-7506
>
>
> "Rick McGuire" ---07/27/2008 04:03:16 PM---Yes, that's exactly what I'm
> proposing. When you lay out it the way
>
> "Rick McGuire" <[EMAIL PROTECTED]>
> Sent by: [EMAIL PROTECTED]
>
> 07/27/2008 04:02 PM
>
> Please respond to
> Open Object Rexx Developer Mailing List <oorexx-devel@lists.sourceforge.net>
>
> To
> "Open Object Rexx Developer Mailing List"
> <oorexx-devel@lists.sourceforge.net>
> cc
>
> Subject
> Re: [Oorexx-devel] A potential improvement to the native APIs.
> Yes, that's exactly what I'm proposing.  When you lay out it the way
> you just did, it's a fairly spectactular difference, isn't it.  I'll
> see if I can whip something up.
>
> Rick
>
> On Sun, Jul 27, 2008 at 5:00 PM, Mark Miesfeld <[EMAIL PROTECTED]> wrote:
>> On Sun, Jul 27, 2008 at 1:35 PM, Rick McGuire <[EMAIL PROTECTED]>
>> wrote:
>>> Mark's recent questions about his RECT class sort of triggered a
>>> thought ...
>>
>>> 2)  An ObjectToCSelf() API that can extract the CSELF information for
>>> another object would allow objects primarily implemented as native
>>> code to operate together better.  This will return NULL if not CSELF
>>> variable is found in any scope of the instance.
>>
>> So with the above ObjectToCSelf(), instead of doing this:
>>
>> bool rxGetRect(RexxMethodContext *context, RexxObjectPtr r, int
>> argPos, RECT *rect)
>> {
>>    RexxClassObject RectClass = context->FindContextClass("RECT");
>>    if ( ! context->IsInstanceOf(r, RectClass) )
>>    {
>>        goto errReturn;
>>    }
>>
>>    RexxObjectPtr i = context->SendMessage0(r, "LEFT");
>>    if ( i == NULLOBJECT || ! context->IsInteger(i) )
>>    {
>>        goto errReturn;
>>    }
>>    context->ObjectToNumber(i, &rect->left);
>>
>>    i = context->SendMessage0(r, "TOP");
>>    if ( i == NULLOBJECT || ! context->IsInteger(i) )
>>    {
>>        goto errReturn;
>>    }
>>    context->ObjectToNumber(i, &rect->top );
>>
>>    i = context->SendMessage0(r, "RIGHT");
>>    if ( i == NULLOBJECT || ! context->IsInteger(i) )
>>    {
>>        goto errReturn;
>>    }
>>    context->ObjectToNumber(i, &rect->right);
>>
>>    i = context->SendMessage0(r, "BOTTOM");
>>    if ( i == NULLOBJECT || ! context->IsInteger(i) )
>>    {
>>        goto errReturn;
>>    }
>>    context->ObjectToNumber(i, &rect->bottom);
>>
>>    /* Should we enforce positive numbers?
>>    if ( (rect->right >= rect->left) && (rect->bottom >= rect->top) )
>>    {
>>        return true;
>>    }
>>    */
>>    return true;
>>
>>  errReturn:
>>
>>    char buf[256];
>>    _snprintf(buf, sizeof(buf),
>>             "Method argument %d requires a .RECT object with indexes
>> 'left', 'top', 'right, and 'bottom'", argPos);
>>
>>    context->RaiseException1(Rexx_Error_Incorrect_method_user_defined,
>> context->NewStringFromAsciiz(buf));
>>    return false;
>> }
>>
>> I could do something like this:
>>
>> RECT *rxGetRect(RexxMethodContext *context, RexxObjectPtr r, int argPos)
>> {
>>    RECT *pRect;
>>
>>    RexxClassObject RectClass = context->FindContextClass("RECT");
>>    if ( ! context->IsInstanceOf(r, RectClass) )
>>    {
>>        // raise exception
>>    }
>>
>>    pRect = (RECT *)context->ObjectToCSelf(r);
>>
>>    // Let the caller worry about NULL
>>    return pRect;
>> }
>>
>> Based on the above, adding ObjectToCSelf() would get my vote.  <grin>
>>
>> --
>> Mark Miesfeld
>>
>> -------------------------------------------------------------------------
>> This SF.Net email is sponsored by the Moblin Your Move Developer's
>> challenge
>> Build the coolest Linux based applications with Moblin SDK & win great
>> prizes
>> Grand prize is a trip for two to an Open Source event anywhere in the
>> world
>> http://moblin-contest.org/redirect.php?banner_id=100&url=/
>> _______________________________________________
>> Oorexx-devel mailing list
>> Oorexx-devel@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/oorexx-devel
>>
>
> -------------------------------------------------------------------------
> This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
> Build the coolest Linux based applications with Moblin SDK & win great
> prizes
> Grand prize is a trip for two to an Open Source event anywhere in the world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> _______________________________________________
> Oorexx-devel mailing list
> Oorexx-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/oorexx-devel
>
>
> -------------------------------------------------------------------------
> This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
> Build the coolest Linux based applications with Moblin SDK & win great
> prizes
> Grand prize is a trip for two to an Open Source event anywhere in the world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> _______________________________________________
> Oorexx-devel mailing list
> Oorexx-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/oorexx-devel
>
>

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Oorexx-devel mailing list
Oorexx-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/oorexx-devel

Reply via email to