I really like the Lua programming language. It’s small, easy to embed and easy to learn. I’ve used Lua successfully in several projects with varying levels of integration from simple extensions to full object hierarchy extensions, RPC support, data replication and all logic for client, server and UIs.
Lua makes some interesting design decisions which I don’t necessarily think lend it to longer term software development.
You can work around some of these decisions because Lua is so flexible, but I can’t help feeling that at some point the ease of integration and simple elegance of Lua are outweighed by the need for a solution more suitable to the domains you might be working in.
- The default scope is the global scope.
- You have to choose the right calling syntax, obj:func() or obj.func() depending on the implementation of the function you’re calling.
- You can easily read variables that haven’t been previously assigned.
- There is only one number type.
- You can’t override an object’s equality with nil.
Any variable declared will automatically live in the global scope. If you don’t like this you can use a few work arounds. The one I came up with was to make each script have it’s own function environment and alter the scope search order to the file scope, then the global scope. All variable assignments therefore default to the file scope and you can use _G to create a global should you wish.
I worked around this using an up value to store the self table and a function environment to change scope rules. Scoping goes to the self scope, the file scope and then the global scope. This is done automatically with a C side closure wrapper.
You can catch this with a metatable but it’s not a good idea. If you try and catch them you’ll stop common constructs like linked lists and checking of an object or variable has been created or destroyed. This is dangerous because typo’s can go unnoticed.
You need to choose either a real number or integer number type when compiling Lua. You can’t have both, Lua has no mechanism to recognize or represent the difference between two number types. You can work around this with userdata types but it’s not very elegant or fast.
If an object has been destroyed you can’t make it equal to nil in Lua because the userdata representing the object will still exist. A metamethod cannot be used to override a comparison between a userdata and nil. This effects you if you want to integrate your own object lifetime management. Using a wrapper function such as IsNil() is the only solution I’ve come up with thus far without changing the VM.
So what other options are available?
While interpreted C/C++ would be familiar — at first glance I don’t think it’s seriously embedable.
Other options that spring to mind include AngelScript, Pawn (which used to be called Small), Squirrel and Python or Stackless Python.
On the other hand a language based on a standard like ECMA might be a better option — such as DMDScript , SEE: Simple ECMAScript Engine or
Spider Monkey.





Post a Comment