Calling a function from an .ERL to .YAWS file
Asked Answered
E

1

6

I am very new to YAWS and ERLANG and would like to call a function from a different .erl file to the YAWS page.

i.e. I have a page called webpage.yaws and have another file called utilities.erl and would like to call a function from utilities.erl in webpage.yaws

Any ideas?

Thanks

Eyestrain answered 17/10, 2012 at 7:35 Comment(0)
S
7

It's very simple, just call the function like you would normally do in Erlang programs, i.e. Module:func_name(arguments) the only thing you need to do is make sure Yaws knows where to find the compiled BEAM file. In the Yaws configuration file add:

ebin_dir = /tmp/ebin

Compile your utilities.erl, put the BEAM file in /tmp/ebin and you can call your utility functions from the webpage.yaws file.

Full example:

website.yaws:

 <html>
  <erl>
    out(Arg) ->
       D=utilities:get_some_strings(),
       {html, ["Retrieved from utilities: ", D]}.
  </erl>    
 </html>

utilities.erl:

-module(utilities).

-export([get_some_strings/0]).

get_some_strings() ->
    "hello world!".
Spense answered 17/10, 2012 at 9:15 Comment(1)
I am also a newbie to Erlang. So I am not sure if I am interpreting something wrong or picking a fine point. I liked johlo's answer but I could only get it to load a function in a module defined in a beam file after I restarted the yaws serviceDisconnection

© 2022 - 2024 — McMap. All rights reserved.