Skip to content

Commit

Permalink
add propertynames
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Christ authored and Simon Christ committed Jun 17, 2019
1 parent b507581 commit 4fa3c52
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/ProtoStruct.jl
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
macro proto( name )
ex = quote
struct $name{ NT<:NamedTuple{Syms,T} where {Syms,T} }
struct $name{NT<:NamedTuple}
properties::NT
end # struct

$name(;kwargs...) = $name(kwargs.data)

function Base.getproperty( o::$name, s::Symbol )
return getproperty( getfield(o,:properties), s )
return getproperty( getfield(o, :properties), s )
end # function

function Base.propertynames( o::$name )
return propertynames( getfield(o, :properties) )
end # function
end # quote
esc(ex)
Expand Down
4 changes: 4 additions & 0 deletions test/test_ProtoStruct.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ end # testset
@test test_me.B == "2"
@test test_me.C == complex(1)
end # testset

@testset "Properties" begin
@test propertynames( test_me ) == (:A, :B, :C)
end # testset

2 comments on commit 4fa3c52

@BeastyBlacksmith
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request updated: JuliaRegistries/General/1417

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if Julia TagBot is installed, or can be done manually through the github interface, or via:

git tag -a v0.1.0 -m "<description of version>" 4fa3c521ce44ebfc968d1cdf01597992d421c230
git push origin v0.1.0

Please sign in to comment.