Skip to content

Instantly share code, notes, and snippets.

@lpgauth
Created March 24, 2014 17:59
Show Gist options
  • Save lpgauth/9745585 to your computer and use it in GitHub Desktop.
Save lpgauth/9745585 to your computer and use it in GitHub Desktop.
-module(swirl_flow_generate).
-export([
compile_and_load/1,
test/0
]).
compile_and_load(Strings) ->
Forms = [begin
{ok, S, _} = erl_scan:string(String),
{ok, Form} = erl_parse:parse_form(S),
Form
end || String <- Strings],
{ok, ModuleName, Binary} = compile:forms(Forms),
{module, ModuleName} = code:load_binary(ModuleName, "nofile", Binary).
test() ->
ModuleName = swirl_flow_example,
Module =
[["-module(", atom_to_list(ModuleName), ")."],
["-behavior(swirl_flow)."],
["-export([map/4, reduce/4])."],
["map(FlowId, StreamName, Event, MapperOpts) -> ignore."],
["reduce(FlowId, Period, Aggregates, ReducerOpts) -> ok."]],
Strings = [binary_to_list(iolist_to_binary(Line)) || Line <- Module],
compile_and_load(Strings).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment