最近clone了一个开源项目最新版本,代码启动的时候总是报错,超纠结,以前没这问题啊= =

查看了源码错误是在erlang:function_exported(xx, xx, 0)这个函数位置。代码的执行依赖于这个函数的返回,

API对此函数的说明是:Returns true if the module Module is loaded and contains an exported function Function/Arity; otherwise false.

但明明模块是有这个导出函数的啊,然后我在控制台再次手工调用了一次这个方法,显示结果是true。

第一次调用时返回false,第二次调用时返回true,呃,应该是code load的问题。

查看一下文档http://www.ostools.net/apidocs/apidoc?api=erlang

说的很清楚:In interactive mode, code is dynamically loaded when first referenced. When a call to a function in a module is made, and the module is not loaded, the code server searches the code path and loads the module into the system.

好吧,那我只能手工加载了,在函数调用之前,调用code:ensure_loaded对模块进行主动加载,果然没问题了。

但是,在我重新clone该项目的最新代码时发现,作者在修订版本里又主动把这句话加上了,⊙﹏⊙b汗

 

 posted on 2012-12-25 15:44  文武双全大星星  阅读(244)  评论(0编辑  收藏  举报