lua-users home
lua-l archive

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


On Thu, Aug 15, 2013 at 5:39 AM, Sean Conner <sean@conman.org> wrote:
>> My approach would be to bind individual POSIX functions as tightly as
>> possible, and only deviating when necessary to keep the interface to
>> Lua clean and usable. It seems like the current API can't decide
>> whether it wants to be high or low level.
>
>   That's pretty much the approach I took, except that I don't have a
> getpid() function (org.conman.process.PID contains the current PID).  But I
> do have setuid(), setgid(), getuid(), getgid(), etc.

Tight binding works much better I think,. For ljsyscall (which is a
subset of posix in effect) I do have getpid().

>> 3) Error reporting
>>
>> In Prosody's POSIX library we have fixed error strings such as
>> "permission-denied", which are more important than the
>> locale-dependent human-readable strings given by strerror() (ideally
>> we would have a function to return strerror() for any error name).
>
>   I handled that by setting the __index() method on org.conman.errno:
>
>         errno = require "org.conman.errno"
>         print(errno[23])
>
>   I also have (as far as I can determine) a predefined set of errors defined
> in org.conman.errno so one can check for specific errors:
>
>         if err = errno.EINTR then
>          ...
>         elseif err == errno.ETIMEDOUT then
>          ...
>         end
>
>  I should also note that all of my Posix routines return errno as the second
> result (if no error, then it returns 0).  I'm consistent in this, because
> consistency is good.

For ljsyscall I return an error object such that you can get
err.errno, can call tostring on it to get the message, plus you can
test flags so err.PERM is true for EPERM etc, so you do not need to
compare against the constant directly, which is even more concise than
your version.


>> 4) Documentation
>>
>> A big issue, especially with the current bizarre API - there's
>> basically no way to use the library without reading the source, unless
>> I've missed the documentation somewhere (I do find it hard to believe
>> a library that has been around so long has none).
>
>   Alas, that's a problem I have ...

ditto.

>   -spc
>
> [1]     https://github.com/spc476/lua-conmanorg
>
>