lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

On 1/18/12, Tom N Harris <> wrote:
> On 01/17/2012 05:08 PM, joao lobato wrote:
>> Also also, when you do need to use loadstring(), you should consider
>> using string.format() instead of all the string concatenation.
> Lua handles string concatenation quite well. I long chain of `..'
> operations will just emit a series of register loads followed by a
> single CONCAT opcode.
> On the other hand, string.format has the %q option which makes it safer
> for building strings that will be compiled. Perhaps this is what Joao
> was implying. Doing `code = "'" .. some_string .. "'"' invites arbitrary
> execution if some_string isn't properly protected.
> --
> - tom

You give me more credit than you should :-), I meant for performance
reasons, guess I was wrong.

However, imho, string.format is much more readable (no need to quote
quotation marks, easier to indent, the %s and %q stand out...)