Skip to content

Instantly share code, notes, and snippets.

@jmbr
Created February 14, 2023 16:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmbr/c5be43a418abc8136a4b6f9091cf46b7 to your computer and use it in GitHub Desktop.
Save jmbr/c5be43a418abc8136a4b6f9091cf46b7 to your computer and use it in GitHub Desktop.
Python interpreter embedded in SBCL
(defpackage :python-interpreter
(:use :common-lisp :cffi)
(:export #:run-python))
(in-package :python-interpreter)
(define-foreign-library libpython (:unix "libpython3.10.so"))
(use-foreign-library libpython)
(defcfun "Py_InitializeEx" :void (initsigs :int))
(defcfun "PyRun_SimpleStringFlags" :void (str :string) (flags :pointer))
(defcfun "Py_FinalizeEx" :int)
(defun run-python ()
(sb-vm::with-float-traps-masked
(:underflow :overflow :inexact :invalid :divide-by-zero)
(py-initializeex 1)
(pyrun-simplestringflags "import code; code.interact()" (cffi:null-pointer))
(py-finalizeex)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment