mmomtchev / swig

This is SWIG JavaScript Evolution, a fork of the SWIG project with modern JavaScript/TypeScript support including WASM and async
http://www.swig.org
Other
11 stars 1 forks source link

Support for `std::set` and `std::list` #15

Open dsogari opened 8 months ago

dsogari commented 8 months ago

Sorry to bother you again... :P

It appears that std::set and std::list are not supported for JavaScript, although they are supported for languages such as Java, Ruby and Python. Would it be too difficult to implement this feature? I would definitely tackle this myself if I had enough knowledge of the SWIG codebase. If you can give me some pointers, I could give it a shot.

mmomtchev commented 8 months ago

std::list will be the same as std::vector and in fact the best way to do it is to probably transform the current std::vector maps so that they can be used with any STL that supports forward iterators.

However std::set is much problematic since the JS Set does not have a C++ API, it is a userland implementation and any C++ wrapper will have to call the JS methods.

dsogari commented 8 months ago

Hm, I guess you're right. But isn't it just a matter of providing an interface matching the JS Set, instead of actually using a JS Set? A user might complain about lack of idiomaticity, but at least they can call their functions.

mmomtchev commented 8 months ago

This you can already do: you can simply wrap std::set by using %template(IntegerSet) std::set<int>; and you will get a JavaScript-accessible class called IntegerSet that will be fully usable. But you won't have transparent and automatic conversion of arguments.