Skip to content

Commit

Permalink
Added serpent as a dependency, made it default in luarun and added it…
Browse files Browse the repository at this point in the history
… to luarun's preloaded packages.
  • Loading branch information
topkecleon committed Jan 22, 2018
1 parent 0ce526d commit 4f1005f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 21 deletions.
2 changes: 0 additions & 2 deletions config.lua
Expand Up @@ -53,8 +53,6 @@ Send /help to get started.
nasa_api_key = nil,
-- http://tech.yandex.com/keys/get
yandex_key = nil,
-- Whether luarun should use serpent instead of dkjson for serialization.
luarun_serpent = false,

hackernews = {
-- Interval (in minutes) for hackernews.lua to fetch new posts.
Expand Down
2 changes: 1 addition & 1 deletion install-dependencies.sh
Expand Up @@ -3,7 +3,7 @@

#!/bin/sh

rocklist="dkjson lpeg lrexlib-pcre luasec luasocket multipart-post"
rocklist="dkjson lpeg lrexlib-pcre luasec luasocket multipart-post serpent"
if [ $(lsb_release -r | cut -f 2) == "16.04" ]; then
luaver="5.3"
else
Expand Down
25 changes: 7 additions & 18 deletions otouto/plugins/luarun.lua
Expand Up @@ -9,23 +9,12 @@

local utilities = require('otouto.utilities')
local URL = require('socket.url')
local JSON, serpent
local serpent = require('serpent')

local luarun = {name = 'luarun'}

function luarun:init()
luarun.triggers = utilities.triggers(self.info.username, self.config.cmd_pat):t('lua', true):t('return', true).table
if self.config.luarun_serpent then
serpent = require('serpent')
luarun.serialize = function(t)
return serpent.block(t, {comment=false})
end
else
JSON = require('dkjson')
luarun.serialize = function(t)
return JSON.encode(t, {indent=true})
end
end
-- Lua 5.2 compatibility.
luarun.err_msg = function(x)
return 'Error:\n' .. tostring(x)
Expand Down Expand Up @@ -53,10 +42,11 @@ function luarun:action(msg)
local bindings = require('otouto.bindings')\n\z
local utilities = require('otouto.utilities')\n\z
local drua = require('otouto.drua-tg')\n\z
local JSON = require('dkjson')\n\z
local URL = require('socket.url')\n\z
local HTTP = require('socket.http')\n\z
local HTTPS = require('ssl.https')\n\z
local json = require('dkjson')\n\z
local url = require('socket.url')\n\z
local http = require('socket.http')\n\z
local https = require('ssl.https')\n\z
local serpent = require('serpent')\n\z
return function (self, msg)\n" .. input .. "\nend"
)

Expand All @@ -70,7 +60,7 @@ function luarun:action(msg)
output = 'Done!'
else
if type(output) == 'table' then
local s = luarun.serialize(output)
local s = serpent.block(output, {comment=false})
if URL.escape(s):len() < 4000 then
output = s
end
Expand All @@ -82,4 +72,3 @@ function luarun:action(msg)
end

return luarun

0 comments on commit 4f1005f

Please sign in to comment.