Path: Computer > Computer > Calling Perl > Calling Perl from Lua

Calling Perl from Lua

If you want to embed live Perl code into your Lua programs, then this page is for you. (If you ask yourself why anyone in his right mind would do a thing like that… well, there are reasons:-). One is that I have so much Perl code lying around (and there is so much more in the CPAN archives) that it would be a crime to leave this huge potential untapped. What I am certainly not trying to do here is to preach Perl as opposed to Lua: I am an entirely pragmatic agnostic in these matters.)

I have stitched together an interface library that allows calling Perl from Lua. This effort is based on two similar projects for some macro languages I have used in the past. The Lua interface to Perl is similar in spirit to these, but easier and more natural to use, mainly because Lua is flexible enough to support an almost seamless integration.

The sources as well as the binaries (the latter for Windows only, as I am not really into Linux) are in this archive. (There are also two archives with the Perl58.dll or Perl510.dll that you'll need if you do not have a recent version of Perl 5.8 or 5.10 installed: these contain the Perl DLLs (version 5.8 or 5.10) that the embedding interface DLL needs to do its job.) Details about usage and a few examples are found in the first archive.

Please note that the included PERLEMBED*.DLLs were compiled and tested against the current LuaBinaries distribution (that's Lua 5.1.4). In particular, the PERLEMBED*.DLLs rely on lua5.1.dll. Earlier versions of Lua, so long as they're in the 5.1 branch, should work as well.

If anyone wants to get this up and running under Linux or other *x-like systems, that shouldn't be too difficult provided there's a recent Perl available for that system (any 5.8.x or 5.10 should do). The sources (actually, it's just one C file plus a couple of Lua modules) and a makefile are included. I have tried to do things in such a way that the C code should work with other systems as well (perhaps after some minor tweaking). In case you try to port this and run into unsurmountable difficulties, just drop me a note: although I am not an *x-pert I may be able to point you in the right direction.

All comments, bug reports et cetera please to thomas.lauer@gmail.com or via the contacts page.


$updated from: Calling Perl from Lua.htxt Thu 27 Apr 2017 10:06:49 thomasl (By Thomas Lauer)$