|
NAMElfe_gen - Lisp Flavoured Erlang (LFE) dynamic code generatorSYNOPSISThis module provides an experimental interface for dynamically generating modules.DATA TYPESsexpr()An LFE s-expression, a list structure. EXPORTSnew_module(Name) -> ModDef.add_exports([[Name,Arity]], ModDef) -> ModDef. add_imports([from,Module|Functions], ModDef) -> ModDef. add_imports([rename,Module|Renames], ModDef) -> ModDef. add_attribute(Attribute, ModDef) -> ModDef. add_form(Form, ModDef) -> ModDef. build_mod(ModDef) -> Forms. compile_mod(Mod) -> CompRet where
These functions are used to incrementally create a module which can at the end be compiled by compile_mod/1. The various components have the same formats as they do when defining a module in a file. A simple module which defines one function a/0 could be defined with:
EXAMPLEIn this example we build a module of parameters where each parameter has a number of features which each have a value. We will create one function for each parameter and the feature is the functions argument. The value for each feature is returned.We are creating code equivalent to:
but generating it and compiling it directly in memory without generating a text file. We assume that we have collected the data and have it in the form:
The equivalent LFE code which we will be generating is:
The following code builds and compiles a module from the parameter data:
This module could be generated and then be loaded into the system by doing:
The second argument to code:load_binary/3, here "nofile", is irrelevant in this case. ERROR INFORMATIONThe ErrorInfo mentioned above is the standard ErrorInfo structure which is returned from all IO modules. It has the following format:{ErrorLine,Module,ErrorDescriptor} A string describing the error is obtained with the following call:
SEE ALSOlfe_comp(3), lfe_macro(3)AUTHORSRobert Virding.
Visit the GSP FreeBSD Man Page Interface. |