Hacker Read top | best | new | newcomments | leaders | about | bookmarklet login

Without knowing any more specifics about your problem it seems like this would be possible in Nim. It is cross platform and can generate dynamic libraries across them. I guess you could somehow also set up a static library, but I've never tried that myself. So as long as your target language(s) have the ability to use dynamic libraries then Nim should be able to supply them.


sort by: page size:

Congrats to the team!

Could Nim be used to generate a framework for Xcode and the the same code be used in a Windows C++ or .NET project?

I've been looking for ages for a cross platform solution that can be used to create dynamic or static libraries that isn't C++.


AFAIK Nim can use C and C++ libs so yeah, in principle you should be able to produce a cross platform GUI.

Yes, it's compiled into two different libraries. Nim hasn't magically made cross-platform dynamic libraries. But the code for both libraries is the same, just compiled for two different platforms.

Nim supports dynamic libraries as well and that is very important for security.

As far as I know, that should be doable. Nim can compile to Objective C as well as C++, and has a `when` statement that makes it easy to produce code for a specific OS or language target. Not an Xcode or .NET expert though, so not sure how difficult it is to hook into those platforms.

Yes, Nim is static, however I've been told using lots of type inference and unions it can get almost the ease of use of dynamic languages. I never did something with it so far though, so I can't say whether that really holds up. My main concern would still be libraries - hard to beat python or the JVM in that regard I think.

As the others have said it should be possible. Nim is already pretty good at cross-compiling, but it is also able to just spit out the C files it generates and allow you to play with those.

For the specific case of Python executing Nim code you might be interested in [nimporter](https://github.com/Pebaz/nimporter) instead. Genny would definitely work for you as well, but it seems to be more geared towards creating libraries in Nim that can be imported by multiple languages.

If you provide a C library then it'll be super easy to add Nim support!

Whilst there is a pretty well fleshed out stdlib, since Nim can compile to C, C++, Javascript, and even LLVM, you can use any library written for those languages/platforms. That's a huge mass of ecosystems that are natively accessible.

Nim's FFI is excellent and makes this very easy without worrying about the ABI (since you're compiling to the target languages).

There's also excellent interop with Python with embedding Python within Nim or calling Nim from Python.


This seems quite possible from everything I've explored, and also is something I want to try soon. It's also interesting to use Nim through JS for a scripting layer for an application written in Nim; where they both communicate through shared data structures or something.

Here's a repo I found: https://github.com/Jipok/Nim-SDL2-and-Emscripten


I want to use Nim.

As is , Nim already supports a bunch of different scripting languages.


Afaik with Nim you have access to the C and C++ libraries.

This, for sure. For my work I wrote a dynamic library in Nim. The library is loaded by an application written in C, and I needed it to work on both Windows and Linux (Windows for customers, Linux for myself and the server back-end). Setting up a Docker container that runs the entire build and integrates well into the existing build-system we had was fairly straight forward. All Nim needs to cross-compile is a C compiler that can do it (in my case that was MinGW). So now I'm happily running the same Nim dynamic library compiled to both a DLL and a .so.

Nim has a powerful templating system that allows introducing new syntactic elements and semantics, but maybe you are thinking about generating output code in multiple languages (C, C++, JS...)?

what about nim, already works great with c++, easy to integrate with existing c++, python style syntax, seems like a really good, production ready option to me

That sounds a lot like Nim. I haven’t used it myself, but I’m intrigued at the idea of having one language I can use in a lot of places.

For what it's worth, wrapping C++ in Nim is pretty trivial so you could use this fairly easily with Nim.

Nim compiles to C, so can at least make use of fast C compilers. But the solution really seems to be to just use a fully dynamic language like Common Lisp that can compile, load, and redefine (hotswap) everything incrementally so you're not having to start from nothing all the time.
next

Legal | privacy