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


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  Programming
. -> [Folder]  General
. . -> [Subject]  Lua compiler for windows

Lua compiler for windows

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


Pages: 1 2  

Posted by Metsuro   USA  (389 posts)  [Biography] bio
Date Sat 19 Jan 2008 03:09 AM (UTC)
Message
there a way to run and play with lua in a windows os?

Everything turns around in the end
[Go to top] top

Posted by Nick Gammon   Australia  (22,966 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Sat 19 Jan 2008 05:41 AM (UTC)
Message
See:

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

This has the Lua 5.1 executable in it.

- Nick Gammon

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

Posted by Metsuro   USA  (389 posts)  [Biography] bio
Date Reply #2 on Sat 19 Jan 2008 06:53 PM (UTC)

Amended on Sat 19 Jan 2008 06:54 PM (UTC) by Metsuro

Message
ok since i made this thread donno if I should make a second for this next question I am trying to change something from python to lua just to play around a bit but I actually dont know any python soo..

This is the example of how to do what I want to in python, but I'd like to achieve the same thing in lua...
# short testing script which fetches recent market transactions; this only prints out
# the data, it's an exercise to the reader to parse the XML and do something useful
# with the data.
import httplib, urllib

# setup the parameters we will be sending to the webserver; note that all of this
# information is gathered from the API Key page that the user should visit, and
# the characterID is gathered from /account/Characters.xml.aspx
params = urllib.urlencode( {
    'characterID': xxx,
    'userid': xxx,
    'apikey': 'xxx',
    } )

# connect to server, POST our request, fairly simple stuff...
headers = { "Content-type": "application/x-www-form-urlencoded" }
conn = httplib.HTTPConnection("api.eve-online.com")
conn.request("POST", "/char/WalletTransactions.xml.aspx", params, headers)

# now get response from server, print out the status code for debugging
response = conn.getresponse()
print response.status, response.reason

# now print the data; at this point you'd want to do XML parsing and do whatever
# else you want... well, after probably doing conn.close below
data = response.read()
print data

# OCD comment placement
conn.close

Everything turns around in the end
[Go to top] top

Posted by Nick Gammon   Australia  (22,966 posts)  [Biography] bio   Forum Administrator
Date Reply #3 on Sat 19 Jan 2008 07:52 PM (UTC)
Message
See this:

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

I used Lua to get a web page back.

- Nick Gammon

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

Posted by Metsuro   USA  (389 posts)  [Biography] bio
Date Reply #4 on Sun 20 Jan 2008 05:05 AM (UTC)

Amended on Sun 20 Jan 2008 05:21 AM (UTC) by Metsuro

Message
ok another stupid question this method is not compatible with 5.1 just 5.0? or is it just me... I cant seem to get it to work with the 5.1 but i can with 5.0 this is the error i get in 5.1

> http = require "http"
lua.lua:15: attempt to index global '_LOADED' (a nil value)
stack traceback:
        lua.lua:15: in function 'require'
        stdin:1: in main chunk
        [C]: ?

Everything turns around in the end
[Go to top] top

Posted by Nick Gammon   Australia  (22,966 posts)  [Biography] bio   Forum Administrator
Date Reply #5 on Sun 20 Jan 2008 06:05 AM (UTC)

Amended on Sun 20 Jan 2008 06:06 AM (UTC) by Nick Gammon

Message
Ah yes, well that was my initial post done for Lua 5.0.

See this:

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

Scroll down to "How to get LuaSocket to work".


Also see:

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


The second post is more recent. If you follow that it should work OK.

- Nick Gammon

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

Posted by Metsuro   USA  (389 posts)  [Biography] bio
Date Reply #6 on Sun 20 Jan 2008 06:53 AM (UTC)
Message
Well ok I got it load a webpage and all but i'm still rather confused on the urlencode, and the connection bits cause I can view the site no problem, but the connecting to it and sending the data for what I want I dont understand I guess.

Everything turns around in the end
[Go to top] top

Posted by Metsuro   USA  (389 posts)  [Biography] bio
Date Reply #7 on Sun 20 Jan 2008 07:43 AM (UTC)
Message
After ,urking around I found all i needed.

Everything turns around in the end
[Go to top] top

Posted by Metsuro   USA  (389 posts)  [Biography] bio
Date Reply #8 on Mon 21 Jan 2008 12:54 AM (UTC)
Message
Ok guys I'm sorry if I'm being a bother but... I can view this file through a web browser http://api.eve-online.com/char/CharacterSheet.xml.aspx?userID=1075019&apiKey=crwY4h9679J5ab0py2SL8G9xtOhFB0tLuayoh6aEr5a4iDgwPrUMG7qWpzogZpki&characterID=1097517373

This is my character sheet for eve online. There are a few programs out that can use this information and display it fun way... and what I'm trying to do is mess with this so i can make character backups for myself aswell as help my corp out in the game... only problem is when using luasocket to access the address above and try to print it, it returns nil. But i can use this one and retrieve it just fine. So i'm at a lose... this here is the address to the dev wiki for this api stuff for eve online if anyone wouldn't mind taking a shot at it to help me out. http://wiki.eve-dev.net/Main_Page

Everything turns around in the end
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio
Date Reply #9 on Mon 21 Jan 2008 01:30 AM (UTC)
Message
That is because what you gave isn't a URL: it's a URL with POST parameters.

The URL is:
http://api.eve-online.com/char/CharacterSheet.xml.aspx
The POST parameters are:
userID=1075019
apiKey=crwY4h9679J5ab0py2SL8G9xtOhFB0tLuayoh6aEr5a4iDgwPrUMG7qWpzogZpki
characterID=1097517373

When you make the socket HTTP request, you need to use just the URL portion as the 'url' parameter, and add the parameters one per line as the request body. I think that LuaSocket will set the request method to POST for you.

See:
http://www.tecgraf.puc-rio.br/~diego/professional/luasocket/http.html#request

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
[Go to top] top

Posted by Isthiriel   (113 posts)  [Biography] bio
Date Reply #10 on Mon 21 Jan 2008 03:15 AM (UTC)
Message
That's a GET query string, not POST :P and it is a URL. (or URN, URI whatever...)

The EVE API actually prefers POST for most things (and why they couldn't have just used REST, or SOAP, or XML-RPC like sane code monkeys, no-one will ever know) but GET is designed to work for testing.

And, just testing it:

import urllib2
urllib2.urlopen("...").read()

works fine in the python interactive interpreter.

So, LuaSocket is doing Something it shouldn't, or failing to do something it should. The EVE API might be filtering on the UserAgent header, or expecting HTTP/1.1 with Date and Host headers, or an eTag, or Last-Modified header or any of a number of other headers that the python urllib2 library does for you and the LuaSocket might not.

Why does it need to be Lua? (Especially since you don't seem to be planning this as a MUSHclient plugin.)

I was writing my own Python client back when it was in beta but Entity finished his first and feature-wise it blew mine out of the water so I never got around to finishing mine.

(And it's probably not a brilliant idea to share either your basic or full API key like that, particularly if you're in a player corp :P)
[Go to top] top

Posted by Nick Gammon   Australia  (22,966 posts)  [Biography] bio   Forum Administrator
Date Reply #11 on Mon 21 Jan 2008 04:20 AM (UTC)

Amended on Mon 21 Jan 2008 05:03 AM (UTC) by Nick Gammon

Message
As far as I can make out, the Lua interface generates a reasonable HTTP request, even if you combine everything into the URL. I tested it with trying to access a forum page and it worked fine.

However I also confirm that the URL for the Eve Online character did not work. I am not sure exactly why, but they may be checking for certain web browsers and if they don't get it they close the connection.

Luasocket has a more advanced interface, see:

http://www.tecgraf.puc-rio.br/~diego/professional/luasocket/http.html

Using that you can specify your own headers, however you would need to know what it is expecting. A packet sniffer might help in that regards.

- Nick Gammon

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

Posted by David Haley   USA  (3,881 posts)  [Biography] bio
Date Reply #12 on Mon 21 Jan 2008 05:01 AM (UTC)
Message
Err. Sorry, yeah, I meant get with parameters, not post... although I probably said post because I'm used to sending parameters with post, not get... bleh. :P

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
[Go to top] top

Posted by Metsuro   USA  (389 posts)  [Biography] bio
Date Reply #13 on Mon 21 Jan 2008 05:35 AM (UTC)
Message
well i tried using like

 a = http.request{method="POST", url"http://api.eve-online.com/char/CharacterSheet.xml.aspx?userID=1075019&apiKey=crwY4h9679J5ab0py2SL8G9xtOhFB0tLuayoh6aEr5a4iDgwPrUMG7qWpzogZpki&characterID=1097517373"}


which again didn't work... in the example it uses a header content-type but I'm not exactly sure how to do that using this method.

example was
conn.request("POST", "/char/WalletTransactions.xml.aspx", params, headers)


the params being of course my userid charid and apikey

Everything turns around in the end
[Go to top] top

Posted by Isthiriel   (113 posts)  [Biography] bio
Date Reply #14 on Mon 21 Jan 2008 12:23 PM (UTC)

Amended on Mon 21 Jan 2008 12:27 PM (UTC) by Isthiriel

Message
A GET request is a standard http request for a document. POST requests need the CGI parameters (everything after the ? in a GET request) to be passed in the body of the message, and in some cases, the presence of a Content-Type: application/x-www-form-urlencoded header.

Python's urllib2 handles that for you transparently.

Quote:
I am not sure exactly why, but they may be checking for certain web browsers and if they don't get it they close the connection.

The API is intended for tool developers. In the documentation they recommend providing a unique User-Agent string so that they can potentially tailor a response (ie if the tool is in the wild and the API is updated, they might keep the old response format for a certain User-Agent string). However CCP being CCP and the EVE API being Garthagk's pet project (and Garthagk no longer being an employee of CCP...) it's entirely possible that not receiving a User-Agent string at all causes something to fail silently.

The point is if you just telnet to api.eve-online.com on port 80 and manually enter the GET query, the connection is terminated before the server sends anything... so the ASP process is dying (or being killed?) before it even gets the opportunity to generate an HTTP response code.

Ok, it turns out that the dead simple example given on the API website (using httplib instead of urllib2) uses HTTP/1.1 and sends the GET string, the (required) Host header and an Accept-encoding header.

The issue might be as simple as api.eve-online.com being a virtual site? Or IIS is configured to drop HTTP/1.0 and HTTP/0.9 connections.

Anyway, using telnet to api.eve-online.com on port 80 I verified that EVE API will respond to:
GET /<querystring> HTTP/1.1
Host: api.eve-online.com



So, we presume that LuaSocket either doesn't know about HTTP/1.1 or doesn't produce compliant messages (ie missing host header or the HTTP/1.1 tag).
[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.


65,978 views.

This is page 1, subject is 2 pages long: 1 2  [Next page]

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]