Skip to content

Commit

Permalink
property & repl shenanigans
Browse files Browse the repository at this point in the history
  • Loading branch information
mortenpi committed Jun 25, 2024
1 parent 412e9af commit 1df5bcf
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/sandbox.jl
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,28 @@ Contains the result of an evaluation (see [`evaluate!`](@ref)).
"""
struct Result
sandbox::Sandbox
value::AbstractValue
_value::AbstractValue
output::String
show::String
_source::Union{String, Nothing}
_expressions::Vector{Tuple{Any, String}}
end

function Base.getproperty(r::Result, name::Symbol)
if name === :error
return getfield(r, :_value) isa ExceptionValue
elseif name === :value
# TODO: change to _value[] ?
return getfield(r, :_value)
else
return getfield(r, name)
end
end

function Base.propertynames(::Type{Result})
return (:sandbox, :value, :output, :show, :error)
end

"""
evaluate!(sandbox::Sandbox, [code::AbstractString]; kwargs...)
Expand Down Expand Up @@ -131,9 +146,9 @@ function evaluate!(sandbox::Sandbox; color::Bool=true, repl::Bool=false)
# TODO: use keywords, linenumbernode?
expressions = _parseblock(code)
for (ex, str) in expressions
# if repl
# ex = REPL.softscope(ex)
# end
if repl
ex = REPL.softscope(ex)
end
c = IOCapture.capture(; rethrow=InterruptException, color) do
cd(sandbox.pwd) do
Core.eval(sandbox.m, ex)
Expand Down

0 comments on commit 1df5bcf

Please sign in to comment.