-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to include const image types into image_t? #4
Comments
Hi, due to difficulties with cross linking |
Sorry, I'm not sure the best way to use |
How about something like: module image_t_constants
export PIXEL_FORMAT_UYVY, PIXEL_FORMAT_YUYV
const PIXEL_FORMAT_UYVY = Int32(1498831189)
const PIXEL_FORMAT_YUYV = Int32(1448695129)
end included in using image_t_constants
@show PIXEL_FORMAT_YUYV |
Also, if that's the right interface, it would be straightforward to create a macro to generate that module definition from something like: @define_constants(image_t_constants, begin
PIXEL_FORMAT_UYVY = Int32(1498831189)
PIXEL_FORMAT_YUYV = Int32(1448695129)
end) |
Hi @rdeits , thanks. I think that is a good way to do it -- I'd suggest we leave this issue open for a while and see if someone logs more interest? In the mean time, I'll try get to it if there are spare cycles to implement. |
Here's an example: using MacroTools
function parse_assignment(assignment::Expr)
if @capture(assignment, const x_ = y_)
return x, y
elseif @capture(assignment, x_ = y_)
return x, y
else
error("Expected an assignment of the form `x = y`")
end
end
macro define_constants(name, assignment_exprs::Expr...)
assignments = parse_assignment.(assignment_exprs)
inner_block = Expr(:block)
for (x, y) in assignments
push!(inner_block.args, :(export $(esc(x))))
push!(inner_block.args, :(const $(esc(x)) = $(esc(y))))
end
# We need to put an @eval in the generated expression
# because module definitions must happen at the top-level
# whereas a macro could potentially be invoked anywhere
:(@eval module $(esc(name))
$(inner_block)
end)
end Usage: Main> @define_constants(foo, bar=1, baz=2)
WARNING: replacing module foo
foo
Main> foo.bar
1
Main> foo.baz
2
Main> using foo
Main> bar
1
Main> baz
2 |
HI, yes - that helps thanks. I think that is the right way to do it. I'll try get to it soon. |
Hi,
There's a bit of metadata that should be in image_t.jl:
This is from Libbot. How best to include this into
src/image_t.jl
? Alternatively, we just hack in the specificInt
value without reference.cc @tkoolen , @dehann
The text was updated successfully, but these errors were encountered: