lua-users home
lua-l archive

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


Am 13.04.2017 um 16:28 schröbte Luiz Henrique de Figueiredo:
I'd like to add support for dealing with utf-8 text in Lua 5.1 - for
functions such as string.gsub, string.len and etc. I'm aware 5.3 comes with
a utf8 library but I'm not considering breaking capability for the huge
ecosystem of code that's been developed for 5.1 for my application just yet.

I know there's starwing/luautf8, are there any other options that I should
be considering?

With the simple changes below, lutf8lib.c from 5.3 compiles fine in 5.1.
I haven't tested it though.

It won't work because of `lua_pushfstring(L, "%U", ?)`. You can #define it to something reasonable, though. Compat-5.3[1] has lutf8lib.c backported to Lua 5.1, btw.


    10d9
    < #include "lprefix.h"
    250,251c249,250
    < LUAMOD_API int luaopen_utf8 (lua_State *L) {
    <   luaL_newlib(L, funcs);
    ---
    > LUALIB_API int luaopen_utf8 (lua_State *L) {
    >   luaL_register(L, "utf8", funcs);


Philipp

  [1]: https://github.com/keplerproject/lua-compat-5.3