Author Topic: PXLuaSocket-2.0.1  (Read 10952 times)

0 Members and 1 Guest are viewing this topic.

Offline PPK

  • Administrator
  • Emperor
  • *****
  • Posts: 1 478
  • Karma: +209/-22
  • PtokaX developer
PXLuaSocket-2.0.1
« on: 20 September, 2006, 02:30:03 »
For lua 5.0.3
For lua 5.1.1

Source

Initializing in lua 5.0.3 like
Code: [Select]
libinit = loadlib("pxluasocket.dll", "luaopen_pxluasocket")
libinit()

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

Initializing in lua 5.1.1
Code: [Select]
require "pxluasocket"

require "pxluasocketmime"

This will register global socket or mime, more is in docs  8)
« Last Edit: 20 September, 2006, 02:32:37 by PPK »
"Most of you are familiar with the virtues of a programmer. There are three, of course: laziness, impatience, and hubris." - Larry Wall

PtokaX forum

PXLuaSocket-2.0.1
« on: 20 September, 2006, 02:30:03 »

Offline PPK

  • Administrator
  • Emperor
  • *****
  • Posts: 1 478
  • Karma: +209/-22
  • PtokaX developer
Re: PXLuaSocket-2.0.1
« Reply #1 on: 21 September, 2006, 00:06:10 »
Updated PXLuaSocket for lua 5.0.3 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
Code: [Select]
dofile("compat/compat-5.1.lua")

require "pxluasocket"

require "pxluasocketmime"
« Last Edit: 21 September, 2006, 00:50:17 by PPK »
"Most of you are familiar with the virtues of a programmer. There are three, of course: laziness, impatience, and hubris." - Larry Wall

Offline bastya_elvtars

  • Forum God
  • ****
  • Posts: 3 730
  • Karma: +173/-7
  • The rock n' roll doctor
    • The FreshStuff3 Site
Re: PXLuaSocket-2.0.1
« Reply #2 on: 21 September, 2006, 02:46:11 »
Updated PXLuaSocket for lua 5.0.3 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.
Everything could have been anything else and it would have just as much meaning.

Offline st0ne-db

  • Scripter
  • Double Ace
  • ******
  • Posts: 107
  • Karma: +14/-3
Re: PXLuaSocket-2.0.1
« Reply #3 on: 21 September, 2006, 05:49:16 »
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 for Lua 5.0
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:

Code: [Select]
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:
Code: [Select]
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
Code: [Select]
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:
Code: [Select]
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
« Last Edit: 21 September, 2006, 05:51:40 by st0ne-db »

Offline PPK

  • Administrator
  • Emperor
  • *****
  • Posts: 1 478
  • Karma: +209/-22
  • PtokaX developer
Re: PXLuaSocket-2.0.1
« Reply #4 on: 21 September, 2006, 05:52:51 »
Wow it is working  :o
"Most of you are familiar with the virtues of a programmer. There are three, of course: laziness, impatience, and hubris." - Larry Wall

Offline st0ne-db

  • Scripter
  • Double Ace
  • ******
  • Posts: 107
  • Karma: +14/-3
Re: PXLuaSocket-2.0.1
« Reply #5 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??



Offline st0ne-db

  • Scripter
  • Double Ace
  • ******
  • Posts: 107
  • Karma: +14/-3
Re: PXLuaSocket-2.0.1
« Reply #6 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..

Code: [Select]
---------------------------------------------------------------------------
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
Code: [Select]
-----------------------------------------------------------------------------
---- 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:
Code: [Select]
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
}
« Last Edit: 21 September, 2006, 08:16:16 by st0ne-db »

Offline bastya_elvtars

  • Forum God
  • ****
  • Posts: 3 730
  • Karma: +173/-7
  • The rock n' roll doctor
    • The FreshStuff3 Site
Re: PXLuaSocket-2.0.1
« Reply #7 on: 21 September, 2006, 12:35:56 »
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? :)
Everything could have been anything else and it would have just as much meaning.

Offline st0ne-db

  • Scripter
  • Double Ace
  • ******
  • Posts: 107
  • Karma: +14/-3
Re: PXLuaSocket-2.0.1
« Reply #8 on: 21 September, 2006, 17:05:41 »
Care to tell us how you achieved it? :)


I thought i already did...   ???

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 for Lua 5.0
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:

Code: [Select]
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:
Code: [Select]
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
Code: [Select]
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:
Code: [Select]
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...

Code: [Select]
-- 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"
« Last Edit: 21 September, 2006, 17:09:18 by st0ne-db »

Offline PPK

  • Administrator
  • Emperor
  • *****
  • Posts: 1 478
  • Karma: +209/-22
  • PtokaX developer
Re: PXLuaSocket-2.0.1
« Reply #9 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
Code: [Select]
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
Code: [Select]
local socket = require("socket.core")
to
Code: [Select]
local socket = require("pxluasocket")
And in file mime.lua
Code: [Select]
local ltn12 = require("ltn12")
local mime = require("mime.core")
to
Code: [Select]
local ltn12 = require("socket.ltn12")
local mime = require("pxluasocketmime")

After this http.lua loaded without problem...
« Last Edit: 21 September, 2006, 21:56:25 by PPK »
"Most of you are familiar with the virtues of a programmer. There are three, of course: laziness, impatience, and hubris." - Larry Wall

Offline st0ne-db

  • Scripter
  • Double Ace
  • ******
  • Posts: 107
  • Karma: +14/-3
Re: PXLuaSocket-2.0.1
« Reply #10 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:
Code: [Select]
socket = require "socket"
mime = require "mime"

after making the changes you posted to socket.lua, mime.lua everything is loading perfectly  ;D  ;D

Offline bastya_elvtars

  • Forum God
  • ****
  • Posts: 3 730
  • Karma: +173/-7
  • The rock n' roll doctor
    • The FreshStuff3 Site
Re: PXLuaSocket-2.0.1
« Reply #11 on: 21 September, 2006, 23:50:03 »
PPK could you please release an updated version of the lib then?
Everything could have been anything else and it would have just as much meaning.

Offline st0ne-db

  • Scripter
  • Double Ace
  • ******
  • Posts: 107
  • Karma: +14/-3
Re: PXLuaSocket-2.0.1
« Reply #12 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:
Code: [Select]
-- 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"


Offline megacolon

  • Newbie
  • *
  • Posts: 3
  • Karma: +1/-0
Re: PXLuaSocket-2.0.1
« Reply #13 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?

Offline bastya_elvtars

  • Forum God
  • ****
  • Posts: 3 730
  • Karma: +173/-7
  • The rock n' roll doctor
    • The FreshStuff3 Site
Re: PXLuaSocket-2.0.1
« Reply #14 on: 22 August, 2007, 23:52:01 »
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. ;)
Everything could have been anything else and it would have just as much meaning.

Offline megacolon

  • Newbie
  • *
  • Posts: 3
  • Karma: +1/-0
Re: PXLuaSocket-2.0.1
« Reply #15 on: 25 August, 2007, 13:56:07 »
Any other way to get the latest PtokaX version to work with the socket library?

Offline PPK

  • Administrator
  • Emperor
  • *****
  • Posts: 1 478
  • Karma: +209/-22
  • PtokaX developer
Re: PXLuaSocket-2.0.1
« Reply #16 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 ;)
"Most of you are familiar with the virtues of a programmer. There are three, of course: laziness, impatience, and hubris." - Larry Wall

Offline megacolon

  • Newbie
  • *
  • Posts: 3
  • Karma: +1/-0
Re: PXLuaSocket-2.0.1
« Reply #17 on: 27 August, 2007, 14:02:10 »
What exactly do I have to change in order to get it working?

Offline PPK

  • Administrator
  • Emperor
  • *****
  • Posts: 1 478
  • Karma: +209/-22
  • PtokaX developer
Re: PXLuaSocket-2.0.1
« Reply #18 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
"Most of you are familiar with the virtues of a programmer. There are three, of course: laziness, impatience, and hubris." - Larry Wall

PtokaX forum

Re: PXLuaSocket-2.0.1
« Reply #18 on: 14 September, 2007, 21:44:02 »