All BASIC

Message Boards => Scripting Languages => Topic started by: John on June 17, 2019, 08:23:47 PM

Title: Extension Module Builder
Post by: John on June 17, 2019, 08:23:47 PM
It seems that I do a lot of repetitive work building extension modules that could be easily automated with a header file parser. Or just pass it a list of exported function definitions. One could create an extension module with no knowledge of C programming.

Title: Re: Extension Module Builder
Post by: AIR on June 18, 2019, 03:20:40 PM
I don't think you'll ever be able to get away from having to use/know C.
Practically speaking, I think the best you can do would be to generate a template based on your second suggestion, passing a list of exported functions.  Done right, it could generate quite a bit of 'boilerplate' code, but you would still need to implement the actual functionality.
Or try your hand at creating an interface for SWIG.
AIR.
Title: Re: Extension Module Builder
Post by: John on June 18, 2019, 03:31:12 PM
I already tried the SWIG route.

I like your idea of passing a list of function declarations and have it do the templating work for you,
Title: Re: Extension Module Builder
Post by: AIR on June 18, 2019, 04:52:12 PM
So how would you go about converting this
Code: C
  1. int slre_match(const char *regexp, const char *buf, int buf_len,
  2.                struct slre_cap *caps, int num_caps, int flags);
  3.  

Into this
Code: C
  1. besFUNCTION(SLRE_MATCH)
  2.   pModuleObject p;
  3.   const char *regexp;
  4.   const char *buf;
  5.   int buf_len;
  6.   struct slre_cap caps[100];
  7.   int num_caps = 100;
  8.   int flags;
  9.  
  10.   p = (pModuleObject)besMODULEPOINTER;
  11.  
  12.  
  13.   besARGUMENTS("zzi")
  14.       &regexp,&buf,&flags
  15.   besARGEND
  16.  
  17.   int ret = slre_match(regexp,buf,strlen(buf),cap,num_caps,flags);
  18.  
  19.   besRETURN_LONG(ret);
  20.  
  21. besEND


Title: Re: Extension Module Builder
Post by: John on June 18, 2019, 06:07:37 PM
The struct curve ball was cruel.  ;D

The IUP API would have been a good candidate for a utility like this.
Title: Re: Extension Module Builder
Post by: AIR on June 18, 2019, 07:08:20 PM
The struct curve ball was cruel.  ;D

The IUP API would have been a good candidate for a utility like this.

Point is that nothing will fully automate a conversion.

When I used SWIG on IUP (for Python), it got me part of the way there but I still had to go in and tweak things.  If I didn't know C, there's no way I could have done that.

AIR.
Title: Re: Extension Module Builder
Post by: John on June 18, 2019, 07:15:50 PM
That was wishful thinking I guess. I have about a half a dozen template functions I use when I build an extension modules. There is a lot of copy / paste going on when building them.