I recently found "Terra " and, after a few tests, i could make some basic
calls to the API :
"Terra is a low-level system programming language that is embedded in and
meta-programmed by the Lua programming language." It uses LLVM and Clang.
It's well sustained - and providing a complete documentation.
The complete description - documentation are here http://terralang.org/
With Terra i could finally use the csoundCreateThread API function i was
unsucessful to run with luajit.
Here two files ".t" (terra extension), both calling the API. The csnd.t just
plays a sine. The csnd_PerfThread.t do the same, with calling the
csoundCreateThread function. Both were running on Windows 10 - using the
last Terra pre compiled binaries - csound 6.10 x64 binaries - and visual
studio 2017 packages for the C standard lib.
I didn't have time to try it with my IUP / LUA user interface to see if the
separate threads are efficient in my case, i'll do the test soon.
I'll continue to run some tests to see what is possible to do with it.
I'm having some issues trying to implement callbacks from Csound outvalue inside my program.
sum up, there is a main GUI - programmed in Lua with IUP binaries, and
Lua triggers some Terra low-level functions to call csound API. The
csoundPerformKsmps performs well, also with the "Master" control volume
slider (using csoundGetChannelPtr in the csound thread). But, if i
activate the callbacks, moving the volume slider make all the app crash.
The callbacks i use are an outvalue (triggering for each Csound "beat" a
refreshment on a GUI matrix), and two viewmeters refreshing every 256
k-pass (also tried less, it's not really the problem here).
terra callback function (called with csoundGetOutputChannelCallback)
refers to different Lua functions, according to the channel name. Those
Lua functions don't do a big job, only refreshing some IUP objects.
I tried to lock the UserData with a mutex, it's better than without,
but still if i move the slider the app crashes. I also tried to remove
only the content of the Terra callback function (replacing with
printf("Hello \n"), and it works well, even while moving the slider.
Also, i tried to make run all the callbacks in a different thread, and it doesn't seem better.
After those tests, i'm not sure what is crashing :
-Refreshing the GUI with callbacks functions might need some "security" ?
-Maybe mutex is not used well ?
-Maybe i would rather need the SpinLocks, but i'm not sure how to use it ?
If anyone wants to check in, the full project is here (currently just for windows) - with explanations.