Created
February 14, 2023 16:56
-
-
Save jmbr/c5be43a418abc8136a4b6f9091cf46b7 to your computer and use it in GitHub Desktop.
Python interpreter embedded in SBCL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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