lua-users home
lua-l archive

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


2012/7/5 Simon Orde <sorde@gotadsl.co.uk>:

> … let my script-writers write in UTF-16 (or
> whatever) and save the code as UTF-8 to pass to Lua.  This idea hadn't
> occurred to me.  Without thinking about it too carefully, I'd been assuming
> that Lua expects code (e.g. as supplied in a C++ call to lua_load) to be in
> ANSI.  But is your suggestion really always guaranteed to work - even in
> future versions of Lua?  I have to admit, I can't instantly think of any
> reason why it shouldn't.  Sorry to press you on this, but I have read
> "Programming in Lua" and I have the Lua Reference Manual, and I can't find
> anything relevant to this in either of them.

Lua expects code to be in ASCII except inside string literals.

In long strings (delimited by [[…]]) almost anything goes … with one
exception: end-of-line.  Another system's EOL is converted to your
system's EOL.

That is precisely the behaviour you want when the long string contains
some UTF-8 text; I can't speak for UTF-16. But it does mean that the
only way of reliably entering *arbitrary* strings as literals is to
enter them as short strings with non-ASCII characters escaped.