PtokaX forum

Development Section => Extensions for PtokaX Lua => Topic started by: PPK on 20 September, 2006, 02:30:03

Title: PXLuaSocket-2.0.1
Post by: PPK on 20 September, 2006, 02:30:03
For lua 5.0.3 (http://www.ptokax.org/files/Libs/PXLuaSocket-2.0.1-lua5.0.3.7z)
For lua 5.1.1 (http://www.ptokax.org/files/Libs/PXLuaSocket-2.0.1-lua5.1.1.7z)

Source (http://www.ptokax.org/files/Libs/PXLuaSocket-2.0.1-src.7z)

Initializing in lua 5.0.3 like

libinit = loadlib("pxluasocket.dll", "luaopen_pxluasocket")
libinit()

libinit = loadlib("pxluasocket.dll", "luaopen_pxluasocket")
libinit()


Initializing in lua 5.1.1

require "pxluasocket"

require "pxluasocketmime"


This will register global socket or mime, more is in docs  8)
Title: Re: PXLuaSocket-2.0.1
Post by: PPK on 21 September, 2006, 00:06:10
Updated PXLuaSocket for lua 5.0.3 (http://www.ptokax.org/files/Libs/PXLuaSocket-2.0.1-compat-lua5.0.3.7z) with compat-5.1 to allow libs usage in lua 5.1 style  ::)

Is needed file compat-5.1.lua (included in archive) and in this file is needed to define cpath to dir where lib will be. Lib must be in PtokaX dir, then to cpath add "../?.dll;" and i added for test compat-5.1.lua to compat subdir in scripts folder. Initializing work like this

dofile("compat/compat-5.1.lua")

require "pxluasocket"

require "pxluasocketmime"
Title: Re: PXLuaSocket-2.0.1
Post by: bastya_elvtars on 21 September, 2006, 02:46:11
Quote from: PPK on 21 September, 2006, 00:06:10
Updated PXLuaSocket for lua 5.0.3 (http://www.ptokax.org/files/Libs/PXLuaSocket-2.0.1-compat-lua5.0.3.7z) with compat-5.1 to allow libs usage in lua 5.1 style  ::)

The lua files need to be hacked or the whole package needs restructuring, because this won't work out of the box.
Title: Re: PXLuaSocket-2.0.1
Post by: st0ne-db on 21 September, 2006, 05:49:16
Quote from: bastya_elvtars on 21 September, 2006, 02:46:11
The lua files need to be hacked or the whole package needs restructuring, because this won't work out of the box.

I got the packages to load...

This is what i did...

download this distro as well as ppk's lib:

http://luaforge.net/frs/download.php/1617/luasocket-2.0.1-lua50-win32.zip (http://luaforge.net/frs/download.php/1617/luasocket-2.0.1-lua50-win32.zip) for Lua 5.0
http://luaforge.net/frs/download.php/1618/luasocket-2.0.1-lua5.1-win32.zip (http://luaforge.net/frs/download.php/1618/luasocket-2.0.1-lua5.1-win32.zip) for Lua 5.1

create a folder in your PtokaX scripts folder called 'libs'
extract the contents of the Win32 binaries to the libs folder with this file structure:


scripts\libs\compat-51.lua
scripts\libs\ltn12.lua
scripts\libs\mime.lua
scripts\libs\socket.lua
scripts\libs\mime\core.dll
scripts\libs\socket\core.dll
scripts\libs\socket\ftp.lua
scripts\libs\socket\http.lua
scripts\libs\socket\smtp.lua
scripts\libs\socket\tp.lua
scripts\libs\socket\url.lua


next extrack ppk's libs... follow this structure:

scripts\libs\PXLuaSocket.dll
scripts\libs\PXLuaSocket.tds
scripts\libs\PXLuaSocketMime.dll
scripts\libs\PXLuaSocketMime.tds


then rename compat-5.1.lua to compat-51.lua and edit it...

edit the package.path's

package.path = LUA_PATH or os.getenv("LUA_PATH") or
             ("./libs/?.lua;")

package.cpath = LUA_CPATH or os.getenv("LUA_CPATH") or
             "./libs/?.dll;"     


finally load the libs in your script:

dofile("libs/compat-51.lua")
require "pxluasocket"
require "pxluasocketmime"
smtp = require("socket.smtp")


Try this and let me know if it works for you... all these steps might not be necessary.. but this is how i got it working  ;D
Title: Re: PXLuaSocket-2.0.1
Post by: PPK on 21 September, 2006, 05:52:51
Wow it is working  :o
Title: Re: PXLuaSocket-2.0.1
Post by: st0ne-db on 21 September, 2006, 06:14:02
ok... now it seems im having another problem..

the docs for the lib describe all the functions in the socket namespace:

Socket

_DEBUG, dns, gettime, newtry, protect, select, sink, skip, sleep, source, tcp, try, udp, _VERSION.


after i load the libs.... and check whats in the socket namespace... i have access to this:

Socket

protect, dns, gettime, udp, newtry, _VERSION, __unload, select, tcp, skip, sleep, smtp

The smtp module is there!! :)
but.......

socket.try is not :(

this is needed by the smtp module... and from what the docs say is included in the socket namespace...
so if i understand correctly... it shouldnt be necessary to load a module for this function.

it also seems that a few other functions in the socket namespace are missing too..

any ideas??


Title: Re: PXLuaSocket-2.0.1
Post by: st0ne-db on 21 September, 2006, 06:48:32
I have been able to get all the optional modules to load without modifications except socket.http
here are the available functions for each module..


---------------------------------------------------------------------------
socket = {
protect
dns
gettime
udp
newtry
_VERSION
ftp
url
__unload
tcp
tp
select
smtp
skip
sleep
}
---------------------------------------------------------------------------
ltn12 = {
source
_PACKAGE
pump
_VERSION
sink
_NAME
filter
_M
BLOCKSIZE
}
---------------------------------------------------------------------------
mime = {
unqp
eol
_VERSION
unb64
wrp
dot
b64
qpwrp
qp
}
---------------------------------------------------------------------------
smtp = {
SERVER
TIMEOUT
_PACKAGE
send
PORT
open
DOMAIN
message
_NAME
ZONE
_M
}
---------------------------------------------------------------------------
url = {
unescape
_PACKAGE
escape
_VERSION
build_path
_NAME
parse
parse_path
_M
absolute
build
}
---------------------------------------------------------------------------
ftp = {
USER
override
TIMEOUT
_PACKAGE
PASSWORD
open
_NAME
PORT
command
_M
put
get
}
---------------------------------------------------------------------------
tp = {
_NAME
_PACKAGE
_M
TIMEOUT
connect
}
---------------------------------------------------------------------------
http = {
TIMEOUT
_PACKAGE
PORT
open
_NAME
request
_M
USERAGENT
}


not sure why http refuses to load... it doesnt seem any different from the others.. and produces no errors  ???

i have tracked the problem down to this code in http.lua

-----------------------------------------------------------------------------
---- Extra sources and sinks
-------------------------------------------------------------------------------
socket.sourcet["http-chunked"] = function(sock, headers)
    return base.setmetatable({
        getfd = function() return sock:getfd() end,
        dirty = function() return sock:dirty() end
    }, {
        __call = function()
            -- get chunk size, skip extention
            local line, err = sock:receive()
            if err then return nil, err end
            local size = base.tonumber(string.gsub(line, ";.*", ""), 16)
            if not size then return nil, "invalid chunk size" end
            -- was it the last chunk?
            if size > 0 then
                -- if not, get chunk and skip terminating CRLF
                local chunk, err, part = sock:receive(size)
                if chunk then sock:receive() end
                return chunk, err
            else
                -- if it was, read trailers into headers table
                headers, err = receiveheaders(sock, headers)
                if not headers then return nil, err end
            end
        end
    })
end

socket.sinkt["http-chunked"] = function(sock)
    return base.setmetatable({
        getfd = function() return sock:getfd() end,
        dirty = function() return sock:dirty() end
    }, {
        __call = function(self, chunk, err)
            if not chunk then return sock:send("0\r\n\r\n") end
            local size = string.format("%X\r\n", string.len(chunk))
            return sock:send(size ..  chunk .. "\r\n")
        end
    })
end


commenting it out allows the module to load.

i have checked the available functions against the win32 binaries in the lua50 VM. The only functions missng are in the mime and socket tables. All the optional modules are complete.
Running in the Lua5.0 VM returns these functions:

socket = {
        sleep
        source
        newtry
        _VERSION
        connect
        sink
        __unload
        bind
        ftp
        _M
        sinkt
        protect
        skip
        tp
        dns
        _PACKAGE
        select
        udp
        url
        BLOCKSIZE
        sourcet
        tcp
        _NAME
        choose
        try
        smtp
        gettime
        http
}
---------------------------------------------------------------------------
mime = {
        b64
        encode
        _VERSION
        normalize
        dot
        _M
        qpwrp
        qp
        unqp
        decodet
        _PACKAGE
        eol
        stuff
        unb64
        wrp
        _NAME
        wrapt
        wrap
        decode
        encodet
}
Title: Re: PXLuaSocket-2.0.1
Post by: bastya_elvtars on 21 September, 2006, 12:35:56
Quote from: st0ne-db on 21 September, 2006, 06:48:32
I have been able to get all the optional modules to load without modifications except socket.http

Care to tell us how you achieved it? :)
Title: Re: PXLuaSocket-2.0.1
Post by: st0ne-db on 21 September, 2006, 17:05:41
Quote from: bastya_elvtars on 21 September, 2006, 12:35:56
Care to tell us how you achieved it? :)


I thought i already did...   ???

Quote from: st0ne-db on 21 September, 2006, 05:49:16
I got the packages to load...

This is what i did...

download this distro as well as ppk's lib:

http://luaforge.net/frs/download.php/1617/luasocket-2.0.1-lua50-win32.zip (http://luaforge.net/frs/download.php/1617/luasocket-2.0.1-lua50-win32.zip) for Lua 5.0
http://luaforge.net/frs/download.php/1618/luasocket-2.0.1-lua5.1-win32.zip (http://luaforge.net/frs/download.php/1618/luasocket-2.0.1-lua5.1-win32.zip) for Lua 5.1

create a folder in your PtokaX scripts folder called 'libs'
extract the contents of the Win32 binaries to the libs folder with this file structure:


scripts\libs\compat-51.lua
scripts\libs\ltn12.lua
scripts\libs\mime.lua
scripts\libs\socket.lua
scripts\libs\mime\core.dll
scripts\libs\socket\core.dll
scripts\libs\socket\ftp.lua
scripts\libs\socket\http.lua
scripts\libs\socket\smtp.lua
scripts\libs\socket\tp.lua
scripts\libs\socket\url.lua


next extrack ppk's libs... follow this structure:

scripts\libs\PXLuaSocket.dll
scripts\libs\PXLuaSocket.tds
scripts\libs\PXLuaSocketMime.dll
scripts\libs\PXLuaSocketMime.tds


then rename compat-5.1.lua to compat-51.lua and edit it...

edit the package.path's

package.path = LUA_PATH or os.getenv("LUA_PATH") or
             ("./libs/?.lua;")

package.cpath = LUA_CPATH or os.getenv("LUA_CPATH") or
             "./libs/?.dll;"     


finally load the libs in your script:

dofile("libs/compat-51.lua")
require "pxluasocket"
require "pxluasocketmime"
smtp = require("socket.smtp")


Try this and let me know if it works for you... all these steps might not be necessary.. but this is how i got it working  ;D

Optional modules are loaded just like the docs explain...


-- LOAD OPTIONAL MODULES
ltn12 = require "ltn12"
http = require "socket.http"
smtp = require "socket.smtp"
url = require "socket.url"
ftp = require "socket.ftp"
tp = require "socket.tp"
http = require "socket.http"

Title: Re: PXLuaSocket-2.0.1
Post by: PPK on 21 September, 2006, 21:51:08
[21:42] Syntax ./socket/http.lua:88: attempt to index field `sourcet' (a nil value)  ::)

I try to changed loading to like this

require "socket.socket"

require "socket.mime"

ltn12 = require "socket.ltn12"
http = require "socket.http"
smtp = require "socket.smtp"
url = require "socket.url"
ftp = require "socket.ftp"
tp = require "socket.tp"
http = require "socket.http"


And changed in socket.lua

local socket = require("socket.core")

to

local socket = require("pxluasocket")

And in file mime.lua

local ltn12 = require("ltn12")
local mime = require("mime.core")

to

local ltn12 = require("socket.ltn12")
local mime = require("pxluasocketmime")


After this http.lua loaded without problem...
Title: Re: PXLuaSocket-2.0.1
Post by: st0ne-db on 21 September, 2006, 23:13:12
Hell yeah PPK!!! All the libs are loading and complete  ;D

Although to get mine to work i had to load the cores like this:

socket = require "socket"
mime = require "mime"


after making the changes you posted to socket.lua, mime.lua everything is loading perfectly  ;D  ;D
Title: Re: PXLuaSocket-2.0.1
Post by: bastya_elvtars on 21 September, 2006, 23:50:03
PPK could you please release an updated version of the lib then?
Title: Re: PXLuaSocket-2.0.1
Post by: st0ne-db on 22 September, 2006, 00:00:06
Here is a copy of all the needed file modified to work.

put the libs folder in your PtokaX\scripts folder

Load the libs like this:

-- LOAD THE CORES
socket = require "socket"
mime = require "mime"
-- LOAD OPTIONAL MODULES
ltn12 = require "ltn12"
http = require "socket.http"
smtp = require "socket.smtp"
url = require "socket.url"
ftp = require "socket.ftp"
tp = require "socket.tp"
http = require "socket.http"


Title: Re: PXLuaSocket-2.0.1
Post by: megacolon on 22 August, 2007, 17:36:33
I get the following error message:
PtokaX\scripts\libs\ltn12.lua:41: bad argument #1 to 'getn' (table expected, got nil)
Maybe it's not compatible with PX v.0.3.6.0?
Title: Re: PXLuaSocket-2.0.1
Post by: bastya_elvtars on 22 August, 2007, 23:52:01
Quote from: megacolon on 22 August, 2007, 17:36:33
I get the following error message:
PtokaX\scripts\libs\ltn12.lua:41: bad argument #1 to 'getn' (table expected, got nil)
Maybe it's not compatible with PX v.0.3.6.0?

I'd say it's incompatible with Lua 5.1. BTW nice nick. ;)
Title: Re: PXLuaSocket-2.0.1
Post by: megacolon on 25 August, 2007, 13:56:07
Any other way to get the latest PtokaX version to work with the socket library?
Title: Re: PXLuaSocket-2.0.1
Post by: PPK on 25 August, 2007, 16:23:46
You don't need other way, simply change that few small things in luasocket scripts to lua 5.1 ;)
Title: Re: PXLuaSocket-2.0.1
Post by: megacolon on 27 August, 2007, 14:02:10
What exactly do I have to change in order to get it working?
Title: Re: PXLuaSocket-2.0.1
Post by: PPK on 14 September, 2007, 21:44:02
Because 0.3.6.0d break compatibility with libs, here is PXLuaSocket compiled to use with this new version.
http://www.PtokaX.org/files/Libs-0.3.6.0d/PXLuaSocket.7z


Source - http://www.PtokaX.org/files/Libs-0.3.6.0d/PXLuaSocket-src.7z