frostwire / frostwire-jlibtorrent

A swig Java interface for libtorrent by the makers of FrostWire. Develop libtorrent based apps with the joy of coding in Java.
http://www.frostwire.com
MIT License
458 stars 139 forks source link

Is it possible use your libtorrent.i wrap a c# version? #283

Closed ycy1164656 closed 1 year ago

ycy1164656 commented 1 year ago

I am making a wpf client ,and will use libtorrent,I'm wondering if it is possible to use your swig/libtorrent.i to create a c# version ? Thx .

gubatron commented 1 year ago

if swig support C# I'm sure it's possible, it'd be cool if you'd help us with that.

Ideally the C# high level abstraction layer should mimic the current high level abstraction classes we've created in Java, aside from all the automatic wrapping that swig does for us.

Apparently Swig does support C# https://www.swig.org/Doc3.0/CSharp.html#CSharp_introduction_swig2_compatibility

but I think there are some differences and we'll have to have a second libtorrent.c_sharp.i

ycy1164656 commented 1 year ago

if swig support C# I'm sure it's possible, it'd be cool if you'd help us with that.

Ideally the C# high level abstraction layer should mimic the current high level abstraction classes we've created in Java, aside from all the automatic wrapping that swig does for us.

Apparently Swig does support C# https://www.swig.org/Doc3.0/CSharp.html#CSharp_introduction_swig2_compatibility

but I think there are some differences and we'll have to have a second libtorrent.c_sharp.i

I modified libtorrent.i file like this :

libtorren.i.txt

mainly modified

` %define TYPE_INTEGRAL_CONVERSION_EX(name, underlying_type, api_type, java_type) %typemap(ctype) name, const name& "java_type" %typemap(imtype) name, const name& "java_type" %typemap(cstype) name, const name& "java_type"

%typemap(in) name { $1 = name(static_cast($input)); } %typemap(out) name { $result = static_cast(static_cast($1)); } %typemap(csin) name, const name& "$csinput" %typemap(csout) name, const name& { return $imcall; } %enddef `

then I copied libtorrent 1.2.18 include directory and boost to swig directory,

and I run swig -c++ -csharp libtorrent.i ,

but I got this error

boost\system\system_error.hpp(20) : Error: Syntax error in input(1)

do you have any idea what may cause this error?

ycy1164656 commented 1 year ago

by the way, I used swig 4.1

ycy1164656 commented 1 year ago

by the way, I used swig 4.1

ps. this error 'boost\system\system_error.hpp(20) : Error: Syntax error in input(1)' also occured when I run swig -c++ -java libtorrent.i(the origin libtorrent.i)

gubatron commented 1 year ago

running swig on that file has certain requirements in environment variables carrying different paths.

Look at the build-xxx scripts in the swig directory

gubatron commented 1 year ago

You should use swig 4.0.1, I just had it break by running the wrong version.

gubatron commented 1 year ago
/usr/local/bin/swig -version

SWIG Version 4.0.1
gubatron commented 1 year ago

4.0.2 works as well

gubatron commented 1 year ago

just tested with swig 4.1.0 and it breaks. The libtorrent.i would probably need to be updated to make it work with 4.1.0, but that's not really our priority, make sure you have swig 4.0.2 and you should be able to move forward.

gubatron commented 1 year ago

I've made it so that it works with swig 4.1.0

This was the issue. On boost/system/system_error.hpp:20

class BOOST_SYMBOL_VISIBLE system_error: public std::runtime_error

swig couldn't recognize BOOST_SYMBOL_VISIBLE

Screenshot 2023-02-27 at 10 59 35 PM

ycy1164656 commented 1 year ago

👍🏻