2

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

thinwybk
  • 4,193
  • 2
  • 40
  • 76
  • I don't know if there are specific crystal bindings for Python. You _can_ make [arbitrary system calls](https://stackoverflow.com/questions/89228/calling-an-external-command-in-python) that could run Crystal programs. A more important question may be: What specific task are you trying to accomplish? – pixatlazaki Sep 16 '18 at 03:15
  • I want to use bindings to another faster system programming language. System calls are no option for me. Crystal, Rust and D are possible candidates. – thinwybk Sep 16 '18 at 07:23
  • 1
    I don't think crystal is "plumbed" to created shared libraries yet, maybe ask on the google group... – rogerdpack Sep 18 '18 at 22:05

1 Answers1

1

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:

jmunsch
  • 22,771
  • 11
  • 93
  • 114