Author Topic: Extension Module Builder  (Read 366 times)

Offline John

  • Forum Support / SB Dev
  • Posts: 2752
    • ScriptBasic Open Source Project
Extension Module Builder
« 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.


Offline AIR

  • BASIC Developer
  • Posts: 685
Re: Extension Module Builder
« Reply #1 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.

Offline John

  • Forum Support / SB Dev
  • Posts: 2752
    • ScriptBasic Open Source Project
Re: Extension Module Builder
« Reply #2 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,

Offline AIR

  • BASIC Developer
  • Posts: 685
Re: Extension Module Builder
« Reply #3 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



Offline John

  • Forum Support / SB Dev
  • Posts: 2752
    • ScriptBasic Open Source Project
Re: Extension Module Builder
« Reply #4 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.
« Last Edit: June 18, 2019, 06:26:44 PM by John »

Offline AIR

  • BASIC Developer
  • Posts: 685
Re: Extension Module Builder
« Reply #5 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.

Offline John

  • Forum Support / SB Dev
  • Posts: 2752
    • ScriptBasic Open Source Project
Re: Extension Module Builder
« Reply #6 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.