Create application for Erlang

Source: Internet
Author: User

After we have finished writing a set of functional modules (in Erlang, in module), we always want this set of modules to be packaged into an application, as a single whole that can be started, stopped, like Mnesia. And can be referenced in other applications. How to do that. Each application is started with the Application:start series function, and Application:stop can stop an application.

An application needs an. app file to describe it, mainly describing what files, parameters, etc. it includes.



If you start an app when you start an Erlang VM, in fact, there is no way to start a custom application directly with the parameters of the VM, some parameters such as: START_SASL can launch some internal standard build-in applications, but we can give the VM an execution portal, This is like the C language or the Java language main function, when the VM starts, execute the entry point of the program, so that you can start the application in this portal operation.

This entry point is specified by the parameter-S. Let's look at an example:


1. Erl-s Erlycomet_demo
This parameter specifies that after the VM is started, the Erlycomet_demo:start () parameterless function is called

2. In the Erlycomet_demo:start () function, we write the following code:
Application:start (Erlycomet_demo).

Above this sentence, start a erlycomet_demo application, here, the VM will find in the search directory Erlycomet_demo.app this file, if not, error, if found, then follow the instructions in this file to start the Erlycomet_demo application. This section can refer to the relevant documentation, simple, in the Erlycomet_demo with a parameter {mod,{mod_name_app,[]}}
This parameter indicates that the function is called Mod_name_app:start (_type,argu). Take Erlycomet_demo as an example, this call goes into Erlycomet_demo_app:start (_type,argu),


3. In Erlycomet_demo_app start (_type,argu), start a supervisor process to start the child process. As shown below:
Erlycomet_demo_sup:start_link (Args).



Now that we've packaged the app through application, how can we share the app?? For example, how do we use the function of application 2 in application a??  The promise is: to use the application as a unit for the reference, for example: if we want to mnesia function, I will call Mnesia:start () or in the application of a application specified, to start Mnesia. In OPT, there are many applications that are independent and mutually quoted. For example: Mnesia, Crpyto,inet and so on.

Create application for Erlang

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.