lua-users home
lua-l archive

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


2014-04-22 7:05 GMT+02:00 Dirk Laurie <dirk.laurie@gmail.com>:
> 2014-04-22 6:38 GMT+02:00 Hisham <h@hisham.hm>:
>> On 22 April 2014 01:30, Dirk Laurie <dirk.laurie@gmail.com> wrote:
>>>
>>> 2014-04-22 0:08 GMT+02:00 Sean Conner <sean@conman.org>:
>>>
>>> >   Okay, I finally got the rockspec made, it's been uploaded to Luarocks and
>>> > best of all, it no longer requires a C99 compiler.  An interface to IConv, a
>>> > character set conversion library.  Sample usage:
>>> >
>>> >         iconv = require "org.conman.iconv"
>>> >         trans = iconv.open("iso-8859-1","utf-8")
>>> >         iso   = "This is \225 test"
>>> >         utf   = trans(iso)
>>> >         print(utf)
>>> >         This is á test
>>> >
>>> >   License is LGPL.
>>> >
>>> >   -spc
>>> >
>>> >
>>>
>>> $ luarocks download org.conman.iconv
>>>
>>> Error: Could not find a result named org.conman.iconv.
>>
>> ?... It's there:
>>
>> http://luarocks.org/repositories/rocks/#org.conman.iconv
>>
>> ] bin/luarocks search org.conman.iconv
>>
>> Search results:
>> ===============
>>
>> Rockspecs and source rocks:
>> ---------------------------
>>
>> org.conman.iconv
>>    1.1.1-1 (rockspec) - http://www.luarocks.org/repositories/rocks
>>    1.1.1-1 (src) - http://www.luarocks.org/repositories/rocks
>>    1.1.0-1 (rockspec) - http://www.luarocks.org/repositories/rocks
>>    1.1.0-1 (src) - http://www.luarocks.org/repositories/rocks
>>
>> -- Hisham
>>
>
> Is it still 5.1 only? That would explain it, since my default Lua is 5.2.

Well, I checked, and it's yes.

There are at present two iconv rocks:

lua-iconv

Pro:
1. It builds under >= 5.1.
2. It has names in the module for the error returns, so that one can test
against iconv.ERROR_INCOMPLETE etc.
Con:
1. The arguments to iconv.new go TO,FROM whereas one's system
iconv goes FROM,TO.
2. It has one metatable only. So you need to say iconv.new to make
the converter and trans:iconv to invoke it.
3. The error returns are not the ones returned by the system iconv.
So you really need those error names.

org.conman.iconv

Pro:
1 .The user interface allows intuitive syntax by returning a callable
table that returns a callable userdata. So you say iconv(FROM.TO)
to make the converter and trans(STRING) to invoke it.
Con:
1. It does not builds under Lua > 5.1.
2. It returns the same errors as the system iconv, but you need
another module by the same author, not available as a rock,
to make sense of them.

So I have in the meantime made the version I prefer, which does
basically the same as org.conman.iconv, but builds under Lua 5.1,
5.2 and 5.3, and eturns the converter factory as a function, not
a table, and gives string error messages, not numbers.

I'm not saying my version is better than either of the others,
and it is certainly not original, being a small modification of
org.conman.iconv, only that I like it better.

What my version does illustrate is a fundamental reason why Lua
will not soon, and maybe never, have "blessed" application libraries.
Every Lua user has different preferences, and Lua is easy enough
to modify, even at the C API level, to allow one to implement them
rather than live with some one else's preferences.