forked from Museus/HadesListener
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathStyxScribeREPL.lua
More file actions
50 lines (43 loc) · 1.2 KB
/
StyxScribeREPL.lua
File metadata and controls
50 lines (43 loc) · 1.2 KB
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
ModUtil.Mod.Register( "StyxScribeREPL" )
StyxScribeREPL.Globals = { }
StyxScribeREPL.Environment = setmetatable( { }, {
__index = function( _, k )
local v = _ENV[ k ]
if v ~= nil then return v end
return StyxScribeREPL.Globals[ k ]
end,
__newindex = function( _, k, v )
if _ENV[ k ] ~= nil then
_ENV[ k ] = v
return
end
StyxScribeREPL.Globals[ k ] = v
end
} )
local function toString( obj )
return ModUtil.ToString.Deep( obj, 500 )
end
function StyxScribeREPL.RunLua( message, echo )
local func, err = load( "return " .. message )
if not func then
func, err = load( message )
if not func then return print( err ) end
end
setfenv( func, StyxScribeREPL.Environment )
local ret = table.pack( pcall( func ) )
if ret.n <= 1 then return end
if echo then
print( ModUtil.Args.Map( toString, table.unpack( ret, 2, ret.n ) ) )
end
return table.unpack( ret, 2, ret.n )
end
function StyxScribeREPL.RunPython( message )
print("StyxScribeREPL: " .. message )
end
local function runLua( message )
return StyxScribeREPL.RunLua( message, true )
end
StyxScribeREPL.Internal = ModUtil.UpValues( function( )
return toString, runLua
end )
StyxScribe.AddHook( runLua, "StyxScribeREPL: ", StyxScribeREPL )