2019-10-21 21:04:55 +08:00
|
|
|
local runners = {}
|
|
|
|
|
|
|
|
function runners.lua(arg)
|
|
|
|
local code, err = load('return ' .. arg, '@runcode')
|
|
|
|
|
|
|
|
-- if failed, try without return
|
|
|
|
if err then
|
|
|
|
code, err = load(arg, '@runcode')
|
|
|
|
end
|
2017-09-05 17:58:39 +08:00
|
|
|
|
|
|
|
if err then
|
|
|
|
print(err)
|
|
|
|
return nil, err
|
|
|
|
end
|
|
|
|
|
|
|
|
local status, result = pcall(code)
|
|
|
|
print(result)
|
|
|
|
|
|
|
|
if status then
|
|
|
|
return result
|
|
|
|
end
|
2019-10-21 21:04:55 +08:00
|
|
|
|
|
|
|
return nil, result
|
|
|
|
end
|
|
|
|
|
|
|
|
function runners.js(arg)
|
|
|
|
return table.unpack(exports[GetCurrentResourceName()]:runJS(arg))
|
|
|
|
end
|
|
|
|
|
|
|
|
function RunCode(lang, str)
|
|
|
|
return runners[lang](str)
|
2017-09-05 17:58:39 +08:00
|
|
|
end
|