This is a full-featured port of
LuaSocket for GMod. I've tried a simple socket thing, which worked out just fine.
spbogie posted:
I have modified the Lua files to fix the problems with using the sub-modules (socket.http, socket.ftp, etc...).
Required Changes:
Code:
moved socket.lua to /socket/socket.lua
added socket.lua
includes /socket/*.lua in necessary order
changed /socket/mime.lua
removed reqiure( "io" ) - unused, not available in gmod
changed /socket/smtp.lua
Line 33: DOMAIN = os.getenv("SERVER_NAME") or "localhost"
to: DOMAIN = "localhost"
os.getenv not available in gmod
Calling require( "socket" ) will load all sub-modules as well.
Fix is available at
http://people.msoe.edu/~bogies/luasocket_fix.zip.
Includes only modifications made, simply extract over existing install.
Installation instructions:
Extract that archive in garrysmod/lua/includes/modules.
You will need the VS2008 runtime libs, or else you'll get a strange error while loading:
http://www.microsoft.com/downloads/d...displaylang=en
Don't ask any questions unless you've installed that (and rebooted)
Usage:
Just like
LuaSocket, see this for a reference:
http://www.tecgraf.puc-rio.br/~diego...reference.html
Don't forget forget to use non-blocking sockets (set timeout to 0) or else GMod freezes while waiting for data!
Source code:
It's a VS 2008 project, should work in the Express version.
Thanks to:
Sechs - helped me with testing in #luahelp
Jinto - provided the Lua import library
Small example:
require("socket")
local s = socket.connect("www.google.com", 80)
s:send("GET / HTTP/1.1\n")
s:send("Host: www.google.com\n")
s:send("User-Agent: GMod10\n")
s:send("Connection: Close\n")
s:send("\n")
local line = s:receive('*line')
print(line)
s:close()
I don't know if that is correct but it should give you an idea about how it's used. You don't even have to use it manually, there are some helper modules too (http, smtp, ftp), but they don't seem to work. they probably would with some modification.