Mercurial > repos > rhope
annotate said.rhope @ 176:327bcf35e094
Add bytecode interpreter
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Wed, 08 Jun 2011 23:24:29 -0700 |
parents | f582fd6c75ee |
children |
rev | line source |
---|---|
0 | 1 /* |
2 This program implements Paul Graham's "Arc Challenge" | |
3 While I think the Arc Challenge is a little silly, it does provide a simple | |
4 example of how to use the web framework I whipped up for the Rhope blog | |
5 */ | |
6 | |
7 //The Import keyword causes another Rhope source file to be included | |
8 //Here we import the Rhope web framework | |
9 Import framework.rhope | |
10 | |
11 //Here we define an event handler that will get called when the user clicks the button | |
12 //Event handlers get passed the current page tree and an event object | |
13 Save Text[page,event:out] | |
14 { | |
15 //First we store the value from the text box in a session variable | |
16 out <- [[[page]Set["said",[[page]Get Child By Name["foo"]]Value >>] | |
17 //Then we empty the page object | |
18 ]Clear Children | |
19 //And we add a hyperlink | |
147
f3686f60985d
Sort of working port of framework. Transaction bug seems to be getting in the way. Going to work around, but want the old version in the repo so I can test later.
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
20 ]Add Child[Web Link["Click Here","/said"]] |
0 | 21 } |
22 | |
23 //This worker defines our page | |
24 Said[page,query:out] | |
25 { | |
26 //Here we try to retrieve the session variable "said" | |
27 [page]Index["said"] | |
28 { | |
29 //If it's present we display it on the page | |
30 out <- [page]Add Child[ ["You said: "]Append[~] ] | |
31 }{ | |
32 //Otherwise we provide them with a form to enter a word | |
147
f3686f60985d
Sort of working port of framework. Transaction bug seems to be getting in the way. Going to work around, but want the old version in the repo so I can test later.
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
33 out <- [[[page]Add Child[Web Field["foo","","text"]] |
0 | 34 ]Add Child[ |
147
f3686f60985d
Sort of working port of framework. Transaction bug seems to be getting in the way. Going to work around, but want the old version in the repo so I can test later.
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
35 Web Button["blah","Click!"] |
0 | 36 //The Set Handler call here attaches the worker Save Text to the click event for the page |
37 //Events propagate can propagate themselves up the page hierarchy and handled wherever appropriate | |
148
f582fd6c75ee
Fixed framework port, works for said.rhope example
Mike Pavone <pavone@retrodev.com>
parents:
147
diff
changeset
|
38 ]]Set Handler["click",Save Text[?]] |
0 | 39 } |
40 } | |
41 | |
147
f3686f60985d
Sort of working port of framework. Transaction bug seems to be getting in the way. Going to work around, but want the old version in the repo so I can test later.
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
42 Main[args] |
0 | 43 { |
147
f3686f60985d
Sort of working port of framework. Transaction bug seems to be getting in the way. Going to work around, but want the old version in the repo so I can test later.
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
44 [args]Index[1] |
f3686f60985d
Sort of working port of framework. Transaction bug seems to be getting in the way. Going to work around, but want the old version in the repo so I can test later.
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
45 { port <- Int32[~] } |
f3686f60985d
Sort of working port of framework. Transaction bug seems to be getting in the way. Going to work around, but want the old version in the repo so I can test later.
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
46 { port <- Val[80] } |
0 | 47 //Start Web starts the webserver and initializes the web framework |
48 Start Web[ | |
49 //It takes a dictionary mapping paths to Workers that define dynamic pages | |
50 //Rather than just passing the name of the Worker, we're passing a List of info | |
51 //that allows the framework to take care of some of the drudgework for us | |
52 //The first element in the list is the worker name, the second the page title | |
53 //and the third element indicates whether this page will be using session data or not | |
147
f3686f60985d
Sort of working port of framework. Transaction bug seems to be getting in the way. Going to work around, but want the old version in the repo so I can test later.
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
54 [Dictionary[]]Set["/said",[(0,"That's what she said",Yes)]Set[0,Said[?]]], port |
0 | 55 ] |
56 } |