【发布时间】:2021-07-05 02:14:41
【问题描述】:
有没有一种方法可以找到使用我创建的特定宏列出的所有函数?我在想可以使用:application.get_key 函数找到它们。
类似的东西
defmodule DefFooModule do
defmacro deffoo(head, body) do
quote do
def unquote(head) do
unquote(body[:do])
end
end
end
def find_all_foos do
{:ok, modules} = :application.get_key(:app, :modules)
## something here???
## output [
## AnotherModule.do_something/0,
## AnotherModule.do_something_else/0,
## AnotherModule2.do_something_2/0
## ]
end
end
defmodule AnotherModule do
deffoo do_something do
## function goes in here
end
deffoo do_something_else do
## function goes in here
end
end
defmodule AnotherModule2 do
deffoo do_something_2 do
## function goes in here
end
end
谢谢
【问题讨论】:
标签: module macros attributes elixir metaprogramming