lua-users home
lua-l archive

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

On Tue, Jun 15, 2010 at 8:57 PM,  <> wrote:
> As I pass it around in Lua, it removes the \ and becomes C:\a\b\c.. and so
> on..

this is your problem:  Lua doesn't "remove the \"

What happens is that the compiler reads the \\ and stores \ in the
string.  from that point on, all strings are managed as binary blocks
of bytes.  you can pass them around on variables, write to files, read
from there, etc. they won't be modified behind your back.

the only thing that might be confusing is if the file you're writing
is a new Lua script, to be passed (again) through the compiler.  in
that case, you have to 'requote' any string to be sure they'll be
interpreted correctly by the next compiler pass.  that's what the %q
feature of string.format() does.   But that's only if you're writing
Lua scripts, you don't need that if you're writing data files and
reading them with file:read()