Browse Source

try to load json.lua or dkjson

master
Sebastian 1 year ago
parent
commit
beb9961bcf
Signed by: imo GPG Key ID: AFA10CBFE4391C0C
2 changed files with 23 additions and 10 deletions
  1. +5
    -5
      README.md
  2. +18
    -5
      cc.lua

+ 5
- 5
README.md View File

@ -25,11 +25,11 @@ Success 200
* [Abhängigkeiten](#abhängigkeiten)
* [Funktionen](#funktionen)
* [new()](#new)
* [new()](#newcn-opts)
* [fetch()](#fetch)
* [solve()](#solve)
* [submit()](#submit)
* [runtime_avg()](#submit)
* [solve()](#solvefn-sbmt)
* [submit()](#submitdata-header)
* [runtime_avg()](#runtime_avg)
* [Beispiele](#beispiele)
* [Tests](#tests)
@ -37,7 +37,7 @@ Success 200
* lua >= 5.1
* [lua-curl](https://github.com/Lua-cURL/Lua-cURLv3)
* [json.lua](https://github.com/rxi/json.lua)
* [json.lua](https://github.com/rxi/json.lua) or [dkjson](http://dkolf.de/src/dkjson-lua.fsl/home)
* [chronos](https://github.com/ldrumm/chronos)
## Funktionen


+ 18
- 5
cc.lua View File

@ -2,16 +2,29 @@
local time = require('chronos')
local curl = require('lcurl')
local json = require('json')
local CC = {
_VERSION = '1.2.0',
-- try to load json.lua or dkjson
local json do
for _, mod in ipairs({ 'json', 'dkjson' }) do
local ok, j = pcall(require, mod)
if ok then
json = j
break
end
end
assert(json, 'json.lua or dkjson is required')
end
local cc = {
_VERSION = '1.2.1',
_DESCRIPTION = 'Lua module for fetching and submitting challenges from The Morpheus coding challenge',
_URL = 'https://git.kokolor.es/imo/coding_challenge_loesung',
_LICENCE = 'The Unlicense'
}
local USERAGENT = ('cc.lua/%s (%s)'):format(CC._VERSION, CC._URL)
local USERAGENT = ('cc.lua/%s libcurl/%s (%s)')
:format(cc._VERSION, curl.version_info('version'), cc._URL)
local URL = 'https://cc.the-morpheus.de/%s/%d/'
-- private functions
@ -88,6 +101,7 @@ end
-- private methods
local CC = {}
--- fetches the challenge
function CC:fetch()
@ -130,7 +144,6 @@ end
-- public methods
local cc = {}
--- create new coding challenge instance
-- cn (number) = challenge number


Loading…
Cancel
Save