Lua Versus Perl

lua-users home


Perl [1] is a general-purpose dynamic programming language supporting multiple programming paradigms (procedural, object-oriented, and functional styles), automatic memory management, built-in support for text processing, and a large collection of third-party modules. [2]


Expressiveness: Lua is remarkably expressive, despite its small size, providing even coroutines, closures, and metamechanisms for OO and other paradigms. Perl is arguably one of the most expressive languages available [3][4] but is much larger in size and complexity. [5]

Coroutine Support: Lua has built-in coroutine support. There are some modules for adding this in Perl [6]. Perl 6 supports something similar to coroutines [7][8], though as of Aug 2009, Rakudo doesn't yet support laziness, which is required for this.

Performance, Efficiency, and Implementation

Performance: Lua is one of the fastest interpreted scripting languages. Perl is generally more heavyweight though is optimized for some text processing functions [9].

Code Footprint: Lua has a much smaller footprint: about 120K binary. Perl 5.6 is about 1.1M. One of the smallest builds of Perl, TinyPerl? [10] 5.8.0/Win32, is 94K tinyperl.exe + 356K perl58.dll (~3.8x) (and optional 262K

Portability: Lua compiles on nearly any ANSI C compiler. This and its small size allows it to run even on many embedded platforms. Perl, despite running on numerous operating systems, has stricter requirements [11].

Virtual Machine: The Lua VM is an efficient register based virtual machine. Perl works on an Stack Based VM [12][13] (Perl 6 will have a register VM called Parrot [14]). LuaJIT [15] is an a JIT version of the VM for x86.

There are alternative, though in many cases partial, implementations of Lua on other VMs--see "Alternative Implementations of Lua" in LuaAddons. Perl's complexity, lack of a formal language specification, and lack of an independent VM are reasons that only one real implementation exists (though this is changing in Perl 6, which, though is even more complex, does have a formal language specification and separate VM, and one compiler is written in Haskell).

Memory Management: Lua 5.1 has an incremental garbage collector (GarbageCollectionTutorial). Perl uses a simple but efficient reference-based garbage collection that will leak on cycles [16] (though Perl 6/Parrot will use garbage collection [17]).

Stability: Very few bugs can be found in Lua. [18] The code is small, highly stable, and extensively reviewed. The Perl core is larger, does more, and is much more complex, so naturally it would be harder to ensure validity. That said, Perl is widely used and tested, and the core is generally quite stable. If one includes non-core modules, then Perl may be more stable/mature in general.


Embedding and Extending with C: Lua has a very clean and simple interface for embedding or extending C. Perl has XS, which has commonly recognized deficiencies and complexities [19], but there is a cleaner Inline interface [20] to various languages.

The Lua compiler and VM are more readily understood and customized. Perl is much more complex.


Syntax: Perl is in full a quite complicated language. Complex syntax can allow more expressivity if mastered [21] but can also be more difficult to learn and easier to abuse. Some parts of Perl syntax are awkward, such as its use of sigils [22], though this is being addressed in Perl 6 [23].

Lua has a simple, clean syntax, whose core language can be described in 25 pages and standard libaries in another 25 pages [24]. The Lua grammar fits in a page or two (see LuaGrammar).

Grammar Specification/External Parsers: Lua's grammar is defined according to a specification, and a simple one at that (see LuaGrammar). Perl is defined by an implementation rather than a formal language specification (though Perl 6 will be defined according to a specification). Due to both the lack of formal specification and complexity, Perl is only reasonably fully parseable in Perl itself (see [PPI]) or partially parsable with some difficulty [25] (Perl 6 will be fully parsable with some difficulty [26]).

It is far easier to write a Lua parser than a Perl parser for reasons noted above. This makes writing tools that operate on the language easier--e.g. syntax highlighters, source code analyzers, source code translators, source code filters, documentation extractors, metaprogramming tools (e.g. Metalua [27]), and alternative implementations (see "Alternative Implementations of Lua" in LuaAddons). However, it should be noted that Lua, being a highly dynamic language, makes it difficult to extract source code meaning from syntax alone.

Functionality / Application Areas

Database Support: Perl database support [28] is much more mature and includes support for bind value/placeholders [29]. Lua does have LuaSQL though [30].

Regular Expressions: Perl has built-in support for regular expressions in the language. Lua has includes a more limited but still quite functional pattern matching library, and there are various regular expression library addons [31]. Lua's LPeg [32] for PEGs has gotten a lot of attention, though Perl has a variety of modules for grammars, e.g. Parse::RecDescent [33].

Web Development: Since the creation of the web, Perl has been widely used for web programming, first with CGI and then with mod_perl and various other frameworks. There are extensive support modules (e.g. [34]). Lua has Kepler [35].

Threading: Perl has built-in threading [36]. Lua has built-in coroutine support (cooperative multitasking) and encourages the use of it over threads, or at least using one thread per Lua state (see ThreadsTutorial ). There are a few add-ons supporting preemptive multithreading in Lua, such as LuaLanes? [37].

Modules and Software Engineering

Modules: Perl has a huge number of modules in [CPAN] for facilitating a broad range of scripting and programming tasks (15 million lines of code in CPAN as of 2005 [38]). Lua module offerings are more specialized and limited, but many are maintained at LuaForge.

Lua lacks a comprehensive standard library (partly due to the design requirement of ANSI compatibility), but see ExtensionProposal.

Community: Perl has a large and well organized user community (e.g. CPAN, CPANTS [39],,,, more than a hundred mailing lists [40], ...). Still, Lua has active mail lists, wiki, LuaForge, Kepler, ....

Packaging/Deployment: Perl has a mature packaging, versioning, distribution, and installation mechanism through CPAN/ExtUtils::MakeMaker. Something similar for Lua is beginning via the LuaRocks effort.

Documentation Format: Perl has a standard module documentation format, POD [41]. Lua documentation methods are a bit more fragmented (e.g. LuaDoc [42] and LuaPOD [43]).

Testing: Perl has CPANTS [44]/Kwalitee. Most modules on CPAN come with a test suite. There are version testing modules, including the popular Test::More [45]. Lua does have at a few testing modules itself (UnitTesting).

Combining Perl and Lua

There is an implementation of Lua on Parrot. [Inline::Lua], [Outline::Lua], [Lua::API], and [Lux] (not recently maintained) embed Lua in Perl. [perlembed] and [luaperl] embed Lua in Perl. re::engine::Lua [46][47] supplies Perl 5.10 with Lua patterns via a pluggable regex engine. LuaPOD [43] parses POD in Lua. Syntax::Highlight::Engine::Kate::Lua [48] syntax highlights Lua from Perl.

Additional Notes

Though some improvements are made from Perl 5 to Perl 6 are noted above, Perl 6 is a massive undertaking, and it's not known how many years away it will be before the final Perl 6 release. [49].

See Also

RecentChanges · preferences
edit · history
Last edited April 20, 2011 2:53 am GMT (diff)