How to use C code with Solar2D framework?

Dear community,
I’d like to use pre-written complex code, written in C language, from within my LUA/Solar2D app.
I found information about Solar2d Native here


but after reading it several time I still cannot figure out how/where to include the C code or a C library?
It’s written to use Android Studio, but how do I combine the LUA- and C-code and the Solar2D simulator with the C code?
I appreciate any help or exampes or detailed description. Thank you very much.

Is your C code written in a way that makes it compatible with lua? Then it could be as simple as:

local module = require("name-of-compiled-binary")

Here is a chapter from “Programming in Lua” detailing how to call C functions from lua: http://www.lua.org/pil/26.html

Thanks a lot, very good hint just requiring it. Do I have to compile the library for Android then or use gcc with ARM as a target?

Based on your link I found a webpage with an example, which worked so far:
Calling a C Function From Lua

The C code I want to use has some pointer arithmetics, so I have to try if this works too.

You can just wrap the library in a plugin. If you send me the library, I’ll wrap one function to show you.

Great, thanks. :clap:
I’d like to use the astrolib library, then as an example please wrap the first function “double ddd” (line 35):
astrolib.cpp

Sorry that file is much more involved than I expected. It references other libs in the header and is more than I can tackle at the moment.

It would be relatively easy to translate that code to lua. If you’re only interested in the “astrolib.cpp” code, it’s not a difficult task. But have you considered that there may be better options, better astronomical libraries? If you’re interested in astronomical coding for “practical” applications, I recommend the NavList community (fer3.com/arc).

Frank Reed