-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
78 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
mutable struct EditorExport{T} | ||
value::T | ||
|
||
# Inner constructor | ||
function EditorExport(value::T) where T | ||
return new{T}(value) # Use `new` to construct the object | ||
end | ||
end | ||
|
||
# Overload `getproperty` to access `value` transparently | ||
function Base.getproperty(editor::EditorExport{T}, sym::Symbol) where T | ||
if sym === :value | ||
return getfield(editor, :value) # Preserve direct access to `value` | ||
else | ||
return editor.value # Redirect other accesses to `value` | ||
end | ||
end | ||
|
||
# Overload `setproperty!` to modify `value` transparently | ||
function Base.setproperty!(editor::EditorExport{T}, sym::Symbol, new_value) where T | ||
if sym === :value | ||
setfield!(editor, :value, new_value) # Directly update `value` | ||
else | ||
editor.value = new_value # Redirect updates to `value` | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
abstract type Script end | ||
|
||
function Base.getproperty(script::Script, property::Symbol) | ||
if isa(getfield(script, property), EditorExport) | ||
return getfield(script, property).value | ||
end | ||
|
||
return getfield(script, property) | ||
end | ||
|
||
function Base.setproperty!(script::Script, property::Symbol, value) | ||
field = findfirst(f->f==property, fieldnames(typeof(script))) | ||
|
||
if fieldtype(typeof(script), field) <: EditorExport | ||
setfield!(script, property, EditorExport(value)) | ||
else | ||
setfield!(script, property, value) | ||
end | ||
end | ||
|
||
# TODO: Add a way to add custom fields to scripts |