I’m wrapping libwebsockets in Julia for better integration and performance. Unfortunately, I didn’t find it in JuliaBinaryWrappers. After that i want to introduce simpler analogue for HTTP.jl based on this c lib (previously i tried libcurl, however, there is no websocket support). Do you have any advices? This is my first time wrapping lib myself (before that I used libCurl_jll)
I’m sure that the right thing to do is to use something like Clang.jl to generate the wrapper for you. I don’t know much about it, even though I have drug my eyes over the documentation a few times.
If you are mildly masochistic, you can write Julia analogs of the structures used, and call all of the library functions from Julia using @ccall
. I have a semi-large-ish C++ library that I have wrapped that way. I don’t have any experience with libwebsockets
, but it looks semi-large. Probably large enough to make fussing around with Clang worthwhile.
Here is my example code (in this Discourse link). Since you are wrapping C, you wouldn’t need to have a C library wrapper layer. I do recommend that you get bindings autogenerated, rather than doing it manually though.
And what about BinaryBuilder? Or is this previous stage before using Clang.jl to generate wrapper?
You may be right - I haven’t successfully used Clang.jl before.
Also, have you seen: GitHub - JuliaWeb/WebSockets.jl: A WebSockets library for Julia?
Both are kind of necessary steps. I prefer doing the binarybuilder one first because it tends to make the following steps a lot easier though nothing stops you from building the wrapper with a local build.
Any news @DeevsDeevs ?
I noticed GitHub - maxfadson/libwebsockets_jll.jl and GitHub - JuliaBinaryWrappers/libwebsockets_jll.jl are now available.
I published a project skeleton for LibWebsockets.jl https://github.com/femtotrader/LibWebsockets.jl
$ cd gen/
$ julia --project=. generator.jl
can generate code in lib/wrapper.jl
but I’m still locked trying to compile it using
cd ..
julia --project=. test/runtests.jl
with the following error
ERROR: LoadError: UndefVarError: lws_plat_file_ops
not defined in LibWebsockets.LibWebsocketsWrapper
Feel free to look at it, fork and improve code.
Maybe you had an old version of the code loaded? For me the package loads and the tests pass.
is now released.
That’s not my code (mine is now still available at GitHub - femtotrader/WIP_LibWebsockets.jl: Julia wrapper for https://libwebsockets.org/). Thanks bhft guys for their contribution to open source.
my personal advice: just don’t use julia for anything web / trading related
It sounds as a quite definitive answer. May I ask why?
I don’t know about him, but I don’t want to go back to a language without multiple dispatch. It makes me want to use Julia despite the lack of mature libraries in the algorithmic trading space. Just last night, I got a prototype of a strategy execution system working, and I used HierarchicalStateMachines.jl in combination with Rocket.jl to do it.
I’m a fan of state machines, and I find it very satisfying to see them work, because they can define behavior so precisely. However, this was my first time seeing a state machine implemented with multiple dispatch, and the satisfaction I got from seeing that is …probably a bit too much, but it’s so great. The code is so much smaller than what I had done in other languages in the past, and it was because I was able to dispatch on types from the Rocket side AND types on the HSM side at the same time. Without multiple dispatch, I couldn’t have done that. The only other language that might have allowed this kind of design is Common Lisp, but I like Julia more.
I like the new kinds of design that multiple dispatch allows.
At first, it felt unfamiliar, but I got used to it quickly. When I tried to describe it to others, I called it “fine-grained polymorphism”. Things that might have been awkward to impossible in single dispatch suddenly became possible AND often simple too.
There’s no going back.
This is too good to leave.