Skip to content

Commit

Permalink
Proof of concept
Browse files Browse the repository at this point in the history
  • Loading branch information
christiangnrd committed Dec 28, 2024
1 parent 16c257e commit 71f95af
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
19 changes: 19 additions & 0 deletions src/ObjectiveC.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,25 @@ function enable_tracing(enabled::Bool)
end
const tracing = @load_preference("tracing", false)::Bool

@static if Sys.isapple()
function macos_version()
size = Ref{Csize_t}()
err = @ccall sysctlbyname("kern.osproductversion"::Cstring, C_NULL::Ptr{Cvoid}, size::Ptr{Csize_t},
C_NULL::Ptr{Cvoid}, 0::Csize_t)::Cint
Base.systemerror("sysctlbyname", err != 0)

osrelease = Vector{UInt8}(undef, size[])
err = @ccall sysctlbyname("kern.osproductversion"::Cstring, osrelease::Ptr{Cvoid}, size::Ptr{Csize_t},
C_NULL::Ptr{Cvoid}, 0::Csize_t)::Cint
Base.systemerror("sysctlbyname", err != 0)

verstr = view(String(osrelease), 1:size[]-1)
parse(VersionNumber, verstr)
end
else
macos_version() = v"0"
end

# Types & Reflection
include("primitives.jl")
include("methods.jl")
Expand Down
18 changes: 17 additions & 1 deletion src/syntax.jl
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,8 @@ contains a series of property declarations:
check, returning `nothing` if the check fails).
- `setter`: specifies the name of the Objective-C setter method. Without this, no
`setproperty!` definition will be generated.
- `minver`: specifies the minimum macOS version supported by the property. Will only define
the property if the compatibility is met.
- `@getproperty myProperty function(obj) ... end`: define a custom getter for the property.
The function should take a single argument `obj`, which is the object that the property is
being accessed on. The function should return the property value.
Expand All @@ -427,6 +429,7 @@ macro objcproperties(typ, ex)
isa(typ, Symbol) || propertyerror("expected a type name")
Meta.isexpr(ex, :block) || propertyerror("expected a block of property declarations")

unsupportednames = Set{Symbol}()
propertynames = Set{Symbol}()
read_properties = Dict{Symbol,Expr}()
write_properties = Dict{Symbol,Expr}()
Expand Down Expand Up @@ -461,7 +464,20 @@ macro objcproperties(typ, ex)
else
propertyerror("invalid property specification $(property_arg)")
end
push!(propertynames, property)

# This complexity
supported = if haskey(kwargs, :minver)
(VersionNumber(get(kwargs, :minver, "0")) < macos_version()) && property unsupportednames
else
true
end
if supported
push!(propertynames, property)
else
push!(unsupportednames, property)
delete!(propertynames, property)
continue
end

# handle the various property declarations. this assumes :object and :value symbol
# names for the arguments to `getproperty` and `setproperty!`, as generated below.
Expand Down

0 comments on commit 71f95af

Please sign in to comment.