Re: New SWIG python user with a quick question

Julien Marrec <[email protected]> Tue, 5 Mar 2024 11:02:47 +0100
Newsgroups gmane.comp.programming.swig
Message-ID <CAEqKKtwz9uXFz-u1m_yYfOFxEwmDOghM3rtrt0XXf4UbWJtunA@mail.gmail.com>
--===============3664168999205393806==
Content-Type: multipart/alternative; boundary="0000000000005dfcc10612e6f2bf"

--0000000000005dfcc10612e6f2bf
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Hello Mark,

You can just import the header(s) into the .i file. Something like this:

```
%module hello

%{
#include "hello.h"
%}

%include "hello.h"
```

Hope this helps,
--
Julien Marrec, EBCP, BPI MFBA
Owner at EffiBEM <http://www.effibem.com>
T: +33 6 95 14 42 13

LinkedIn (en <https://www.linkedin.com/in/julienmarrec>) *| *(fr
<https://fr.linkedin.com/in/julienmarrec/fr>) :
<http://www.linkedin.com/in/julienmarrec>


Le sam. 2 mars 2024 =C3=A0 09:41, marksibly via Swig-user <
[email protected]> a =C3=A9crit :

> Hi,
>
> I am new to SWIG but have it up and running and producing a python wrappe=
r
> for my C library after only a few hours work/googling!
>
> A quick question (more are likely to follow) - is it possible to get SWIG
> to just use my header files directly instead of having to declare
> everything a second time in the .i?
>
> The headers contain very boring 'C' code, although I do typedef int to a
> number of handle types. I did notice SWIG dealt with my 'typedef const
> char* SGD_String' no problem though, so I assume it knows what my typedef=
s
> mean.
>
> All functions are consistently prefixed with sgd_ and all types and macro=
s
> with SGD_ (there are actually only the int handle types right now - would
> SGD_Bool, SGD_Int be a problem?).
>
> It's not a huge amount of work maintaing the .i, although it's the 3rd se=
t
> I'll have to deal without as I'm supporting another language not supporte=
d
> by SWIG. I guess I could also write something to convert the .h's to a .i=
,
> is this common practice?
>
> Oh, one other quicky: is it possible to generate wrappers for Javascript
> in a node.js environment?
>
> Anyway, loving SWIG so far, nice job!
>
> Bye,
> Mark
>
>
> _______________________________________________
> Swig-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/swig-user
>

--0000000000005dfcc10612e6f2bf
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>Hello Mark,</div><div><br></div><div>You can just imp=
ort the header(s) into the .i file. Something like this:</div><div><br></di=
v><div>```<br></div><div><table class=3D"gmail-highlight gmail-tab-size gma=
il-js-file-line-container gmail-js-code-nav-container gmail-js-tagsearch-fi=
le"><tbody><tr><td id=3D"gmail-file-hello-i-LC1" class=3D"gmail-blob-code g=
mail-blob-code-inner gmail-js-file-line">%module hello</td>
        </tr>
        <tr>
          </tr></tbody></table><table class=3D"gmail-highlight gmail-tab-si=
ze gmail-js-file-line-container gmail-js-code-nav-container gmail-js-tagsea=
rch-file"><tbody><tr><td id=3D"gmail-file-hello-i-LC2" class=3D"gmail-blob-=
code gmail-blob-code-inner gmail-js-file-line">
<br></td>
        </tr>
        <tr>
          </tr></tbody></table><table class=3D"gmail-highlight gmail-tab-si=
ze gmail-js-file-line-container gmail-js-code-nav-container gmail-js-tagsea=
rch-file"><tbody><tr><td id=3D"gmail-file-hello-i-LC3" class=3D"gmail-blob-=
code gmail-blob-code-inner gmail-js-file-line">%{</td>
        </tr>
        <tr>
          </tr></tbody></table><table class=3D"gmail-highlight gmail-tab-si=
ze gmail-js-file-line-container gmail-js-code-nav-container gmail-js-tagsea=
rch-file"><tbody><tr><td id=3D"gmail-file-hello-i-LC4" class=3D"gmail-blob-=
code gmail-blob-code-inner gmail-js-file-line">#<span class=3D"gmail-pl-k">=
include</span> <span class=3D"gmail-pl-s"><span class=3D"gmail-pl-pds">&quo=
t;</span>hello.h<span class=3D"gmail-pl-pds">&quot;</span></span></td>
        </tr>
        <tr>
          </tr></tbody></table><table class=3D"gmail-highlight gmail-tab-si=
ze gmail-js-file-line-container gmail-js-code-nav-container gmail-js-tagsea=
rch-file"><tbody><tr><td id=3D"gmail-file-hello-i-LC5" class=3D"gmail-blob-=
code gmail-blob-code-inner gmail-js-file-line">%}</td>
        </tr>
        <tr>
          </tr></tbody></table><table class=3D"gmail-highlight gmail-tab-si=
ze gmail-js-file-line-container gmail-js-code-nav-container gmail-js-tagsea=
rch-file"><tbody><tr><td id=3D"gmail-file-hello-i-LC6" class=3D"gmail-blob-=
code gmail-blob-code-inner gmail-js-file-line">
<br></td>
        </tr>
        <tr>
          </tr></tbody></table>%include <span class=3D"gmail-pl-s"><span cl=
ass=3D"gmail-pl-pds">&quot;</span>hello.h<span class=3D"gmail-pl-pds">&quot=
;</span></span></div><div>```</div><div><span class=3D"gmail-pl-s"><span cl=
ass=3D"gmail-pl-pds"><br></span></span></div><div><span class=3D"gmail-pl-s=
"><span class=3D"gmail-pl-pds">Hope this helps,<br></span></span></div><div=
><div><div dir=3D"ltr" class=3D"gmail_signature" data-smartmail=3D"gmail_si=
gnature"><div dir=3D"ltr"><div><div dir=3D"ltr"><div><div dir=3D"ltr"><div>=
--<br>Julien Marrec, EBCP, BPI MFBA<br>Owner at <a href=3D"http://www.effib=
em.com" target=3D"_blank">EffiBEM</a><br>T: +33 6 95 14 42 13<br><span styl=
e=3D"color:rgb(0,0,0)"><br></span><span style=3D"color:rgb(0,0,0)">LinkedIn=
 (<a href=3D"https://www.linkedin.com/in/julienmarrec" target=3D"_blank">en=
</a>)<span style=3D"color:rgb(0,0,0)"> <i>| </i></span>(<a href=3D"https://=
fr.linkedin.com/in/julienmarrec/fr" target=3D"_blank">fr</a>) : </span><br>=
<span style=3D"color:rgb(0,0,0)"><a href=3D"http://www.linkedin.com/in/juli=
enmarrec" target=3D"_blank"></a></span></div></div></div></div></div></div>=
</div></div><br></div></div><br><div class=3D"gmail_quote"><div dir=3D"ltr"=
 class=3D"gmail_attr">Le=C2=A0sam. 2 mars 2024 =C3=A0=C2=A009:41, marksibly=
 via Swig-user &lt;<a href=3D"mailto:[email protected]">swig-=
[email protected]</a>&gt; a =C3=A9crit=C2=A0:<br></div><blockquote=
 class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px so=
lid rgb(204,204,204);padding-left:1ex"><u></u><div><div style=3D"font-famil=
y:Verdana,Arial,Helvetica,sans-serif;font-size:10pt"><div>Hi,<br></div><div=
><br></div><div>I am new to SWIG but have it up and running and producing a=
 python wrapper for my C library after only a few hours work/googling!<br><=
/div><div><br></div><div>A quick question (more are likely to follow) - is =
it possible to get SWIG to just use my header files directly instead of hav=
ing to declare everything a second time in the .i?<br></div><div><br></div>=
<div>The headers contain very boring &#39;C&#39; code, although I do typede=
f int to a number of handle types. I did notice SWIG dealt with my &#39;typ=
edef const char* SGD_String&#39; no problem though, so I assume it knows wh=
at my typedefs mean.<br></div><div><br></div><div>All functions are consist=
ently prefixed with sgd_ and all types and macros with SGD_ (there are actu=
ally only the int handle types right now - would SGD_Bool, SGD_Int be a pro=
blem?).<br></div><div><br></div><div>It&#39;s not a huge amount of work mai=
ntaing the .i, although it&#39;s the 3rd set I&#39;ll have to deal without =
as I&#39;m supporting another language not supported by SWIG. I guess I cou=
ld also write something to convert the .h&#39;s to a .i, is this common pra=
ctice?<br></div><div><br></div><div>Oh, one other quicky: is it possible to=
 generate wrappers for Javascript in a node.js environment?<br></div><div><=
br></div><div>Anyway, loving SWIG so far, nice job!<br></div><div><br></div=
><div>Bye,<br></div><div>Mark<br></div><div><br></div></div><br></div>_____=
__________________________________________<br>
Swig-user mailing list<br>
<a href=3D"mailto:[email protected]" target=3D"_blank">Swig-u=
[email protected]</a><br>
<a href=3D"https://lists.sourceforge.net/lists/listinfo/swig-user" rel=3D"n=
oreferrer" target=3D"_blank">https://lists.sourceforge.net/lists/listinfo/s=
wig-user</a><br>
</blockquote></div>

--0000000000005dfcc10612e6f2bf--


--===============3664168999205393806==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline


--===============3664168999205393806==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Swig-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/swig-user

--===============3664168999205393806==--