1
votes

Is there any existing project or easy approach to running lua code in a common lisp program? I've seen a few Lisp in Lua projects but to my knowledge none of them implement full common lisp so don't offer an acceptable bridge.

I would think it wouldn't be that hard to either write a full on Lua interpreter in CL or to access Lua via CFFI but so far I've been unable to find any code bases that do this. Do they not exist or what? If not are there any existing code bases that would be a good place to start, e.g., having C code for embedding lua convenient for CFFI?

EDIT: To avoid confusion note that by CFFI I was referring to this lisp project for calling foreign functions not the python one.

1
Off-topic question (even if interesting one), since asking for resources. The memory model in Lisp and in Lua is quite different. But why do you need to call Lua from Lisp? Why can't you profit from Lisp homoiconicity and call Lisp scripts (not Lua ones)?Basile Starynkevitch
Sorry if it is offtopic. Is there a more appropriate place to ask?Peter Gerdes
As for the bit about why not just call Lisp it's about executing existing code written in Lua (particularly I'm wondering about the feasibility of running existing LuaTex code in common lisp though that of course involves all sort of other gunk)Peter Gerdes
Probably not here. But I recommend a wider approach, and then you might ask a different question, perhaps on softwareengineering.stackexchange.com. You need to explain why you specifically want to call Lua (given that Lisp has a similar, but slightly more powerful, semantics). The mention of LuaTeX should go into your question. I would recommend using an external process (for which some Lisp implementations have solutions)Basile Starynkevitch
Because I mean the common foreign function interface: common-lisp.net/project/cffiPeter Gerdes

1 Answers

6
votes

If you consider the lua implementation (the actual lua-5*.tar.gz) as a library coded in C that you want to call from Common Lisp, your question becomes how to call a C foreign function from Common Lisp (i.e. asks about foreign function interface of your Common Lisp implementation). The answer is of course implementation specific. For SBCL, read its §8 Foreign Function Interface chapter. For CLisp, read §32.3. The Foreign Function Call Facility. The Common Lisp CFFI might be helpful. You might want to interface the Lua API to your Common Lisp implementation (but I'm guessing you don't need to; you probably want to run the lualatex program in a different process).

If you consider Lua as a programming language specification (with its syntax and semantics, written in English in some report) you could also write your own Lua interpreter in Lisp. Since Lua is simple, that might be easy (but is it really worthwhile? Probably you'll need to reimplement many Lua primitives).

According to your comments, you might be interested in LuaTeX or LuaLaTeX. Then you really want to start a different process running that. And several Lisp implementations provide some way for this, for example SBCL provides run-program and you might want more inter-process communication (on Linux, that might be unix(7) sockets, or fifo(7), or pipe(7)...). Many Lisp implementations provide some ways to use these. See their documentation.

If you need to understand more how to have several processes working together on Linux -one of them being e.g. lualatex- , read some Linux programming book, perhaps the old ALP (freely downloadable), then intro(2) & syscalls(2). The poll(2) multiplexing system call is relevant, to be used in your event loop. Many Lisp implementations provide ways to do such system calls; for SBCL look into sb-posix

(asking for explicit software resources is off-topic on SO)