Skip to content

Commit

Permalink
put defaults back the way they were
Browse files Browse the repository at this point in the history
  • Loading branch information
rjkat committed Jan 4, 2019
1 parent a72ba39 commit e5d3b55
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 29 deletions.
4 changes: 2 additions & 2 deletions src/FlatBuffers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ slot_offsets(T) = [4 + ((i - 1) * 2) for i = 1:length(T.types)]

default(T, TT, sym) = default(TT)
default(::Type{T}) where {T <: Scalar} = zero(T)
default(::Type{T}) where {T <: AbstractString} = nothing
default(::Type{T}) where {T <: AbstractString} = ""
default(::Type{T}) where {T <: Enum} = enumtype(T)(T(0))
default(::Type{Vector{T}}) where {T} = nothing
default(::Type{Vector{T}}) where {T} = T[]

# attempt to call default constructors for the type,
# use above methods as fallback
Expand Down
47 changes: 24 additions & 23 deletions test/MyGame/Example/Monster.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@ FlatBuffers.@with_kw mutable struct Monster{T}
pos::Union{Vec3, Nothing} = nothing
mana::Int16 = 150
hp::Int16 = 100
name::Union{String, Nothing} = nothing
inventory::Union{Vector{UInt8}, Nothing} = nothing
name::String = ""
inventory::Vector{UInt8} = []
color::Color = 8
test_type::UInt8 = 0
test::T = nothing
test4::Union{Vector{Test}, Nothing} = nothing
testarrayofstring::Union{Vector{String}, Nothing} = nothing
test4::Vector{Test} = []
testarrayofstring::Vector{String} = []
#=
# an example documentation comment: this will end up in the generated code
# multiline too
=#
testarrayoftables::Union{Vector{Monster{T}}, Nothing} = nothing
testarrayoftables::Vector{Monster{T}} = []
enemy::Union{Monster{T}, Nothing} = nothing
testnestedflatbuffer::Union{Vector{UInt8}, Nothing} = nothing
testnestedflatbuffer::Vector{UInt8} = []
testempty::Union{Stat, Nothing} = nothing
testbool::Bool = false
testhashs32_fnv1::Int32 = 0
Expand All @@ -36,29 +36,30 @@ FlatBuffers.@with_kw mutable struct Monster{T}
testhashu32_fnv1a::UInt32 = 0
testhashs64_fnv1a::Int64 = 0
testhashu64_fnv1a::UInt64 = 0
testarrayofbools::Union{Vector{Bool}, Nothing} = nothing
testarrayofbools::Vector{Bool} = []
testf::Float32 = 3.14159
testf2::Float32 = 3.0
testf3::Float32 = 0.0
testarrayofstring2::Union{Vector{String}, Nothing} = nothing
testarrayofsortedstruct::Union{Vector{Ability}, Nothing} = nothing
flex::Union{Vector{UInt8}, Nothing} = nothing
test5::Union{Vector{Test}, Nothing} = nothing
vector_of_longs::Union{Vector{Int64}, Nothing} = nothing
vector_of_doubles::Union{Vector{Float64}, Nothing} = nothing
testarrayofstring2::Vector{String} = []
testarrayofsortedstruct::Vector{Ability} = []
flex::Vector{UInt8} = []
test5::Vector{Test} = []
vector_of_longs::Vector{Int64} = []
vector_of_doubles::Vector{Float64} = []
parent_namespace_test::Union{InParentNamespace, Nothing} = nothing
vector_of_referrables::Union{Vector{Referrable}, Nothing} = nothing
vector_of_referrables::Vector{Referrable} = []
single_weak_reference::UInt64 = 0
vector_of_weak_references::Union{Vector{UInt64}, Nothing} = nothing
vector_of_strong_referrables::Union{Vector{Referrable}, Nothing} = nothing
vector_of_weak_references::Vector{UInt64} = []
vector_of_strong_referrables::Vector{Referrable} = []
co_owning_reference::UInt64 = 0
vector_of_co_owning_references::Union{Vector{UInt64}, Nothing} = nothing
vector_of_co_owning_references::Vector{UInt64} = []
non_owning_reference::UInt64 = 0
vector_of_non_owning_references::Union{Vector{UInt64}, Nothing} = nothing
# any_unique_type::UInt8 = 0
# any_unique::AnyUniqueAliases = nothing
# any_ambiguous_type::UInt8 = 0
# any_ambiguous::AnyAmbiguousAliases = nothing
vector_of_non_owning_references::Vector{UInt64} = []
#= any_unique_type::UInt8 = 0 =#
#= any_unique::AnyUniqueAliases = nothing =#
#= any_ambiguous_type::UInt8 = 0 =#
#= any_ambiguous::AnyAmbiguousAliases = nothing =#
vector_of_enums::Vector{Color} = []
end
FlatBuffers.@ALIGN(Monster, 1)
FlatBuffers.slot_offsets(::Type{T}) where {T<:Monster} = [
Expand All @@ -73,7 +74,7 @@ FlatBuffers.slot_offsets(::Type{T}) where {T<:Monster} = [
0x00000046, 0x00000048, 0x0000004A, 0x0000004C,
0x0000004E, 0x00000050, 0x00000052, 0x00000054,
0x00000056, 0x00000058, 0x0000005A, 0x0000005C,
0x0000005E, 0x00000060
0x0000005E, 0x00000060, 0x00000062
]
FlatBuffers.root_type(::Type{T}) where {T<:Monster} = true
FlatBuffers.file_identifier(::Type{T}) where {T<:Monster} = "MONS"
Expand Down
2 changes: 1 addition & 1 deletion test/MyGame/Example/Stat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import FlatBuffers

FlatBuffers.@with_kw mutable struct Stat
id::Union{String, Nothing} = nothing
id::String = ""
val::Int64 = 0
count::UInt16 = 0
end
Expand Down
4 changes: 2 additions & 2 deletions test/MyGame/Example/TypeAliases.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ FlatBuffers.@with_kw mutable struct TypeAliases
u64::UInt64 = 0
f32::Float32 = 0.0
f64::Float64 = 0.0
v8::Union{Vector{Int8}, Nothing} = nothing
vf64::Union{Vector{Float64}, Nothing} = nothing
v8::Vector{Int8} = []
vf64::Vector{Float64} = []
end
FlatBuffers.@ALIGN(TypeAliases, 1)
FlatBuffers.slot_offsets(::Type{T}) where {T<:TypeAliases} = [
Expand Down
2 changes: 1 addition & 1 deletion test/flatc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function checkmonster(monster)
@test sum([test0.a, test0.b, test1.a, test1.b]) == 100

@test monster.testarrayofstring == ["test1", "test2"]
@test monster.testarrayoftables == nothing
@test monster.testarrayoftables == []
@test monster.testf == 3.14159f0
end

Expand Down

0 comments on commit e5d3b55

Please sign in to comment.