[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  Communicating with the Internet

Communicating with the Internet

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Candido   USA  (78 posts)  [Biography] bio
Date Sat 24 Nov 2007 03:41 PM (UTC)

Amended on Sat 24 Nov 2007 08:48 PM (UTC) by Candido

Message
A while ago I converted my script from Python to Lua, all except for one thing I haven't been able to find a Lua equivalent for:

import urllib
urllib.urlopen("http://www.lusternia.com/vote")

Normally, you open that url in your browser and it votes for Lusternia on topmudsites.com.

I'm not completely sure how this bit of Python works, but when I run it while connected the game gives me a line thanking me for voting. How can I do this in Lua?
[Go to top] top

Posted by Nick Gammon   Australia  (23,016 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Sat 24 Nov 2007 07:00 PM (UTC)
Message
See:

http://www.gammon.com.au/forum/bbshowpost.php?id=4935

My first post there shows a bit of Lua code that accesses a web page.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Candido   USA  (78 posts)  [Biography] bio
Date Reply #2 on Sat 01 Dec 2007 03:32 PM (UTC)
Message
I haven't been able to get this to work. The page you downloaded luasocket-2.0-beta2.tar.gz from seems to be gone, so I looked up luasocket on the Lua Forge.

First I tried the most recent version (luasocket-2.02), but the files were different and I couldn't successfully adapt them to the instructions you gave. Next I tried the oldest version they had (luasocket-2.0-beta3), and while it was more familiar, both the .zip and the .tar.gz were missing some files, notably lua.lua.

So, I did what I could. I copied tp.lua, url.lua, ftp.lua, http.lua, ltn12.lua, mime.lua, smtp.lua, socket.lua, lmime.dll, and lsocket.dll to what I think is the Mushclient directory (C:\Program Files\Mushclient).

Then I tried dofile("http.lua") and dofile("C:\Program Files\Mushclient\http.lua"), and both failed. Where did I go wrong?
[Go to top] top

Posted by Nick Gammon   Australia  (23,016 posts)  [Biography] bio   Forum Administrator
Date Reply #3 on Sat 01 Dec 2007 07:18 PM (UTC)

Amended on Sat 01 Dec 2007 09:00 PM (UTC) by Nick Gammon

Message
Er, yes it got a bit confusing. I took a look at my page here:

http://www.gammon.com.au/forum/?id=7322

That described the DLLs for use with Lua 5.1, which are different from the original post. Then after looking at the complicated instructions halfway down the page ("How to get LuaSocket to work"), and the fact that the LuaSocket file was not available from the advertised location, I simplified things a bit.

What I suggest you do now is:


  • Download this file from my site:

    http://www.gammon.com.au/files/mushclient/lua5.1_extras/luasocket-2.0.1.zip

    This file is 35 Kb. Its md5sum is 7ebacf720d7113a0b261c5e4e315a8c6.

  • Unzip that into the same directory as MUSHclient.exe (eg. c:\Program Files\MUSHclient if that is where you put it).

  • You should end up with three subdirectories:


    • lua (which already exists in the MUSHclient directory). This will have added to it: ltn12.lua, mime.lua and socket.lua.

    • mime - which should contain a single file: core.dll

    • socket - which should contain: core.dll, ftp.lua, http.lua, smtp.lua, tp.lua and url.lua.


  • Now, this test should work:

    
    http = require "socket.http" 
    a, b, c = http.request("http://some.web.site/")
    print (a, b, c)  -- page, return code, headers
    




What I effectively did is reorganize the files in the original .zip file that I downloaded so you didn't need to move them around as described in the earlier post.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Candido   USA  (78 posts)  [Biography] bio
Date Reply #4 on Sat 01 Dec 2007 08:42 PM (UTC)

Amended on Sat 01 Dec 2007 08:44 PM (UTC) by Candido

Message
The link to the file goes to a nonexistent page, but I really appreciate you reorganizing the .zip; that's going to save me a lot of time and frustration.
[Go to top] top

Posted by Nick Gammon   Australia  (23,016 posts)  [Biography] bio   Forum Administrator
Date Reply #5 on Sat 01 Dec 2007 09:01 PM (UTC)
Message
Sorry, I used the name of the original file, then I reorganized it and forgot to change it. The post above has been amended and should now point to the correct file.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Candido   USA  (78 posts)  [Biography] bio
Date Reply #6 on Sat 01 Dec 2007 09:21 PM (UTC)

Amended on Sat 01 Dec 2007 10:15 PM (UTC) by Candido

Message
I unzipped the .zip and all the files were in place as you said they should be, but when I try 'http = require "socket.http"', I get the following error message:

Run-time error
World: CrownSystem
Immediate execution
C:\Program Files\MUSHclient\lua\socket.lua:13: module 'socket.core' not found:
no field package.preload['socket.core']
no file '.\socket\core.lua'
no file 'C:\Program Files\MUSHclient\lua\socket\core.lua'
no file 'C:\Program Files\MUSHclient\lua\socket\core\init.lua'
no file 'C:\Program Files\MUSHclient\socket\core.lua'
no file 'C:\Program Files\MUSHclient\socket\core\init.lua'
stack traceback:
[C]: in function 'require'
C:\Program Files\MUSHclient\lua\socket.lua:13: in main chunk
[C]: in function 'require'
C:\Program Files\MUSHclient\socket\http.lua:11: in main chunk
[C]: in function 'require'
[string "Command line"]:1: in main chunk

What does it mean?
[Go to top] top

Posted by Nick Gammon   Australia  (23,016 posts)  [Biography] bio   Forum Administrator
Date Reply #7 on Sat 01 Dec 2007 10:20 PM (UTC)

Amended on Sat 01 Dec 2007 10:21 PM (UTC) by Nick Gammon

Message
Go to File menu -> Global Preferences. Select the Lua tab and check "Allow DLLs to be loaded".

Then go to the Game menu -> Reload Script File. This re-initializes the script space.

If you don't do that, I get the same error message as you did. You see, the file it is looking for is a DLL.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Candido   USA  (78 posts)  [Biography] bio
Date Reply #8 on Sat 01 Dec 2007 11:05 PM (UTC)
Message
Everything's working perfectly now. Thank you!
[Go to top] top

Posted by Nick Gammon   Australia  (23,016 posts)  [Biography] bio   Forum Administrator
Date Reply #9 on Wed 01 Sep 2010 01:42 AM (UTC)
Message
The LuaSocket files and DLLs are now included in MUSHclient version 4.60 onwards, so you should be able to just use them.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #10 on Wed 01 Sep 2010 01:43 AM (UTC)
Message
*cheers*

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


39,565 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]