logiceditor-com/lua5.1.js — pull request #3 by ggcrunchy (2013-10-02 21:07:51+00:00)
Title: "Bring files up to date" for local testing

Hi.

First of all, this is sort of a mess. **I would not accept it as-is**... (I wasn't sure if this was exactly the best way to send this to you, but I figured you'd at least see it.) I polluted the base directory a bit and there's a bunch of junk (a bunch of "lua" files... just big text files used to make sure the progress bar kicked off) used for testing. Comments are pretty sparse. Mostly a proof of concept, I guess

Also, this is unfortunately probably full of Windows-isms, as I don't have a lot of other things to test on just now. :(

Basically, if you're running as localhost, you can call UpdateLua.BringUpToDate() (see index.html) and it will run the packer on your files if the packed js file isn't current with all of them.

**Stuff**:

The files of interest are server.js, update_lua.js, and packer.lua; driver in index.html.

The server can be run with Node ("node server.js" on the command line).

The progress bars are ugly, but the progress state is decoupled from them, so they can easily be replaced .

**Quirks**:

I don't know if I needed to mess with os.exit() in packer.lua... I thought it was crashing the server some times but I may have misdiagnosed that.

Right now packer.lua just prints to stdout and the server picks that up. I imagine this isn't the best way. :) Sockets or a read-write file or pipe or whatever would probably work (or move the packer into the server code in Node, I guess...), but I tried to use what was there.

I did a crappy thing with file seeks to make sure the byte count was current. I think newlines are the culprit? Anyway, kind of a lazy solution, and it caused me a big speed hit.

The whole thing could probably stand a lot of testing to hit all the error cases and see how robust it is.

**Dependencies**:

- It uses Node.js, since I had it installed from a project last year. I tried Luvit and had some problems. There are three node modules, installed via:

npm install express
npm install http-proxy
npm install dive

The first is the static server I used and the latter two were mostly for convenience.

- Also, LuaJIT should be somewhere (see the execFile in server.js), e.g. in my case I dropped it into the root folder... stricly speaking it could be any lua--in fact I tried to make it use lua5.1.js for a while--but it's hard-coded to LuaJIT at the moment since I had the binary handy.

I am NOT proficient in Node.js or writing servers, so I'm sure this is rather amateur, and would welcome any further improvements. :)