This commit is contained in:
Andreas Bielawski 2016-09-07 13:07:36 +02:00
commit 855316c216
3 changed files with 40 additions and 17 deletions

View File

@ -1,8 +1,25 @@
# Run Brawlbot in Lua 5.3, if available.
# (Specifying lua5.3 because "lua" is not linked to it in Ubuntu 16.04.)
# Otherwise, use any generic installed Lua.
# If none, give an error and a friendly suggestion.
# If Lua was found, restart Brawlbot five seconds after halting each time.
#!/bin/sh #!/bin/sh
# Launch Brawlbot
# Restart Brawlbot five seconds after halted. # Ubuntu 16.04 seems to not link "lua" to lua5.3.
while true; do if type lua5.3 >/dev/null 2>/dev/null; then
lua main.lua while true; do
echo 'otouto has stopped. ^C to exit.' lua5.3 main.lua
echo "Brawlbot has stopped. ^C to exit."
sleep 5s sleep 5s
done done
elif type lua >/dev/null 2>/dev/null; then
while true; do
lua main.lua
echo "Brawlbot has stopped. ^C to exit."
sleep 5s
done
else
echo "Lua not found."
echo "If you're on Ubuntu, try running ./install-dependencies.sh."
fi

View File

@ -17,6 +17,12 @@ function luarun:init(config)
return JSON.encode(t, {indent=true}) return JSON.encode(t, {indent=true})
end end
end end
-- Lua 5.2 compatibility.
-- "loadstring" was renamed "load" in 5.3.
luarun.loadstring = load or loadstring
luarun.err_msg = function(x)
return 'Error:\n' .. tostring(x)
end
end end
function luarun:action(msg, config) function luarun:action(msg, config)
@ -35,24 +41,21 @@ function luarun:action(msg, config)
input = 'return ' .. input input = 'return ' .. input
end end
local output, success = local output, success = luarun.loadstring(
load("local bot = require('otouto.bot')\n\z "local bot = require('otouto.bot')\n\z
local bindings = require('otouto.bindings')\n\z local bindings = require('otouto.bindings')\n\z
local utilities = require('otouto.utilities')\n\z local utilities = require('otouto.utilities')\n\z
local json = require('dkjson')\n\z local json = require('dkjson')\n\z
local URL = require('socket.url')\n\z local URL = require('socket.url')\n\z
local http = require('socket.http')\n\z local http = require('socket.http')\n\z
local https = require('ssl.https')\n\z local https = require('ssl.https')\n\z
return function (self, msg, config)\n" .. input .. "\nend") return function (self, msg, config)\n" .. input .. "\nend"
)
local function err_msg(x)
return "Fehler:\n" .. tostring(x)
end
if output == nil then if output == nil then
output = success output = success
else else
success, output = xpcall(output(), err_msg, self, msg, config) success, output = xpcall(output(), luarun.err_msg, self, msg, config)
end end
if output == nil then if output == nil then

View File

@ -20,7 +20,6 @@
local utilities = {} local utilities = {}
utf8 = require 'lua-utf8'
ltn12 = require('ltn12') ltn12 = require('ltn12')
http = require('socket.http') http = require('socket.http')
https = require('ssl.https') https = require('ssl.https')
@ -33,6 +32,9 @@ redis = (loadfile "./otouto/redis.lua")()
mime = (loadfile "./otouto/mimetype.lua")() mime = (loadfile "./otouto/mimetype.lua")()
OAuth = require "OAuth" OAuth = require "OAuth"
helpers = require "OAuth.helpers" helpers = require "OAuth.helpers"
-- Lua 5.2 compatibility.
-- If no built-in utf8 is available, load the library.
local utf8 = utf8 or require('lua-utf8')
http.timeout = 5 http.timeout = 5
https.timeout = 5 https.timeout = 5
@ -1104,4 +1106,5 @@ function utilities.fix_utf8(str)
return string.char(utf8.codepoint(str, 1, -1)) return string.char(utf8.codepoint(str, 1, -1))
end end
return utilities return utilities