lua-users home
lua-l archive

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


Reuben Thomas wrote:

I was just wondering what the current state of the art is on changing the char type. I have found LuaPlus, but that has a lot of extra baggage; ideally I'd just like to change Lua's char type to wide character.

Anyone done this?

It may not be what you want but, some time ago i made a small library to handle utf8 strings with an interface similar to the string library provided by lua. The interface is the same (except for string.dump) and all returned strings are *userdata* objects, representing utf8 strings that can be passed to the ustring functions or even use its metatable (which is ustring itself). You can create new utf8 strings with the command "us = ustring.new('string')" or just pass normal strings to the functions; these values will be automaticly converted to its internal representation. After that you can use normal operations on it "us:len()" etc. To get back to the lua string type, use "tostring(us)" or "us:cstr()". Normal string comparison also works. Implicit convertion to lua strings can also happen through its metatable __tostring function.

The drawbacks:
   it is not a "primitive" type, it is not the same as a lua string.
whenever an utf8 string is used it is converted from utf8 to wide character string internaly (not visible from lua)

http://mega.ist.utl.pt/~tngd/lua/lustring-0.1.tar.gz
(as you will notice, there isn't any kind of information apart from the description i am giving on this email)

Tested it on linux and win32 using gcc/mingw.

Hope it helps.
Tiago