From 5912e56015de9c64c0cec60a1c752b7b0697de7b Mon Sep 17 00:00:00 2001 From: Avik Sengupta Date: Sat, 9 Dec 2017 14:49:04 +0000 Subject: [PATCH] Use @struct macro --- src/StrPack.jl | 5 ++--- test/runtests.jl | 18 +++++++++--------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/StrPack.jl b/src/StrPack.jl index 62ae6c7..7a29066 100644 --- a/src/StrPack.jl +++ b/src/StrPack.jl @@ -1,7 +1,6 @@ module StrPack -Base.warn_once("Using v0.2.0 of StrPack, which is incompatible with previous versions") -export @str +export @struct export pack, unpack, sizeof export DataAlign export align_default, align_packed, align_packmax, align_structpack, align_table @@ -31,7 +30,7 @@ immutable Str endianness::Symbol end -macro str(xpr...) +@eval macro $(Symbol("struct"))(xpr...) (typname, typ, asize) = extract_annotations(xpr[1]) if length(xpr) > 3 error("too many arguments supplied to @str") diff --git a/test/runtests.jl b/test/runtests.jl index a815815..52a829d 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,41 +1,41 @@ using Base.Test using StrPack -@str type A +@struct type A a::UInt8 end -@str type B +@struct type B a::Array{UInt8,2}(2,2) end -@str type C +@struct type C a::String(5) end -@str type D +@struct type D a::C end -@str type E +@struct type E a::Array{C,1}(2) end -@str immutable F +@struct immutable F a::Array{Float64,2}(3,2) end abstract type abstractG; end -@str type G1 <: abstractG +@struct type G1 <: abstractG a::UInt8 end -@str immutable G2 <: abstractG +@struct immutable G2 <: abstractG a::UInt8 end -@str type Hvl_t +@struct type Hvl_t len::Csize_t p::Ptr{Void} end