views:

1623

answers:

4

From my understanding, Lua is an embeddable scripting language that can execute methods on objects. What are the pitfalls to avoid? Is is it feasible to use Lua as an interpreter and execute methods in an web environment or as a rule engine?

+6  A: 

Lua scripting is on track to becoming a core module for Apache web server.

There are a couple tools for binding Lua and C#/.NET code here. LuaInterface is the most up to date.

Doug Currie
what a shame all those links fail with redirects to double-wwwhammy www.www.lua-users.org
stimpy77
The site has been undergoing maintenance (from 2010-08-22), according to a mailing list post on 2010-08-19. I have notified the list of the issue. Thanks.
Doug Currie
The DNS has been updated and lua-users.org links seem to be working as of today, 2010-08-23.
Doug Currie
+5  A: 

Lua is very fast - scripts can be precompiled to bytecodes and functions execute close to C++ virtual method calls. That is the reason why it is used in gaming industry for scripting AI, plugins, and other hi-level stuff in games.

But you put C# and web server in your question tags.

If you are not thinking of embedded web servers - than Lua is not very strong. Lua is ANSI C - it compiles to native code, and as such it is not very welcome to your asp.net server, nor to your C# code. Think of "medium trust" or "binding" or "64bit".

Enough of pitfalls. If you are allready using C#, there is no reason to avoid it on web server. It gets compiled and cached. It servers huge sites like this one.

dmajkic
+2  A: 

Why I like Lua is that it excels as a language, especially when used together with C/C++ as it's supposed to be. To me, it's the merger of these two that "makes" the language.

Pitfalls.. The lack of extension modules could be seen as one. Like no CPAN, but there is LuaRocks. Depends if you have enough bindings to go for your problem. If not, you might need to be making them.

Language pitfalls.. There are some wishes in the Lua wiki, which can be seen as "pitfalls". No "switch" statement. No proper "cond ? a : b" format. If you don't want to stretch your mind above such rather superficial syntax things, then maybe JavaScript is for you?

As a whole, it's a language that makes me 10-100 times more productive than programming without it.

akauppi
Of course `cond and a or b` is the Lua equivalent to a C-like `cond ? a : b` and has the advantage of almost making sense ;-)
RBerteig
If it were equivalent, there wouldn't be an issue. It's not. If 'a' is nil or false, the statement becomes b. That is the problem, and there is no solution but doing a function or making sure a nil/false is always in the latter value. That sucks.
akauppi
+2  A: 

We used to use Lua as our scripting language in a medium-sized C# biomedical instrument control application. It was a great way to teach the hardware guys how to write their own little bits of test code.

Once IronPython reached maturity, we decided that since Python is a little more full-featured and well-integrated with VS (as well as having more people who use it), we would replace all our Lua with Python. So far that's working out pretty well. Lua is a fine little language, I'm not sure I can think of any advantages of Lua over Python at this point.

Lua can be a bit faster, but if you're already splitting your domains into script-y and non-script-y, presumably that's not a big factor.

Mark Maxham
Would you just start with Iron Python if you had a greenfield?
David Robbins
I think this goes for Lua vs. Python in a more generic plane, as well. If all one wants is a 'ready' scripting language then Python is a safe and popular choice. If one wants embedding, small size or customization, I don't think anything beats Lua.
akauppi
.. or raw performance?
stimpy77