[Gambas-devel] GB Macros and Methods

Randall Morgan rmorgan62 at ...176...
Wed Jan 25 01:13:52 CET 2012


Hi,

I've been digging around the various components and trying to piece
together the inner workings. I'm far from done! But I do have a few
questions:

I plan to port the GNU Scientific Library to Gambas (GSL) using C. The GSL
is a collection of related high level mathmatic functions. Many of which
require vectors and matrices.
I want these to appear to Gambas as gb.GSL.<class>, where class is one of
the GSL's many classes shuch as "math" for generic mathimatical methods
like special implementations of POW().
It is desired to be able to use the library in Gambas as
gb.GSL.math.IntPow2(2) which should return a float (double in C) to the
caller. The function takes in integer as the argument.

With this info in had, it appears that much of this can be done by creating
C function wrapped in BEGIN_METHOD()/END_METHOD macros, i.e.:

BEGIN_METHOD(INTPOW2, GB_INTEGER x)
   // Return x^2 using a small int safe method
   // call gsl native function double gsl_pow_2(int x)
   GB.ReturnFloat(gsl_pow(VARG(x)))
END_METHOD


In the header file I need to used the DECLARE_METHOD() to expose the
methods to Gambas:

DECLARE_METHOD(INTPOW2)


Next, in the class file, I need to expose the class to Gambas using the
Class Desc macro:

GB_DESC CMath[] =
{
    /* Describe the math class to Gambas */
    GB_DECLARE("CMath",0), GB_NOT_CREATABLE(),

}

Can you explain the params and the use of GB_STATIC_PROPERTY,
GB_STATIC_PROPERTY_SELF, GB_STATIC_METHOD, GB_STATIC_FAST_METHOD,
GB_INTERFACE?

Where does the ID come from in GB_INHERITS?

Somewhere I need to expose the various classes to GAMBAS. I think the in
the main or base class file?

GB_DESC *GB_CLASSES[] EXPORT =
{
    /* GSL */
    CGsl,

    /* GSL.MATH */
    CMath,

    /* GSL.STAT */
    CStatistics,

    /* GSL.MATRIX */
    CMatrix,

     ...

    /* GSL.POLYNORMAL */
    CPoly,

    NULL // Looks like all GB_DESC must end with NULL?
};

Am I way off base here or on the right track?

Ok, I know this is a lot to ask. So I'll make you a deal. If you help me to
understand all this I will write an English tutorial for creating
components using C/C++.


Thanks,

Randall

-- 
If you ask me if it can be done. The answer is YES, it can always be done.
The correct questions however are... What will it cost, and how long will
it take?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/devel/attachments/20120124/b1380f3f/attachment.html>


More information about the Devel mailing list