lua-users home
lua-l archive

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


I wrote:
> It's unfortunate to have namespace conflicts in such basic stuff as
> posix and curl. It reminds me of JavaScript; it means my app should
> test for curl.new == None  and use different code accordingly...

steve donovan wrote:
> Oh yes, especially posix - that's really basic functionality.
> E.g.  because both posixes are in the LuaRocks repository,
> I cannot make 'lposix' a dependency on a LR module/script
> without potentially messing up some script that uses 'luaposix'.

<RFC|suggested-enhancements :-) >

For the simpler case of curl, I'd like to propose that the
freepops-luacurl folk add a dummy curl.new function which is
just an alias of curl.easy_init, and a curl.close function which
either does nothing, or cleans up as if c had gone out of scope.

Also that the non-freepops folk add a curl.easy_init function
which is just an alias of curl.new, and to check that curl.close
is invoked automatically when c goes out of scope.

AFAICS, that would fix most of the incompatibilities,
(except perhaps that all callback functions might still have to
test how many arguments they're getting - not sure about this...)

posix is probably harder because there are more functions.
Has anyone made a list of the incompatibilities ?
Is there a reliable app-space test for which posix module is present ?

JavaScript has been messed up deliberately, by huge corporations
creating incompatibilities on purpose in order to make rival browsers
work less well; they are powerful, and they have their motives.
But why Lua?  Why self-inflicted?  It's such a neat language...

I'd also like to propose that luarocks.org and luaforge.net
not adopt any new namespace conflicts.

> in LR previous to 2.0.x, this was resolvable using luarocks.require

If there were a   luarocks register my_new_posix   command in each
post-install script, then luarocks.require could work for dist
packages too.  But it's still confusing when one required sub-module
wants one posix and another required sub-module wants the other.
Or when code is pasted.

Apologies for ranting somewhat ...

Regards,  Peter Billam

P.S.  my function so far, but untested with the non-freepops curl:
  function wget(url)
    local text = {}
    local function WriteMemoryCallback(s)
        text[#text+1] = s
        return string.len(s)
    end
    local c
    if curl.new then c = curl.new() else c = curl.easy_init() end
    c:setopt(curl.OPT_URL, url)
    c:setopt(curl.OPT_WRITEFUNCTION, WriteMemoryCallback)
    c:setopt(curl.OPT_USERAGENT, "luacurl-agent/1.0")
    c:perform()
    if curl.close then c:close() end
    return table.concat(text,'')
  end

http://www.pjb.com.au       pj@pjb.com.au      (03) 6278 9410
 A stich in time saves nine.