PXLuaSocket-2.0.1
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

PXLuaSocket-2.0.1

Started by PPK, 20 September, 2006, 02:30:03

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

PPK

For lua 5.0.3
For lua 5.1.1

Source

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)
"Most of you are familiar with the virtues of a programmer. There are three, of course: laziness, impatience, and hubris." - Larry Wall

PPK

#1
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
dofile("compat/compat-5.1.lua")

require "pxluasocket"

require "pxluasocketmime"
"Most of you are familiar with the virtues of a programmer. There are three, of course: laziness, impatience, and hubris." - Larry Wall

bastya_elvtars

Quote from: PPK 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  ::)

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.

st0ne-db

#3
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 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:

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

PPK

"Most of you are familiar with the virtues of a programmer. There are three, of course: laziness, impatience, and hubris." - Larry Wall

st0ne-db

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??



st0ne-db

#6
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
}

bastya_elvtars

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? :)
Everything could have been anything else and it would have just as much meaning.

st0ne-db

#8
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 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:

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"


PPK

#9
[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...
"Most of you are familiar with the virtues of a programmer. There are three, of course: laziness, impatience, and hubris." - Larry Wall

st0ne-db

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

bastya_elvtars

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.

st0ne-db

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"



megacolon

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?

bastya_elvtars

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. ;)
Everything could have been anything else and it would have just as much meaning.

megacolon

Any other way to get the latest PtokaX version to work with the socket library?

PPK

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

megacolon

What exactly do I have to change in order to get it working?

PPK

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

SMF spam blocked by CleanTalk