在路径中加载所有erlang模块 [英] Load all erlang modules in path

查看:276
本文介绍了在路径中加载所有erlang模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用简单的答案使用螺纹依赖关系加载项目的方法,依赖关系现在可以自动解决,但不会自动加载。

Using the answer from Easy way of loading projects with rebar dependencies, dependencies are now automatically resolved, but they are not automatically loaded.

那么,如何加载所有的模块我的ebin和/ deps / * / bin路径自动?这样他们可以使用Erlang shell选项卡完成,这大大加快了我的开发过程。

So, how can I load all the modules in my ebin and /deps/*/bin path automatically? That way they are available when using the Erlang shell tab completion, which speeds up my dev process considerably.

我的解决方案基于Adam Lindberg的伟大答案 https://gist.github.com/1131312 它只会加载项目模块

My solution based on the great answer of Adam Lindberg: https://gist.github.com/1131312 It will only load the project modules automagically, so almost no delay in erl startup.

推荐答案

这个代码段将会成为诀窍:

This snippet would do the trick:

[code:ensure_loaded(list_to_atom(filename:rootname(filename:basename(F))))
 || P <- code:get_path(), F <- filelib:wildcard(P ++ "/*.beam")].

将其放在您的〜/ .erlang 文件作为一行(包括点:),它将在启动任何 Erlang shell时执行。请警告,这是非常缓慢的!

Put it in your ~/.erlang file as one row (including the dot: .) and it will be executed upon starting any Erlang shell. Be warned though, it's hideously slow!

» time erl -noshell -s init stop
erl -noshell -s init stop  0.11s user 0.02s system 11% cpu 1.143 total # Without
» time erl -noshell -s init stop
erl -noshell -s init stop  7.31s user 1.08s system 88% cpu 9.480 total # With 

这篇关于在路径中加载所有erlang模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆