Norx - a Nim wrapper of ORX

Hi all!

I recently discovered ORX and I have a game idea I want to make reality. But... I am not that interested in C or C++ - but I do like the up and coming Nim language. I have worked a bit with Nim, making my own little language in it and some other utilities. I also know the creator and the Nim community fairly well - top notch and very sharp people.

So, since ORX is C99 and Nim integrates VERY well with C/C++ I have created a first shot at a wrapper. Nim compiles via C which means the calls to ORX have zero overhead. Nim also produces fast C code so there is seldom any real performance difference. However, Nim is a richer language while being much easier to program in. One can always take a peek at https://nim-by-example.github.io

If one wants to play with it, the best place to start is via my ORX clone at github. The wrapper lives in the subdirectory code/nim:

https://github.com/gokr/orx/tree/master/code/nim/norx

I will try to keep it in sync with the ORX master branch!

I develop on Linux but Nim is cross platform so it should be possible to use Norx on all platforms. There is just a silly port of the "spinning logo" so far, but the wrapper should in theory (modulo bugs of course) be complete because it was in most part autogenerated from the ORX headers. While using it I intend to "smooth things out" making it less "C" and more "Nim".

Any and all comments welcome!

regards, Göran

Comments

  • Hey Göran.

    Nice work on that Nim wrapper for orx. Would you mind if we added a news on the website for it? When you judge it's ready to be announced there, of course.

    Even if I'm not interested in Nim itself anymore (the syntax really isn't for me), I'm sure it'll be much appreciated by others.

    If you were able to move your work into a stand alone repository, I'd be happy to add it (or a fork) to https://github.com/orx (if you're interested, of course, there's no obligation).

  • Hey!

    (hehe, kudos for getting ö right)

    You can mention it of course, although at the moment the wrapper is still 99% one-to-one C style and very "just-got-it-working" so a fair bit of ugliness still, and a bunch of holes.

    I am still undecided exactly how to proceed to make it more Nim (using proper bool instead of orxBOOL, possibly remove a lot of prefixes not needed in Nim since we have modules there etc etc). At the same time I don't want to deviate from the ORX API really. I will move it to its own repo I think, just need to figure out how to track ORX properly. :)

  • The advantage of using an international keyboard layout is that I can directly use many interesting á¢çëñts. ;)

    I understand not wanting to deviate too much from orx's API, but I think it's more important to have something idiomatic in the end, that doesn't suffer from the original C limitations. Especially if the conversion can be automated.

  • What are the benefits of Nim, for someone that barely knows CPP? Can you do a mix of Nim and C, is there a hefty performance hit, is the code far faster to write?

  • Nim is a modern statically typed language with tunable garbage collection. Nim compiles via C, C++ or js. Performance is similar to C/C++ when compiling via those, so not much of a performance hit. The main advantage is a richer language that makes you more productive. Some examples are a good string type, collection types, type safe meta programming and much more. In my personal opinion Nim is a very powerful language that still manages to make things that ought to be easy, stay easy. I think it leverages ORX even more. I am on the ORX discord btw, if you want to ask more - join there - we have a specific norx channel. Also, me and a friend are writing a game using Norx, and it works great.

  • I've been trying to compile the sample, which I can get Orx to compile just fine and the environment variables are there, but when I compile with "nim c -d:nimDebugDlOpen -o:norxsample src/norxsample" I get this:

    ./norxsample
    liborxd.so: cannot open shared object file: No such file or directory
    could not load: liborxd.so

    I've run the commands to link the $ORX directory, however it seems to be unable to access it for whatever reason. Is there a way to set these .so paths directly in the compile?

  • edited October 2020

    I figured it out, when running the exectuable you need to use.

    LD_LIBRARY_PATH=$ORX ./myprogram

    I'm also figuring some other things out, like to load a .ini you need to use 'config.load(cstring("settings.ini")); '. If you search for a function in the entirety of the code it seems these are all mapped inside nim files, and the name of the nim file seems to be what you prefix it with.

    Also useful to know how to pass pointers:
    var pos : orxVector
    discard getPosition(playerObject, addr(pos))
    pos.fX = pos.fX - 1
    discard setPosition(playerObject, addr(pos))

Sign In or Register to comment.