Is it possible to use Crystal in Python3 packages/extensions?
Asked
Active
Viewed 476 times
2
-
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
-
1I 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 Answers
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.
- https://docs.python.org/3/library/ctypes.html#fundamental-data-types
- https://github.com/crystal-lang/crystal/blob/391785249f66aaf5929b787b29810aeb4af0e1e8/src/nil.cr#L42
related posts:

jmunsch
- 22,771
- 11
- 93
- 114