From 1df5bcf9c397be6e6ee5ad88ae97e7cb1dd25a1e Mon Sep 17 00:00:00 2001 From: Morten Piibeleht Date: Tue, 25 Jun 2024 14:15:35 +1200 Subject: [PATCH] property & repl shenanigans --- src/sandbox.jl | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/sandbox.jl b/src/sandbox.jl index dbfbab1..e8300ef 100644 --- a/src/sandbox.jl +++ b/src/sandbox.jl @@ -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...) @@ -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)