Compiling Crystal shared libary and static variables

I can compile a shared library for use in C using an example from stack overflow (questions/32916684). My question, is it possible to have variables persist or data persist between cyrstal lang function calls from the main c program. Obviously I could return them and then pass them back in, as a comprise.

I ask as I can do this with graalvm with static variables, as the VM is initiated by
graal_create_isolate() and then graal_tear_down_isolate(). Static variables in the Java native shared library persist as long as graal_tear_down_isolate() is not called.

Maybe it isn’t possible as there is no VM in a crystal lang compiled shared library only a runtime.

Hi @Jay1, nothing should prevent you from storing a value in the Crystal side and re-use it across calls. The following works:

class Globals
  class_property value : Int32 = 0

fun log = crystal_log(text: UInt8*): Void
  Globals.value += 1
  puts + Globals.value.to_s # subsequent calls will show 2, 3, 4...

Thank you so much!