When to use Lua

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

When to use Lua

Jason Slack

I stumbled upon Lua when reading about Adobe Lightroom.

I write a text editor and backup software, under what circumstances would I want to use Lua in my applications? What does it do for me?

Thanks,

-Jason


Reply | Threaded
Open this post in threaded view
|

Re: When to use Lua

Eric Scouten
On 26 Sep 2006, at 13:18, Jason T. Slack wrote:

I stumbled upon Lua when reading about Adobe Lightroom.

I write a text editor and backup software, under what circumstances would I want to use Lua in my applications? What does it do for me?


Lightroom is a classic example of a hybrid application. We are able to exploit the strengths of several languages. There are portions of the app that we would never write in Lua (our core image processing routines, for example), and other portions where the use of Lua saves us a tremendous amount of time in the development process.

In large part, our application consists of a fairly rich native code layer which exposes various platform services (OS, file system, user interface fundamentals) and Adobe native code libraries (camera raw processing, etc.) to Lua. Most of the core "business logic" of Lightroom is expressed in Lua. Among other things, this allows us to gloss over the fact that the native code may be radically different (i.e. most of our Windows UI layer is written in C++, but the Mac UI layer is written in Objective C, yet the layout is described only once ... in Lua).

Having used Lua for a few years now, I've been amazed at how quickly I can build up arbitrary data structures and defer processing ("do this task whenever the app is idle but only once", etc.). It makes us all much more nimble as a development team.

-Eric


Reply | Threaded
Open this post in threaded view
|

Re: When to use Lua

Ken Smith-2
In reply to this post by Jason Slack
On 9/26/06, Jason T. Slack <[hidden email]> wrote:

I stumbled upon Lua when reading about Adobe Lightroom.

I write a text editor and backup software, under what circumstances
would I want to use Lua in my applications? What does it do for me?

This is a big question but, as a very new Lua user, let me tell you
places where I will use Lua from now on.

- configuration files
  Forget .ini and its ilk.  Lua is simple and lightweight enough to
use for this
  basic service.

- exposing program internals to savvy end users
  Perhaps your editor could use a scripting language for automation?

- real programs
  In the future, when I write a program in C or C++, I will do all I can to
  write the bulk of it in Lua and only use C/C++ to expose otherwise
unavailable
  system internals.  Hashtables are the king of datastructures and I
starting to
  wonder why I ever need anything else :)

 Ken Smith

Reply | Threaded
Open this post in threaded view
|

RE: When to use Lua

Dustin Bruzenak
Lua, like most of the newer, dynamic languages, allows you to create
mini-languages much closer to the domain of your business problem than
their traditional object-oriented counter parts. 

Lua delivers on the promise of object oriented programming by allowing
you to write programs in terms of your business model as opposed to your
hardware and OS model, without having to resort to object-quackery like
dynamic casts and type introspection.
 
This has an advantage when you need to implement a user requirement.
Instead of thinking about the amount of memory you need to allocate or
whether you're going to pass by reference or copy, you find yourself
thinking of how the tax should be calculated for the order or where the
button should be on the screen. 

This level of abstraction does wonders for creating rapid prototypes,
user scripting layers, configuration, and UI. These are the areas where
I think Lua excels.

So where shouldn't you use it? 

I would be wary of using Lua in real time environments where every byte
needs to be accounted for, every loop needs to be tight, and you can't
afford to lose perfect control. 

The same goes for systems that demand speed. Fast as Lua is, you aren't
going to beat plain old C for image processing or modeling.

Finally, I don't think the language makes much sense if you're just
re-implementing functionality provided by your underlying OS. Anywhere
where you're not providing an abstraction is a bad place to use Lua.
Leave those WM_PAINTS out of your pristine business code. 

-Dustin

-----Original Message-----
From: [hidden email]
[[hidden email]] On Behalf Of Ken Smith
Sent: Tuesday, September 26, 2006 3:34 PM
To: Lua list
Cc: [hidden email]
Subject: Re: When to use Lua

On 9/26/06, Jason T. Slack <[hidden email]> wrote:
>
> I stumbled upon Lua when reading about Adobe Lightroom.
>
> I write a text editor and backup software, under what circumstances
> would I want to use Lua in my applications? What does it do for me?

This is a big question but, as a very new Lua user, let me tell you
places where I will use Lua from now on.

 - configuration files
   Forget .ini and its ilk.  Lua is simple and lightweight enough to
use for this
   basic service.

 - exposing program internals to savvy end users
   Perhaps your editor could use a scripting language for automation?

 - real programs
   In the future, when I write a program in C or C++, I will do all I
can to
   write the bulk of it in Lua and only use C/C++ to expose otherwise
unavailable
   system internals.  Hashtables are the king of datastructures and I
starting to
   wonder why I ever need anything else :)

  Ken Smith


Reply | Threaded
Open this post in threaded view
|

Re: When to use Lua

David Given
In reply to this post by Ken Smith-2
Ken Smith wrote:
[...]
> - real programs
>   In the future, when I write a program in C or C++, I will do all I can to
>   write the bulk of it in Lua and only use C/C++ to expose otherwise
> unavailable
>   system internals.

Likewise. IMO, Lua is fast enough and small enough to support writing the core
logic for just about any reasonable application. I wouldn't say it's perfect;
the lack of strict typing and compile-time checking means that scaling up a
Lua program is less easy than one might hope; the extreme RAD-ness of the
language does tend to lead to unmaintainable messes if you don't enforce
coding discipline; actually adding an interpreter to an application is
significantly harder than it should be...

But on the whole, Lua lets me *get the job done*.

My current project is a build tool called Prime Mover, which is not unlike
make. It's designed to be deployed with the applications that use it, and is
written in Lua. pm steering files are Lua scripts. It's 1600 lines of code and
is scarily powerful; it already vastly outstrips make in terms of sheer
extensibility and functionality (although it does work in a rather different way).

And the good bit? Lua is so tiny that I can get around the problem of the user
needing to install Lua before being able to use pm by including a copy of the
Lua interpreter with every copy of pm! The main binary is a 100kB shell script
which contains the pm Lua script itself, but also the Lua interpreter source
(massaged to be a single stand-alone C file). When you run the shell script,
it unpacks the source file, compiles it, and runs the Lua script, all without
the user's intervention. The bootstrap process, which happens only once, takes
about five seconds on my low-end PC.

I don't believe there is *any* other interpreted language that supports that
sort of thing!

-- 
+- David Given --McQ-+ "Gaping from its single obling socket was
|  [hidden email]    | scintillating, many fauceted scarlet emerald..."
| ([hidden email]) | --- Jim Theis, _The Eye of Argon_ (spelling
+- www.cowlark.com --+ original)


Attachment: signature.asc
Description: OpenPGP digital signature

Reply | Threaded
Open this post in threaded view
|

Re: When to use Lua

whisper-4
In reply to this post by Jason Slack
Jason T. Slack wrote:

I stumbled upon Lua when reading about Adobe Lightroom.

I write a text editor and backup software, under what circumstances would I want to use Lua in my applications? What does it do for me?

Thanks,

-Jason


With respect to text editing, you might want to look at Scite (www.scintilla.org) for ideas. There's a version that's had Lua embedded for various tasks. See http://gisdeveloper.tripod.com/scite.html

You could write a backup utility using Lua for most of the glue, leaving the guts to be written as dll extensions. Toss in wxLua and you've got potential for a GUI based platform-independent utility.

Dave LeBlanc
Seattle, WA USA


Reply | Threaded
Open this post in threaded view
|

Re: When to use Lua

Philippe Lhoste
[hidden email] a écrit :
With respect to text editing, you might want to look at Scite (www.scintilla.org) for ideas. There's a version that's had Lua embedded for various tasks. See http://gisdeveloper.tripod.com/scite.html

Actually, Bruce code is already integrated to the official distribution of SciTE. Bruce plans to upgrade to Lua 5.1.

--
Philippe Lhoste
--  (near) Paris -- France
--  http://Phi.Lho.free.fr
--  --  --  --  --  --  --  --  --  --  --  --  --  --


Reply | Threaded
Open this post in threaded view
|

Re: When to use Lua

Nicolas Cannasse
In reply to this post by David Given
> I don't believe there is *any* other interpreted language that supports that
> sort of thing!

Well sorry for the plug, but Neko (http://nekovm.org) provides that as
well, with the difference that you can easily create executable from a
compiled Neko script.

And if you don't want to stick to the "low-level" dynamicly typed
language, you can use haXe (http://haxe.org) that has a complete OO type
system and which targets Neko.

Nicolas

Reply | Threaded
Open this post in threaded view
|

Re: When to use Lua

David Given
Nicolas Cannasse wrote:
>> I don't believe there is *any* other interpreted language that supports that
>> sort of thing!
> 
> Well sorry for the plug, but Neko (http://nekovm.org) provides that as
> well, with the difference that you can easily create executable from a
> compiled Neko script.

No, it can't (from what I understand from the documentation) --- Neko
allows you to build a single executable *for one platform*. What I've
got is a single executable that will run *on all platforms*.

> And if you don't want to stick to the "low-level" dynamicly typed
> language, you can use haXe (http://haxe.org) that has a complete OO type
> system and which targets Neko.

Haxe is interesting; if they ever do a Lua backend, it may be possible
to use Haxe plus my mechanism to produce cross-platform binaries for any
(Unix-like) system...

-- 
+- David Given --McQ-+ "Is Eris true?" "Everthing is true." "Even false
|  [hidden email]    | things?" "Even false things are true." "How can
| ([hidden email]) | that be?" "I don't know, man. I didn't do it!"
+- www.cowlark.com --+ --- _Prinicipa Discordia_

Attachment: signature.asc
Description: OpenPGP digital signature

Reply | Threaded
Open this post in threaded view
|

Re: When to use Lua

Philippe Lhoste
David Given a écrit :
No, it can't (from what I understand from the documentation) --- Neko
allows you to build a single executable *for one platform*. What I've
got is a single executable that will run *on all platforms*.

All platforms with a shell and a compiler on the path, if I understood correctly your smart mechanism. I fear that excludes stock Windows... :-)

--
Philippe Lhoste
--  (near) Paris -- France
--  http://Phi.Lho.free.fr
--  --  --  --  --  --  --  --  --  --  --  --  --  --


Reply | Threaded
Open this post in threaded view
|

Re: When to use Lua

David Given
Philippe Lhoste wrote:
> David Given a écrit :
>> No, it can't (from what I understand from the documentation) --- Neko
>> allows you to build a single executable *for one platform*. What I've
>> got is a single executable that will run *on all platforms*.
> 
> All platforms with a shell and a compiler on the path, if I understood
> correctly your smart mechanism. I fear that excludes stock Windows... :-)

True, but Prime Mover *is* a build tool designed for use from the shell and
whose primary task is to invoke a compiler, so I reckon that's not really a
problem...

(It ought to work from Cygwin, but I haven't tested it. I have made sure it
works on Linux, BSD, OSX, Solaris, and BeOS, though.)

-- 
+- David Given --McQ-+ "They laughed at Newton. They laughed at Einstein.
|  [hidden email]    | Of course, they also laughed at Bozo the Clown."
| ([hidden email]) | --- Carl Sagan
+- www.cowlark.com --+

Attachment: signature.asc
Description: OpenPGP digital signature