Search code examples
pythonpython-3.xcrystal-lang

How can I use Crystal in Python packages/extensions?


Is it possible to use Crystal in Python3 packages/extensions?


Solution

  • dl has been deprecated in python3, look at ctypes.

    It might be possible as highlighted here: https://github.com/hyronx/crystal-shared-lib

    What this might look like in python3:

    from ctypes import *
    
    cdll.LoadLibrary("libcrystal-shared-lib.so")
    
    crystal = CDLL("libcrystal-shared-lib.so") 
    
    crystal.test(None) 
    

    note

    I am not sure at the moment how the primitives convert from Python's None to C's None to Crystal's Nil, but nil returns a 0_u64, so it's a hint, of some sort.

    related posts: