lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


It was thus said that the Great Emmanuel Oga once stated:
> Suppose you have just written a posix-like utility (like find, grep,
> etc..) which is implemented in both  lua and C modules. What would be
> the best way to ship that program?
> 
> I'm working on a small script that implements a basic find-like tool.
> I was thinking of coding my own loader as a small C program and
> linking lua statically. While looking for info about embedding I found
> this article:
> 
> http://www.twistedmatrix.com/users/glyph/rant/extendit.html
> 
> It talks about python but I'm wondering if it applies also for lua.

  It really depends upon the application.  At work, I had to write a program
to test our project, which deals with call processing (the "back-end" of
telephony---the machines that actually deal with setting up and tearing down
phone calls).  I embedded Lua in my testing tool to make it easy to
configure and write the high level logic of each test.  

  Intially I embedded Lua in the application but over time as it gained
capabilities that could also be used elsewhere, I broke parts of it off into
Lua modules.  This change meant I could use the standalone Lua executable
for certain jobs and not have to use the custom tool to run those scripts.

  I still have the custom tool though, for a few reasons:

	1. The code I have to interface with is C++.  Really nasty C++.
	   I don't want to muck with making that into a loadable module.

	2. It can only run on certain machines with the proper device
	   drivers in the operating system (SS7 protocol stack).  There are
	   only a few machines that have the proper device drivers anyway,
	   so there's no real incentive for me to make a module out of
	   this portion of the code anyway.

  But the tool has been compiled such that it can still load other Lua
modules (really, the only difference between the stock Lua interpreter and
my tool is that, well, my tool talks SS7, and it doesn't have a REPL).  I
can still load the extentions via require() that used to be "just there" in
the old script (when everything was integrated).

  Lua is small enough that extending vs. embedding is less an issue that it
seems with Python.  For me, it comes down to what is best for what I'm
working with.  

  I also have a syslogd I wrote [1] that embeds Lua.  Could I have made it
a Lua module?  Yes, but for me, I feel it's better for this syslogd to embed
Lua than for Lua to be extended to support syslogd, if that makes any sense. 
It handles the network and protocol, leaving just the filtering of syslog
messages to a Lua script.

  -spc

[1]	http://www.conman.org/software/syslogintr/