模块中不存在Erlang函数?
在lager.elr(的主模块)中没有名为“debug”的函数,但我有一个从lager模块调用debug函数的应用程序,如: lager:debug(Str,Args)模块中不存在Erlang函数?,erlang,Erlang,在lager.elr(的主模块)中没有名为“debug”的函数,但我有一个从lager模块调用debug函数的应用程序,如: lager:debug(Str,Args) 我是Erlang的初学者,但我知道当我们从模块lile“mymodule:myfunction”调用函数时,文件mymodule.erl中应该有一个名为“myfunction”的函数,但在这种情况下,当我在lager.erl中搜索函数“debug”时我找不到它。您在lager.erl文件中看不到它,因为它位于lager.erl顶
我是Erlang的初学者,但我知道当我们从模块lile“mymodule:myfunction”调用函数时,文件mymodule.erl中应该有一个名为“myfunction”的函数,但在这种情况下,当我在lager.erl中搜索函数“debug”时我找不到它。您在lager.erl文件中看不到它,因为它位于lager.erl顶部的lager.hrl文件中。Erlang允许您使用-include(“filename.hrl”)指令包含文件。按照惯例,include文件以hrl扩展名结尾,但它实际上可以是任何东西
之所以没有提到
lager:debug/2
,是因为lager使用解析转换。因此,在编译代码时,它通过lagers parse transform传递,对lager:debug/2
的调用被另一个模块函数的调用所替代
如果您使用正确的lager解析转换选项编译代码,那么代码就可以工作。我给出了垃圾答案”很好地解释了这种奇怪的行为。我在这里发布了一个代码,它应该向您展示在beam文件中生成的代码:
在外壳中:
实用程序:反编译([yourfile.beam])
%%作者:PCHAPIER
%%创建日期:2010年5月25日
-模块(实用程序)。
%%
%%包括文件
%%
%%
%%导出函数
%%
-导出([decompile/1,decompdir/1])。
-导出([shuffle/1])。
%%
%%API函数
%%
反编译目录(目录)->
Cmd=“cd”++Dir,
操作系统:cmd(cmd),
L=os:cmd(“dir/B*.beam”),
L1=re:split(L,[\t\r\n+],[{return,list}]),
io:格式(“decompdir:~p~n,[L1]),
反编译(L1)。
反编译(Beam=[H |))时为_整数(H)->
io:格式(“反编译:~p~n,[Beam]),
{ok,{{uu,[{abstract\u code,{uu,AC}]}}=beam\u lib:chunks(beam++“.beam”,[abstract\u code]),
{ok,File}=File:open(Beam++“.erl”,[write]),
io:fwrite(文件,“~s~n”,[erl_prettypr:format(erl_语法:form_list(AC))],
文件:关闭(文件);
反编译([H|T])->
io:格式(“反编译:~p~n,[[H | T]]),
反编译(removebeam(H)),
反编译(T);
反编译([])->
好啊
洗牌(P)->
最大值=长度(P)*10000,
{{uu,R}=lists:unzip(lists:keysort(1,[{random:uniform(Max),X}|X
removebeam1(列表:反向(L))。
移除波束1([$m,$a,$e,$b,$.| T])->
列表:反向(T);
移除波束1(L)->
列表:反向(L)。
但在头文件中没有名为“debug”的函数。在该头文件中有:-define(级别,[debug,info,notice,warning,error,critical,alert,emergency,none])。我找不到名为“debug”的函数。因为在另一个应用程序中它调用“debug”,如:lager:debug(参数1,参数2)。
%% Author: PCHAPIER
%% Created: 25 mai 2010
-module(utility).
%%
%% Include files
%%
%%
%% Exported Functions
%%
-export([decompile/1, decompdir/1]).
-export([shuffle/1]).
%%
%% API Functions
%%
decompdir(Dir) ->
Cmd = "cd " ++ Dir,
os:cmd(Cmd),
L = os:cmd("dir /B *.beam"),
L1 = re:split(L,"[\t\r\n+]",[{return,list}]),
io:format("decompdir: ~p~n",[L1]),
decompile(L1).
decompile(Beam = [H|_]) when is_integer(H) ->
io:format("decompile: ~p~n",[Beam]),
{ok,{_,[{abstract_code,{_,AC}}]}} = beam_lib:chunks(Beam ++ ".beam",[abstract_code]),
{ok,File} = file:open(Beam ++ ".erl",[write]),
io:fwrite(File,"~s~n", [erl_prettypr:format(erl_syntax:form_list(AC))]),
file:close(File);
decompile([H|T]) ->
io:format("decompile: ~p~n",[[H|T]]),
decompile(removebeam(H)),
decompile(T);
decompile([]) ->
ok.
shuffle(P) ->
Max = length(P)*10000,
{_,R}= lists:unzip(lists:keysort(1,[{random:uniform(Max),X} || X <- P])),
R.
%%
%% Local Functions
%%
removebeam(L) ->
removebeam1(lists:reverse(L)).
removebeam1([$m,$a,$e,$b,$.|T]) ->
lists:reverse(T);
removebeam1(L) ->
lists:reverse(L).