functional prototype
This commit is contained in:
parent
5fdb8f98c9
commit
e69c25bce5
|
@ -1,4 +1,5 @@
|
|||
*.so
|
||||
*so
|
||||
/luvit
|
||||
/lit
|
||||
/luvi
|
||||
/base64.lua
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
#!/bin/bash
|
||||
if [ ! -f ./luaqalculator/libqalculator.so ]; then
|
||||
cd luaqalculator
|
||||
make
|
||||
mv libqalculator.so ../
|
||||
cd ..
|
||||
fi
|
||||
if [ ! -f ./luvit ]; then
|
||||
curl -L https://github.com/luvit/lit/raw/master/get-lit.sh | sh
|
||||
fi
|
||||
if [ ! -f ./base64.lua ]; then
|
||||
curl -L https://github.com/iskolbin/lbase64/raw/master/base64.lua > base64.lua
|
||||
fi
|
|
@ -0,0 +1,47 @@
|
|||
local http = require("http")
|
||||
local querystring = require("querystring")
|
||||
local qalculate = require("libqalculator").qalc
|
||||
local base64 = require("base64")
|
||||
|
||||
-- [[
|
||||
-- welcam to best api ever yes
|
||||
-- doing this at like 1 am
|
||||
-- how to use:
|
||||
-- http://localhost:8080/?expression=your shitty expression here&binaryoptions=whatever the fuck
|
||||
-- fields:
|
||||
-- expression (string) - the thing to calculate
|
||||
-- (any of the whatever fields mean that if the option is present, it counts as binary "true". if it isn't, it's a binary "false")
|
||||
-- exact (whatever) - try and give an exact answer (do not calculate irrational fractions)
|
||||
-- interval (whatever) - give an answer in interval when appropriate
|
||||
-- structuring (whatever) - if true, factorize the result. otherwise, expand.
|
||||
-- base64 (whatever) - if true, decode the expression as a base64 string first.
|
||||
|
||||
local function onRequest(req, res)
|
||||
p(req.url:match("%?(.*)$"))
|
||||
local options = querystring.parse(req.url:match("%?(.*)$"))
|
||||
p(options)
|
||||
local expression = options.expression
|
||||
local body
|
||||
if expression then
|
||||
if options.base64 then
|
||||
expression = base64.decode(expression)
|
||||
end
|
||||
body = qalculate(
|
||||
expression,
|
||||
options.exact,
|
||||
options.interval,
|
||||
options.structuring
|
||||
)
|
||||
if not body then
|
||||
body = ""
|
||||
end
|
||||
else
|
||||
body = "Invalid request"
|
||||
end
|
||||
res:setHeader("Content-Type", "text/plain")
|
||||
res:setHeader("Content-Length", #body)
|
||||
res:finish(body)
|
||||
end
|
||||
|
||||
http.createServer(onRequest):listen(8080)
|
||||
print("Server listening at http://localhost:8080/")
|
Loading…
Reference in New Issue