by antidoh · 13y ago · 0 comments
Lua really, really rocks - especially if you look at it as the domain tool it is, and not the prepackaged broad-spectrum scripting language that many people consider it to be ..
I really like a lot of Lua's features, especially closures and the way metatables work. Although Lua doesn't support true classes, it's possible to implement them nicely through metatables.
And anything it doesn't have, which one would truly need to derive from the C/C++ side, is a few simple binding calls away .. but anyway, tables will do all you ask, and more, if you learn to use them properly.
I haven't used Lua yet, but reading about it led me to believe it was a "broad-spectrum scripting language".
I'd like to understand the distinction you're making more deeply.
Then there's Lua-the-implementation(s) (PUC + LuaJIT), both of which are designed from the start to be maximally easy to embed in a host C program, or to delegate work to shared libraries written in C. In my opinion, it is an order of magnitude better at this than Python or Ruby; some of this is a matter of taste but I believe most of the advantages are objective.
Not to put words in the GP's mouth, but I take the "domain tool" comment to mean: "You really should try to use this in close cooperation with C, and not just as a stand-alone language. If you don't you'll miss a significant portion of the value." Note that using it in concert with C need not be done in a single person's head (though this case is also common); Lua+C is an extremely productive way for a systems programmer and an applications programmer to work in harmony while enjoying most of the best of both worlds.
Yes, you can just run 'lua' at the console and treat it as a local scripting language, with the default bindings available in the distribution Lua-interpreter .. but you can also take the VM itself, make it your own, and put it in your own project for domain-specific applications.
For a great example, take a look at MOAI: http://getmoai.com/
Essentially, MOAI is a collection of C and C++ libraries, tied together into the Lua VM to provide a cross-platform development tool for Android/iOS/Linux/Mac/Windows/&etc. This is accomplished by 'gluing' the Lua VM into the space between a variety of different API's and making those API's available within the Lua environment - in this capacity, it serves very, very well. I could imagine building an entire GUI/OS in a very similar way, and may end up doing just that one day soon ..
domain tool - a tool which can be applied to, and adjusted according to the needs of the domain of your application. You can embed the Lua VM in your 'broader application' and use it as an internalized scripting language. If, for example, you've got a C/C++ program which sorts apples, you can export those apples, with bindings, into the Lua VM and reference them from the Lua language as apples, just the same ..
board-spectrum scripting language - python, perl, lua. Each of these can be (usually) found in /usr/bin somewhere, as a single executable that can be used to run the language scripts. Lua has a part in this role too - I frequently write system-admin scripts using #!/usr/bin/lua, but in this particular case I don't have any 'customizations' - I get only whats built-in to the Lua executable as shipped by my distribution.
But, beyond this, I could take the Lua VM and build my own domain tool with it. See the difference now?