| Author |
Message |
< Yaws mailing list ~ Invoking fun() callback from within a yaws module |
| Guest |
Posted: Wed Apr 18, 2007 8:59 pm |
|
|
|
Guest
|
Hi all,
This is a newbie question but I'm trying to invoke a fun() from within
a yaws module (see simplified example below).
When executing line 8, I get the following error:
yaws code at ./foo.yaws:1 crashed or ret bad val:#Fun
Req: {http_request,'GET',{abs_path,"/foo.yaws"},{1,1}}
I've had a look at the generated erl file and was able to simulate the
callback function by compiling the module and just invoking out/1 in a
shell.
At first I thought it was because of the visibility of bar/0, so I
explicitly exported that, so now bar/0 is in the foo module namespace,
but this doesn't seem to help the execution.
Is there something basic that I'm missing here?
Thanks for any help,
Ben
-------------------------------
1<erl module=foo>
2
3 -export([bar/0]).
4
5 out(A) ->
6 io:format("Executing foo module ~n"),
7 foo:bar(),
8 Cback = cb(foo,bar),
9 Cback().
10
11 bar() ->
12 io:format("Executed bar~n",[]).
13
14 cb(M,F) ->
15 fun() -> M:F() end.
16
17
18 </erl>
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Erlyaws-list mailing list
Erlyaws-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/erlyaws-list
Post recived from mailinglist |
|
|
| Back to top |
|
| tobbe |
Posted: Wed Apr 18, 2007 9:29 pm |
|
|
|
User
Joined: 19 Jan 2005
Posts: 274
Location: Stockholm, Sweden
|
Ben Hood skrev:
> Hi all,
>
> This is a newbie question but I'm trying to invoke a fun() from within
> a yaws module (see simplified example below).
>
> When executing line 8, I get the following error:
>
> yaws code at ./foo.yaws:1 crashed or ret bad val:#Fun
> Req: {http_request,'GET',{abs_path,"/foo.yaws"},{1,1}}
Isn't the problem that io:format72 returns ok, while Yaws
expects something else?
What about replacing line 9 with: {html, io_lib:format("~p", [catch Cback()])}.
Cheers, Tobbe
>
> I've had a look at the generated erl file and was able to simulate the
> callback function by compiling the module and just invoking out/1 in a
> shell.
>
> At first I thought it was because of the visibility of bar/0, so I
> explicitly exported that, so now bar/0 is in the foo module namespace,
> but this doesn't seem to help the execution.
>
> Is there something basic that I'm missing here?
>
> Thanks for any help,
>
> Ben
>
> -------------------------------
>
> 1<erl module=foo>
> 2
> 3 -export([bar/0]).
> 4
> 5 out(A) ->
> 6 io:format("Executing foo module ~n"),
> 7 foo:bar(),
> 8 Cback = cb(foo,bar),
> 9 Cback().
> 10
> 11 bar() ->
> 12 io:format("Executed bar~n",[]).
> 13
> 14 cb(M,F) ->
> 15 fun() -> M:F() end.
> 16
> 17
> 18 </erl>
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by DB2 Express
> Download DB2 Express C - the FREE version of DB2 express and take
> control of your XML. No limits. Just data. Click to get it now.
> http://sourceforge.net/powerbar/db2/
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Erlyaws-list mailing list
Erlyaws-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/erlyaws-list
Post recived from mailinglist |
|
|
| Back to top |
|
| anders_n |
Posted: Wed Apr 18, 2007 10:57 pm |
|
|
|
User
Joined: 28 Feb 2005
Posts: 155
Location: Saltillo, Mexico
|
On 4/18/07, Torbjorn Tornkvist <tobbe@tornkvist.org> wrote:
> Ben Hood skrev:
> > Hi all,
> >
> > This is a newbie question but I'm trying to invoke a fun() from within
> > a yaws module (see simplified example below).
> >
> > When executing line 8, I get the following error:
> >
> > yaws code at ./foo.yaws:1 crashed or ret bad val:#Fun
> > Req: {http_request,'GET',{abs_path,"/foo.yaws"},{1,1}}
>
> Isn't the problem that io:format72 returns ok, while Yaws
> expects something else?
>
> What about replacing line 9 with: {html, io_lib:format("~p", [catch Cback()])}.
>
I only sent my first reply to Ben, but to recap, I first thought that it was
something like that as well, but when I tried his code on yaws 1.68 on
openSuSE 10.2 it worked, that is, I did not get the error Ben mentioned
in his first email. But it just gave an empty page, but no errors.
/Anders
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Erlyaws-list mailing list
Erlyaws-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/erlyaws-list
Post recived from mailinglist |
|
|
| Back to top |
|
| Guest |
Posted: Mon Apr 23, 2007 8:25 am |
|
|
|
Guest
|
Anders Nygren wrote:
>
> I only sent my first reply to Ben, but to recap, I first thought that it was
> something like that as well, but when I tried his code on yaws 1.68 on
> openSuSE 10.2 it worked, that is, I did not get the error Ben mentioned
> in his first email. But it just gave an empty page, but no errors.
>
The man page yaws_api(3) thoroughly lists all return values from
out/1.
io:format/2 returns ok. The ret val 'ok' from out/1 means "Do nothing"
/klacke
--
Claes Wikstrom -- Caps lock is nowhere and
http://www.tail-f.com -- everything is under control
cellphone: +46 70 2097763
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Erlyaws-list mailing list
Erlyaws-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/erlyaws-list
Post recived from mailinglist |
|
|
| Back to top |
|
|
|
All times are GMT
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You can attach files in this forum You can download files in this forum
|
|
|