-
Notifications
You must be signed in to change notification settings - Fork 0
/
sh_luadev.lua
50 lines (50 loc) · 1.15 KB
/
sh_luadev.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
return function(sfc3)
function sfc3.luadev_loadstring(code, name)
local func, err = loadstring(code, name)
if func ~= nil and not isfunction(func) then
func, err = nil, func
end
if func == nil then
if istable(err) then
err = rawget(err, 'message')
end
err = tostring(err)
end
return func, err
end
function sfc3.luadev_retval(success, ...)
if not success then
local err = ...
if istable(err) then
err = rawget(err, 'message')
end
err = tostring(err)
return success, err
end
local t = {}
for i=1, select('#', ...) do
t[i] = tostring(select(i, ...))
end
return success, table.concat(t, "\t")
end
function sfc3.luadev_eval(identifier, code, executor, print_result)
local name, func, err = "Validation"
if print_result then
func, err = sfc3.luadev_loadstring('return '..code, name)
end
if func == nil then
func, err = sfc3.luadev_loadstring(' '..code, name)
end
if func == nil then
return false, err, true
end
local success, retval = sfc3.luadev_retval(pcall(func))
if not success then
return false, retval
end
if print_result then
return true, retval
end
return true
end
end