Skip to content

Instantly share code, notes, and snippets.

@aktowns
Created June 5, 2011 14:08
Show Gist options
  • Save aktowns/1008985 to your computer and use it in GitHub Desktop.
Save aktowns/1008985 to your computer and use it in GitHub Desktop.
INCEPTION
;;; Lua running in Ruby running in Python running in Lisp by [email protected]
;;; TODO:
;;; Lua
;;; Javascript
;;; ???
;;; OUTPUT:
;;; ~| newlisp inception.lisp
;;; [Entered lisp state]
;;; [Entered python state]
;;; [Entered ruby state]
;;; [Entered lua state]
;;; Hello, im lua running in ruby which is running in python which is running in lisp.
;;; [Leaving lua state]
;;; [Leaving ruby state]
;;; [Leaving python state]
;;; [Leaving lisp state]
;;; ~|
(println "[Entered lisp state]")
(setq python "libpython2.6.dylib")
(setq py-initialize (import python "Py_Initialize"))
(setq py-run-simplestring (import python "PyRun_SimpleString"))
(setq py-finalize (import python "Py_Finalize"))
(setq py-content (join '(
"print '[Entered python state]'"
"import sys"
"from ctypes import *"
"ruby = cdll.LoadLibrary('libruby.dylib')"
"ruby.ruby_init()"
"ruby.ruby_init_loadpath()"
"ruby.rb_eval_string('''"
"puts '[Entered ruby state]'"
"require 'rubygems'"
"require 'ffi'"
"module Lua"
" extend FFI::Library"
" ffi_lib 'lua'"
" attach_function :luaL_newstate, [], :pointer"
" attach_function :luaL_openlibs, [ :pointer ], :void"
" attach_function :luaL_loadstring, [ :pointer , :string], :void"
" attach_function :lua_pcall, [ :pointer, :int, :int, :int ], :int"
"end"
"l = Lua.luaL_newstate"
"Lua.luaL_openlibs(l)"
"Lua.luaL_loadstring l, <<-LUACODE"
"print '[Entered lua state]'"
"print 'Hello, im lua running in ruby which is running in python which is running in lisp.'"
"print '[Leaving lua state]'"
"LUACODE"
"Lua.lua_pcall(l, 0, -1, 0)"
"puts '[Leaving ruby state]'"
"''')"
"ruby.ruby_finalize()"
"print '[Leaving python state]'") "\n"))
(py-initialize)
(py-run-simplestring py-content)
(py-finalize)
(println "[Leaving lisp state]")
(exit)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment