[Gambas-devel] component docs

Ken Schrock schrockk at ...26...
Tue Jun 10 17:23:38 CEST 2003


Rob wrote:

>On Tuesday 10 June 2003 06:59, Ken Schrock wrote:
>
>>Where are docs for all the GB.xxx type calls?
>>
>There are none but whatever's in that example code.  I'm hoping to use 
>whatever you come up with for the socket component (or whichever) and your 
>conversations with Benoit on the list to somehow expand that example code's 
>comments into documentation ;)
>

I will do the docs

Email my schrockk at ...41... account with your e-mail address
And I will send you this stuff (small package , 28k tar.gz)
Here is the code parts, readme follows, to test in app
Class is generic, do NEW Generic(int, int)
Properties are data1 (read-only) & data2
Method called swap takes int, returns int
p.s. gb.generic.help can be blank

/*** main.h ***/

#ifndef __MAIN_H
#define __MAIN_H

#include "gambas.h"

#ifndef __MAIN_C

extern GB_INTERFACE GB;

#else

static void hook_main(int *argc, char **argv);

#endif /* __MAIN_C */
#endif /* __MAIN_H */

/*** main.c ***/

#define __MAIN_C

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>

#include "CGeneric.h"
#include "main.h"

#ifdef __cplusplus
extern "C" {
#endif

GB_INTERFACE GB;

GB_DESC *GB_CLASSES[] =
{
  CGenericDesc, NULL
};

int GB_INIT(void)
{
  GB.Hook(GB_HOOK_MAIN, (void *)hook_main);
  return 0;
}

void GB_EXIT()
{
}

void GB_INFO(int info, void **result)
{
  switch (info)
  {
    case GB_INFO_CONTROL:

      *result = (void *)NULL;
      break;

    case GB_INFO_REQUIRE:

      *result = (void *)NULL;
      break;
  }
}

#ifdef _cpluscplus
}
#endif

static void hook_main(int *argc, char **argv)
{
  int i;

  printf("gb.generic: argc = %d\n", *argc);
  for (i = 0; i < *argc; i++)
    printf("gb.generic: argv[%d] = \"%s\"\n", i, argv[i]);
}


/*** CGeneric.h ***/

#ifndef __CGENERIC_H
#define __CGENERIC_H

#include "gambas.h"

#ifndef __CGENERIC_C

extern GB_DESC CGenericDesc[];

#else

#define THIS ((CGENERIC *)_object)

#endif

typedef
  struct {
    GB_BASE ob;
    long data1;
    long data2;
    }
  CGENERIC;

#endif

/*** CGeneric.c ***/

#define __CGENERIC_C

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>

#include "main.h"

#include "CGeneric.h"


//DECLARE_EVENT(FirstEvent);
//DECLARE_EVENT(SecondEvent);

//  Read Only Property
BEGIN_PROPERTY(CGENERIC_data1)
  GB.ReturnInteger(THIS->data1);
END_PROPERTY

//  Standard Property
BEGIN_PROPERTY(CGENERIC_data2)
  if (READ_PROPERTY)
  {
    GB.ReturnInteger(THIS->data2);
  }
  else
  {
    THIS->data2 = VPROP(GB_INTEGER);
  }
END_PROPERTY

//  A method that takes no params
BEGIN_METHOD_VOID(CGENERIC_free)
  /* Nothing to do, at least here */
END_METHOD

//  A method that does take params
BEGIN_METHOD(CGENERIC_new, GB_INTEGER data1; GB_INTEGER data2)
  THIS->data1 = VARG(data1);
  THIS->data2 = VARG(data2);
END_METHOD

//  A method that takes param and returns a value
BEGIN_METHOD(CGENERIC_swap, GB_INTEGER data)

  int i;

  i = THIS->data2;
  THIS->data2 = VARG(data);
  GB.ReturnInteger(THIS->data2);

END_METHOD

GB_DESC CGenericDesc[] =
{
  GB_DECLARE("Generic", sizeof(CGENERIC)),

  GB_PROPERTY("data2", "i", CGENERIC_data2),
  GB_PROPERTY_READ("data1", "i", CGENERIC_data1),

  GB_METHOD("_free", NULL, CGENERIC_free, NULL),
  GB_METHOD("_new", NULL, CGENERIC_new, "(Data1)i(Data2)i"),
  GB_METHOD("swap", "i", CGENERIC_swap, "(Data)i"),

//  Other examples

//  GB_INHERITS("GenericMother"),
//  GB_VIRTUAL_CLASS(),
//  GB_CONSTANT("AnIntegerConstant", "i", 1972),
//  GB_CONSTANT("AStringConstant", "s", "Gambas"),
//  GB_CONSTANT("AFloatConstant", "f", "3.1415"),
//  GB_METHOD("AMethodThatReturnsNoValue", NULL, do_the_job,
//    
"(FirstParameter)i(SecondParameter)s[(FirstOptionalParameter)ClassName;(SecondOptionalParameter)v]"),
//  GB_METHOD("AMethodThatReturnsAStringAndTakesNoParameter", "s", 
do_another_job, NULL),
//  GB_PROPERTY("AProperty", "s", do_AProperty),
//  GB_STATIC_PROPERTY("AStaticProperty", "i", do_AStaticProperty),
//  GB_READ_PROPERTY("AReadOnlyProperty", "i", do_AReadOnlyProperty),
//  GB_PROPERTY("AnotherProperty", "i<Border>", do_AnotherProperty),
//  GB_PROPERTY("AWellDefinedProperty", "i<Border,None,Plain>", 
do_AWellDefinedProperty),
//  GB_EVENT("FirstEvent", NULL, "(Parameter)i", &FirstEvent),
//  GB_EVENT("SecondEvent", "b", NULL, &SecondEvent),
//  GB_METHOD("_get", "i", CGENERIC_get, "(X)i(Y)i"),
//  GB_METHOD("_put", NULL, CGENERIC_put, "(Value)i(X)i(Y)i"),
//  GB_STATIC_METHOD("_call", NULL, CGENERIC_call, "(Message)s"),

  GB_END_DECLARE
};

/*** readme ***/

Gambas Generic Component

This is a simple Gambas component example
(for those of us [moi] that don't like comments :-)
That could easily be extended to something real

1. @@@  Preliminary stuff
2. &&&&  Binary install
3. $$$$$  Source install

1. @@@  Preliminary stuff

The Gambas working files are various places

/opt/gambas in Mandrake
/usr/gambas in Lindows (Debian variant)

(If you know another place in another distro
  write me and I will add the location to the list)

Binary or source install, you must do the following

Copy this next piece of text

[gb.generic]
Name=A generic component example
Name[fr]=Un plume de composant
Author=schrockk at ...26...

And paste it into the file /(opt or usr)/gambas/lib/component
This lets Gambas know that the component exists

2. &&&&  Binary install

Copy the gb.generic.help file to /(opt or usr)/gambas/lib/help
Copy the gb.generic.info file to /(opt or usr)/gambas/lib/info
Copy the files that start with lib.gb to /(opt or usr)/gambas/lib

Run the Gambas app and play around
(if you copy the Form1.xx files somewhere
  make sure you get the .project [hidden] file)

3. $$$$$  Source install

To start out, put all these files in the Gambas source directory
For the package I have, on Mandrake, this is gambas-0.57/src/lib/generic
( generic won't be there, create it and transfer the files or untar in lib)

Take the file gb.generic.help and put it into gambas-0.57/src/help

Go to gambas-0.57/src/lib directory and open makefile.am
 Change the top line
   SUBDIRS = eval example @DB_SUBDIRS@ @QT_SUBDIRS@
 To
   SUBDIRS = generic eval example @DB_SUBDIRS@ @QT_SUBDIRS@

Go up to the gambas-0.57 directory and open configure.in
Add this line to the list at the bottom of the file

src/lib/generic/Makefile

Inside the gambas-0.57 directory do the following commands

autoconf
automake
./configure
make
make install

Rock and Roll


>-------------------------------------------------------
>This SF.net email is sponsored by:  Etnus, makers of TotalView, The best
>thread debugger on the planet. Designed with thread debugging features
>you've never dreamed of, try TotalView 6 free at www.etnus.com.
>_______________________________________________
>Gambas-devel mailing list
>Gambas-devel at lists.sourceforge.net
>https://lists.sourceforge.net/lists/listinfo/gambas-devel
>
>

-- 
Using Linux Mandrake 8.2
 









More information about the Devel mailing list