å¯ãæ¥ææ¥ã®æãããã°ã©ãã¯äœãããŸããïŒ å¯ãæ¥ææ¥ã®æãããã°ã©ããŒã¯ç±ããè¶ã飲ãã§ã³ãŒããæžããŸãã 圌ã¯æãå¯ãã®ã§ãè¶ã飲ã¿ãŸããããŸã ç®ãèŠããŠããŸããããæãã§ããã®ã§ã³ãŒããæžããŸãã ããã°ã©ããŒã¯åžžã«ã³ãŒããæžããããšæã£ãŠããŸããããéã®ããã«ã³ãŒããæžãã®ã¯å¹³æ¥ã ãã§ãããã«éåžžã«ç²ããŠãããé±æ«ã¯èªåã§äŒã¿ãŸãã
ä»æã¯ãOcsigenã®æåã®ã¢ããªã±ãŒã·ã§ã³ãäœæããŸãã å ¬åŒã®ããã¥ã¢ã«ãæåã«ç¥ããããã°ããã®ã§ãããããã¥ã¢ã«ã¯äžå®å šã§ãã??????ãã®ãããªå°æããè¡ã§ãã£ã±ããªã®ã§ãããŸãæåŸ ããªãã§ãã ããã ãã©ã³ã¹èªã®ååã ãããã£ãŠãç§ãã¡ã€ã³ã®ããã¥ã¢ã«ã«ãªããŸãã
èŠããŠãããããããŸããããç§ãã¡ã¯ãã€ãŠãšãèªã®éèš³ãæžããŸãã ã ãã以æ¥ãã€ã³ã¿ããªã¿ã¯ãããã«æ¹åãããå¥ã®ã¯ã©ã¹ã«å²ãåœãŠãããå ¥åã«è¡ãåãå§ããåºåã«è¡ãäžãå§ããŸããïŒã³ã³ãœãŒã«ã§äœæ¥ãã代ããã«ïŒã ããã§ã®ã¿ã¹ã¯ã¯ãYoba
æåã«ãocsigenãµãŒããŒãã€ã³ã¹ããŒã«ããå¿ èŠããããŸãã ãã£ã¹ããªãã¥ãŒã·ã§ã³çšã«2.0ãã³ã³ãã€ã«ããããšãã§ããŠããªãããã ãã®æ瀺ã«åŸã£ãŠãã³ãã«ãµãŒããŒãããŒã ãã£ã¬ã¯ããªã«ã€ã³ã¹ããŒã«ããŸãã ãã³ãã«ãæ£ãããããããã®ã«ããã«ã¯ãmakeãå®è¡ããåã«Makefile.configãç·šéããŠããã«æžã蟌ã¿ãŸãã
LOCAL := ${HOME}/bin/ocsigen
DEV := YES
OCAMLDUCE := YES
OCLOSURE := YES
OTHERS := YES
OcamlãšFindlibã¯åéãããããã§ã«ãªããžããªã«ãããŸãã ä»åã¯O'Closureã¯å¿ èŠãããŸãããã念ã®ããåéããŸããããã«ãããåŸã§é žçŽ ãåæ§ç¯ããå¿ èŠããªããªããŸããããªãèªèº«ãèå³ãæã£ãŠããããç§ããã®èšäºãå¿ èŠãªå Žåã
次ã®é ç®ã¯ãã¡ã€ã«$ {HOME} /bin/ocsigen/etc/ocsigenserver/ocsigenserver.confãããã«ç·šéããŸãïŒé©åãªããŒããããã«æžãããŠããããšãšãéå§ââãããŠãŒã¶ãŒã®ååãšã°ã«ãŒãã確èªããŸãã 次ã¯ãå°æ¥ã®ãµã€ãã®æ§æãæºåããŸãã $ {HOME} /bin/ocsigen/etc/ocsigenserver/conf.d/yoba.confãäœæããå 容ãå ¥åããŸãã
<ocsigen> <server> <charset>utf-8</charset> <extension findlib-package="ocsigenserver.ext.staticmod"/> <extension findlib-package="ocsigenserver.ext.ocsipersist-sqlite"> <database file="ocsidb"/> </extension> <extension findlib-package="ocsigenserver.ext.deflatemod" /> <extension findlib-package="eliom.server"/> <host charset="utf-8" hostfilter="*"> <site path="" charset="utf-8"> <static dir="/home/username/yoba" /> <eliom module="/home/username/yoba/_build/server/yoba.cmo"> <cache-size>10000</cache-size> </eliom> </site> <deflate compress="only"> <type>application/x-javascript</type> </deflate> </host> </server> </ocsigen>
ã³ã³ãã³ãã«ã€ããŠç°¡åã«ïŒ
- staticmodã䜿çšãããšããµãŒããŒã¯éçããŒã¿ãè¿ãããšãã§ããŸãïŒãã®å Žåãããã¯ã³ã³ãã€ã«ããã.jsãã¡ã€ã«ã«ãªããŸã
- ocsipersist-sqlite-æ°žç¶ããŒã¿ãæäœã§ããããã«ããŸãããããå¿ èŠãªçç±ãããããŸãã
- deflatemodã¯ãäºæ³ã©ãããéä¿¡æã«ããŒã¿ãæŒããŸãã 以äžã§ã¯ããµã€ãèšå®ã®deflateã»ã¯ã·ã§ã³ãèŠãããšãã§ããŸããããã¯jsã®ã¿ãæŒãããšã瀺ããŠããŸãã 泚ïŒå§çž®æ¹åŒïŒgzipãŸãã¯deflateïŒãéžæããããšã¯ã§ããŸãããã¯ã©ã€ã¢ã³ãã®æåŸ ã«åºã¥ããŠèªåçã«éžæãããŸãã
- eliom.serverã¯ããã¬ãŒã ã¯ãŒã¯ã®ãµãŒããŒéšåå šäœãæäŸããŸã
- ãã¹ãã®hostfilterãã©ã¡ãŒã¿ãŒã§ããã¹ãŠã®ãã¡ã€ã³ã«å¿çãããšèšããŸã
- ãããŠããµã€ãã®ç©ºã®ãã¹ã瀺ããŠããµã€ãããã¡ã€ã³ã®ã«ãŒãã«ãããšèšããŸãã 空ã®è¡ããyobaããªã©ã«çœ®ãæãããšããã¹ãŠã®éçã³ã³ãã³ããšå ±ã«ã¢ãã¬ã¹hostname / yobaã«ãµã€ãã匷å¶ãããŸã-æ確ãªå©çãåããã¡ã€ã³ã«è€æ°ã®ãµã€ããä¿æãã奜ããªããã«ã·ã£ããã«ã§ããŸã
- / home / username / yobaã¯ãã³ãŒãïŒããã³ã³ã³ãã€ã«æžã¿ã®yoba.jsãã¡ã€ã«ïŒãæ ŒçŽããããã£ã¬ã¯ããªã«ãªãã_build / serverã«ã¯ãã³ã³ãã€ã«æžã¿ã®ãµãŒããŒã¢ãžã¥ãŒã«ã«ãªããŸãã ãã¡ãããçæ³çã«ã¯ãã³ã³ãã€ã«ããŠããã³ãŒããå¥ã®ãã©ã«ããŒã«è»¢éããå¿ èŠããããŸãããã³ã³ãã€ã«ãããã¢ãžã¥ãŒã«ãšåããã©ã«ããŒã«éçã³ã³ãã³ããä¿åããªãã§ãã ããã
ãã£ãïŒ ã³ãŒããæžãããšã«ããŸãã
æªåé«ããã©ã«ããŒ/ home /ãŠãŒã¶ãŒå/ yoba /ãäœæãã ã¢ãŒã«ã€ããYobaèšèªã§ããŠã³ããŒãããŸã -èšèªèªäœã¯æ¢ã«äœæããŸããããå°ããã¡ã€ã«ããŠã¯ã©ã¹ã«å€æããã®ã¯é¢çœããªãã®ã§ãããã«ãããåããŸãã åããã©ã«ããŒã«è§£åããæšæºã®Makefile.configãšMakefile.rulesãåãå Žæã«ããŠã³ããŒãããŸãããããžã§ã¯ãã®æ§ç¯ã¯ç°¡åã§ã¯ãªããfigãã¡ã€ã«ãæåããäœæã§ããŸãã
äœããä¿®æ£ããããã«æåã®æ§æã®é©æ°ã«ã€ããŠåŠã³ãŸããEliomã§ã¯ãã³ãŒããã»ã¯ã·ã§ã³ã«é 眮ã§ããŸãã {server {...}}ã»ã¯ã·ã§ã³ïŒã»ã¯ã·ã§ã³ã®ãªãã³ãŒããšåãïŒã¯ãµãŒããŒã§ã³ã³ãã€ã«ããã³å®è¡ããã {client {...}}ã»ã¯ã·ã§ã³ã¯ã¯ã©ã€ã¢ã³ãã§ã³ã³ãã€ã«ããã {shared {...}}ã¯ãã¡ãã¡ããã¢ã¯ã»ã¹ã§ããŸãã
ã€ã³ã¿ãŒããªã¿ãŒãã¯ã©ã€ã¢ã³ãã§åäœãããããyobaLang.mlãã¡ã€ã«ã®ååãyobaLang.eliomã«å€æŽããŠéããæåã«ã{client {ãè¡ãè¿œå ããæåŸã«ã;;ãã眮ãæããŸãã ïŒ2ã€ã®ã»ãã³ãã³-ããã¯ã³ãŒãã®æäžäœã§ã®ã¿åœä»€ã®çµããã§ãããã»ã¯ã·ã§ã³å ã§ã¯äœ¿çšã§ããªããªããŸãïŒããã}}ããžã çæãããocamllexããã³ocamlyaccã³ãŒãã¯ãmakefileãäœæãããšãã«åæ§ã«ç·šéãããŸãã
ãããŸã§ã®éããã¹ãŠãå®è¡ãããã¡ã€ã«ãäœæããŸãããã ããšãã°ãhome.eliomãšåŒã³ãŸãã
ãã¡ã€ã«ã®å é ã§ãå°æ¥ã®ããã«ã¢ãžã¥ãŒã«ãéããããã«èšªåè ã«æäŸããããµã³ãã«ã³ãŒããå«ãè¡ãäœæããŸãã
{shared{ open Eliom_pervasives open Lwt open HTML5.M open Eliom_parameters open Eliom_request_info open Eliom_output.Html5 open Ocsigen_extensions let code_example = ref " 1 2 1 50 " }}
次ã«ãã¢ããªã±ãŒã·ã§ã³ã®ã¢ãžã¥ãŒã«ãäœæããŸããã¯ã©ã€ã¢ã³ããšãµãŒããŒã®çžäºäœçšãæ£ããæ©èœããããã«ããã¹ãŠã®ãµãŒãã¹ãã¢ããªã±ãŒã·ã§ã³ã«ä»£ãã£ãŠç»é²ãããŸãã 幞ããªããšã«ãããã¯ç°¡åã§ãã
module My_appl = Eliom_output.Eliom_appl ( struct let application_name = "yoba" end)
Yobeã§ã³ãŒããå®è¡ããçµæãè¿ãé¢æ°ãè¿œå ããŸããé¢æ°ã¯çŽç²ã«ã¯ã©ã€ã¢ã³ãã«ãªãããµãŒããŒã¯ããã«ã€ããŠãç¥ããŸããã
{client{ let yoba_execute str = ( let yparser = new YobaLang.yoba_interpretator () in yparser#parse str; yparser#get_output) }}
ãŠãŒã¶ãŒèŠæ±ãåŠçãããµãŒãã¹ãäœæããŸãã ocsigenã§ã®ãµãŒãã¹ã®äœæã¯éåžžã«ç°¡åã§äŸ¿å©ã§ããåãµãŒãã¹ã¯ãæ¹æ³ãšåŒ·ãåä»ããããïŒïŒïŒGET / POSTãã©ã¡ãŒã¿ãŒã®ã»ããã«ãã£ãŠç¹åŸŽä»ããããŸãã ãããã£ãŠããµãŒããŒã¯ããªã¯ãšã¹ãã«åºã¥ããŠã©ã®ãµãŒãã¹ããªã¯ãšã¹ããåŠçãããã決å®ããŸãã ãã©ã¡ãŒã¿ãŒãªãã§èŠæ±ãåŠçããããã©ã«ãã®ãµãŒãã¹ã1ã€ã®GETãã©ã¡ãŒã¿ãŒã§èŠæ±ãåŠçããåãã¢ãã¬ã¹ã®2çªç®ã®ãµãŒãã¹ã1ã€ã®POSTãã©ã¡ãŒã¿ãŒã§3çªç®ã®ãµãŒãã¹ãäœæã§ããŸãã ãããŠã圌ãã¯æ··ä¹±ããªãã§ãããã ãã ããçŸæç¹ã§ã¯ãå¿ èŠãªãµãŒãã¹ã¯1ã€ã ãã§ãã
let empty_service = Eliom_services.service ~path:[""] ~get_params:(Eliom_parameters.unit) ();;
ãã¹ã¯ããµãŒãã¹ããµã€ãã®ããã©ã«ããã¹ã«æ²¿ã£ãŠïŒApacheã®ã€ã³ããã¯ã¹ããŒãžãšããŠïŒæäŸãããããšã象城ãããget_paramsã§ããµãŒãã¹ããã©ã¡ãŒã¿ãŒãåãå ¥ããªãããšã瀺ããŸããã
ããŒãžãã³ãã¬ãŒããäœæããŸãã
let page_template code_input counter_value = html (head (title (pcdata "Yoba interpreter")) [] ) (body [ h1 [pcdata "Yoba! For human beings"]; p [pcdata " ! â !"]; div [ raw_textarea ~a:[a_id "clientcode"] ~name:"clientcode" ~rows:25 ~cols:60 ~value:code_input (); raw_button ~button_type:`Button ~name:"clientbutton" ~a:[a_id "clientbutton"] ~value:"!" [pcdata "!"]; ]; pre ~a:[a_id "clientoutput"] []; hr (); p [pcdata "- : "; b [pcdata (string_of_int counter_value)]] ]);;
ã芧ã®ãšããããã¹ãŠã®ããŒãžèŠçŽ ã¯ãå³å¯ã«å®çŸ©ããããã©ã¡ãŒã¿ãŒãå ¥åãšããŠåãåãé¢æ°ã§ãããã®ãããäœæãããHTMLããŒãžã®éçãªé¡ååãå®è¡ãããŸãã ãã®ãããhtmlé¢æ°ã¯2ã€ã®ãã©ã¡ãŒã¿ãŒãå ¥åãšããŠåãå ¥ããŸã-1ã€ã¯ãHeadãã¿ã€ãã§ããã1ã€ã¯ãBodyãã¿ã€ãã§ãã ãããŠdiv-divå ã«ããããšãèš±å¯ãããŠããèŠçŽ ã®ãªã¹ããå ¥åãšããŠåãåããŸãã
ããããç§ãã¡ã¯ããå°ã詳ãã説æããŸãã ãŸããpage_templateé¢æ°ã¯ãã³ãŒããšèšªåè ã«ãŠã³ã¿ãŒãšãã2ã€ã®ãã©ã¡ãŒã¿ãŒãå ¥åãšããŠåãå ¥ããŸãã 1ã€ç®ã¯textareaã«é 眮ããã2ã€ç®ã¯äžçªäžã®<p>ã¿ã°ã®å åŽã«ãããŸãã 第äºã«ãraw_textareaããã³raw_buttoné¢æ°ã®ååã¯ãšãŠãçã§ã-æ£åœãªçç±ã§ãã åæ§ã®åçŽãªéãraw_ãé¢æ°ããããŸããããããã¯ãäœããã®ãµãŒãã¹ãåžžã«åç §ããçŽ æŽãããã匷ãåä»ãããããã©ãŒã å ã«èŠçŽ ãäœæããããã«èšèšãããŠããŸããã©ã¡ãŒã¿ïŒã ããããããã¹ããšãªã¢ãšãã¿ã³ïŒããã¯<input>ã¿ã°ã§ã¯ãªããHTML5ã®æãèªç¶ãª<button>ã¿ã°ïŒã¯äœãéä¿¡ããŸããããããŒãžå ã§æ¯ããã®ã§ããã©ãŒã ã¯ãããŸããã 第äžã«ãã€ã³ã¿ãŒããªã¿ãŒã®çµæãä¿åããç¹å¥ãª<pre>ãäœæããŸããã
ãšããã§ãç§ã¯èšªåè ã®ã«ãŠã³ã¿ãŒã«èšåããŸãããïŒ ç§ã¯å®å šã«å¿ããŸãããæžããŸãããã ãããè¡ãã«ã¯ãLwtãšOcsipersistã®2ã€ã®æ°ããã¢ãžã¥ãŒã«ãããã«ç解ããŸãã 1ã€ç®ã¯å調ã¹ã¬ããã®æäœãæ åœãã2ã€ç®ã¯æ°žç¶çãªã¹ãã¬ãŒãžãæ åœããŸãã
é žçŽ ãããŒã·ã¹ãã ã¯å調çã§ãã ããã¯ãæ°ããããã»ã¹ãåŒã³åºãã¹ã¿ãã¯ããã®ä»ã®ããããã®äœæãå¿ èŠãšããåŸæ¥ã®ã¹ã¬ããã®ä»£ããã«ãéåžžã«è»œéãªã¹ã¬ããïŒã»ãšãã©ãã¹ãŠã®åŒã³åºãã«äœ¿çšãããã»ã©è»œãïŒãåŸãããããšãæå³ããŸãã ããããçš®é¡ã®ãã³ã»ã³ã¹ãäœæãã代ããã«ãã¹ã¬ããã«ç®ãåããŠãã³ãŒãã«ãããã ã³ã³ãã€ã©èªäœãå¿ èŠãªãã¹ãŠãå®è¡ãããããããã¯ã®å¯èœæ§ãæå°éã«æããååãã€ã³ãã
let get_count = let counter_store = Ocsipersist.open_store "counter_store" in let cthr = Ocsipersist.make_persistent counter_store "countpage" 0 in let mutex = Lwt_mutex.create () in (fun () -> cthr >>= (fun c -> Lwt_mutex.lock mutex >>= (fun () -> Ocsipersist.get c >>= (fun oldc -> let newc = oldc + 1 in Ocsipersist.set c newc >>= (fun () -> Lwt_mutex.unlock mutex; return newc) ) ) ) ) ;;
OCamlã«æ £ããŠããªãå ŽåïŒæåã«ãã£ãããã«ïŒãç§ãã¡ã®æ©èœãããªãããŒã§ããããšã«æ°ä»ãã§ãããã Get_countèªäœã¯ããã¥ãŒããã¯ã¹ãšã¹ãã¬ãŒãžãªããžã§ã¯ããæ ŒçŽããããªããžã§ã¯ããã§ãã ã³ãŒãã«ãget_countããèšè¿°ãããšãinputïŒïŒãåãåãããã¹ãŠã®äœæ¥ãå®è¡ããé¢æ°ãè¿ãããŸãã 次ã«ãé¢æ°ã«å ¥ããŸãã ããã«ããªãããŒãªæŒç®å ">> ="ã衚瀺ãããŸããããã¯ãæåã®åŒæ°ïŒã¹ã¬ããïŒã®çµæã2çªç®ã®åŒæ°ïŒæ°ããã¹ã¬ãããäœæããé¢æ°ïŒã®å ¥åã«æž¡ãç¹å¥ãªæŒç®åã§ãã æ£åŒã«ã¯ããªãã¬ãŒã¿ãŒã®çœ²åã¯æ¬¡ã®ãšããã§ãã
val (>>=) : 'at -> ('a -> 'bt) -> 'bt
ãããŠãæåŸã®returné¢æ°ã¯ã¹ã¬ããã®çµæãè¿ããŸãã
Ocsipersistã䜿çšãããšãäœãããããªããŠããã¹ãŠãæ確ã«ãªããŸãã
ã©ãã§get_countãåŒã³åºããŠããŒãžãã³ãã¬ãŒããçæããŸããïŒ ãããŠãããã«åœŒå¥³ã¯ã解éé¢æ°ã§ãïŒ
let interpret code = let req = Eliom_request_info.get_ri () in let ref = match Lazy.force_val req.ri_referer with | None -> "" | Some x -> x in Ocsigen_messages.accesslog ("Referer: " ^ ref); get_count() >|= (page_template code);;
ãã®æ©èœã¯ãããã€ãã®èå³æ·±ãæ©èœã玹ä»ããŸãã æ®å¿µãªãããOksigenã¯ããªã¯ãšã¹ãã«é¢ããç°¡åãªæ å ±ã®ã¿ããã°ã«æžã蟌ã¿ãŸã-誰ãã©ã®ãŠãŒã¶ãŒãšãŒãžã§ã³ããã©ã®ãã¹ããã©ã®ããŒãžããã€ã ãŸãããªãã¡ã©ãŒãååŸãããã£ãã ããŠããªã¯ãšã¹ãã«é¢ããæ å ±ãååŸãããªãã¡ã©ãŒãåŒãåºããŸãã åã³å·§åŠã«äœæãããŠããŸã-ååšããªãå¯èœæ§ã®ããå€ïŒä»ã®èšèªã®Nullãªã©ïŒã§ãããã¬ã€ãžãŒã³ã³ãã¥ãŒãã£ã³ã°ã«ãã©ãããããŠããŸããã€ãŸããèŠæ±ãããŸã§ãã©ãã«ãæ ŒçŽãããŠããŸããã
å¥ã®æ°ããæŒç®å "> | ="㯠">> ="ã«äŒŒãŠããŸã-å¯äžã®éãã¯ãã¹ã¬ããã®äœæ¥ã®çµæããæ°ããã¹ã¬ããããŸã£ããè¿ããªãäºå®ã®é¢æ°ã®å ¥åã«æž¡ãããããšã§ãã
ããã§çµããã§ãã ãµãŒãã¹ãç»é²ããã³ãŒãã®è§£éæ¹æ³ãåŠç¿ããŸãã
My_appl.register empty_service (fun () () -> Eliom_services.onload {{ Js.Opt.iter (Dom_html.document##getElementById (Js.string "clientbutton")) ( fun clntbutton -> clntbutton##onclick <- Dom_html.handler (fun _ -> Js.Opt.iter (Dom_html.document##getElementById (Js.string "clientcode")) ( fun cdinput -> Js.Opt.iter (Dom_html.document##getElementById (Js.string "clientoutput")) ( fun cdoutput -> let cdinputarea = Dom_html.CoerceTo.textarea cdinput in Js.Opt.iter cdinputarea (fun x -> let i = Js.to_string x##value in cdoutput##innerHTML <- Js.string (yoba_execute i) ) ) ); Js._true ) ) }}; interpret !code_example);;
{{...}}ãããã¯ã¯ã¯ã©ã€ã¢ã³ãé¢æ°ã®ãããªãã®ã§ã-ããŒãžã®onloadãã³ãã©ãŒã«ç»é²ããŸãã
ã¯ã©ã€ã¢ã³ãã³ãŒãã§ã¯ãæ§æãè¥å¹²ç°ãªããŸãã Jsãªããžã§ã¯ãã®ã¡ãœããã«ã¢ã¯ã»ã¹ããã«ã¯ãåäžã®ã·ã£ãŒãã§ã¯ãªããããã«ã䜿çšããããããDom_html.document ## getElementByIdã¯åçŽãªãdocument.getElementByIdãã«å¯Ÿå¿ããŸãã
ããã§ç¢ºèªã§ããå€æ°ã®Js.Opt.iterã¯ãgetElementByIdé¢æ°ãå¿ ãããäœãè¿ããªããšããäºå®ã«ãããã®ã§ãã ãããã£ãŠãJs.Opt.iterã¯ãçµæãæ¬åœã«ããã§ããå Žåã«ã®ã¿ãçµæã«å¯ŸããŠã¢ã¯ã·ã§ã³ãå®è¡ããŸãã ãããã£ãŠãæ¢ããŠããããŒãžäžã®3ã€ã®ãªããžã§ã¯ãã«ã¯ã4ã€ã®Js.Opt.iterãå¿ èŠã§ããã 4-ããã©ã«ãã§ã¯ãgetElementByIdé¢æ°ã¯æãäžè¬çãªããããã£ã®ã¿ãæã€èŠçŽ åã®ãªããžã§ã¯ããè¿ãããã ãããŠãtextareaã®valueããããã£ã«å°éããããã«ããªããžã§ã¯ããtextareaåã«ãã£ã¹ãïŒDom_html.CoerceToïŒããããšããŠããŸãããããã¯äžè¬çãªå Žåã®çµæãä¿èšŒããŸããã
ãããã£ãŠãç»é²ããããµãŒãã¹ãã³ãã©ãŒã¯2ã€ã®ããšã ããè¡ããŸããããŒãžã®å é ã§Jsã³ãŒããåŒã³åºããäžèšã®ãã³ãã¬ãŒããè¿ããŸãã
æ°é ãã®ããèªè ã¯ããªãæåã«code_exampleãæååïŒrefïŒãžã®ãªã³ã¯ãšããŠå®£èšãããããã©ãã§ãåç §è§£é€ããã®ãããã§ã«æ°ä»ããŠçåã«æããããããŸããã ãããŠäºã¯ãããæç¹ã§ãç§ãã¡ã®ãšãŒãã¯çã«éå£ã§ããã¹ãã ãšããããšã§ããã ãŠãŒã¶ãŒã解éããŠä»ã®äººã«èŠããããšããããšãä¿åããŸãããã
ãããè¡ãã«ã¯ãæåã®ãµãŒãã¹ã®é£ã«ãç¹å¥ã«èšç·Žããã2çªç®ã®ãµãŒãã¹ãäœæããŸããããã¯ãã³ãŒããå«ãè¡ãååŸããŠcode_exampleã«é 眮ããŸãã JavaScriptãããµãŒãã¹ãåŒã³åºãã«ã¯ãEliom_output.Camlã«ä»£ãã£ãŠãµãŒãã¹ãäœæããŸãã
let update_code_service = Eliom_output.Caml.register_service ~path:["update code"] ~get_params:(string "f") (fun f () -> code_example := f; return ());;
次ã«ãã¯ã©ã€ã¢ã³ãé¢æ°ïŒæãå éšçãªãã®ïŒãå€æŽããŠã1è¡ã ãè¿œå ããŸãã
let i = Js.to_string x##value in ignore(Eliom_client.call_caml_service ~service:%update_code_service i ()); cdoutput##innerHTML <- Js.string (yoba_execute i)
åºæ¥äžããïŒ ããã§ãããŒãžã«ã¢ã¯ã»ã¹ãããã¹ãŠã®äººã«ãæåŸã«å®è¡ãããã³ãŒãã衚瀺ãããŸãã 確ãã«ããµãŒããŒãåèµ·åããŠãããã®äŸã¯å ã®å Žæã«æ»ããŸãã
æåŸã«ãMakefileãäœæããŸãã
MODULE = yoba APP = yoba include Makefile.config SERVERFILES := home.eliom CLIENTFILES := yobaType.ml yobaLexer.eliom yobaParser.eliom yobaLang.eliom home.eliom SERVERLIB := -package eliom.server,ocsigenserver,lwt CLIENTLIB := -package js_of_ocaml INCLUDES = EXTRADIRS = include Makefile.rules yobaParser.eliom: ocamlyacc yobaParser.mly echo '{client{' >yobaParser.eliom cat yobaParser.ml >>yobaParser.eliom echo '}}' >>yobaParser.eliom sed -i 's/;;//' yobaParser.eliom rm yobaParser.ml yobaParser.mli yobaLexer.eliom: yobaParser.eliom ocamllex yobaLexer.mll echo '{client{' >yobaLexer.eliom cat yobaLexer.ml >>yobaLexer.eliom echo '}}' >>yobaLexer.eliom sed -i 's/;;//' yobaLexer.eliom rm yobaLexer.ml _build/client/yobaLexer.cmo: _build/client/yobaParser.cmo _build/client/yobaLang.cmo: _build/client/yobaLexer.cmo _build/client/yobaParser.cmo $(STATICDIR)/$(APP).js: _build/client/${MODULE}.cmo ${JS_OF_ELIOM} -jsopt -pretty -verbose ${CLIENTLIB} -o $@ $^ #yui-compressor --charset utf-8 $@ > $@_min #mv $@_min $@ pack: $(STATICDIR)/$(APP).js
yobaLexer.eliomãšyobaParser.eliomãçæããå¿ èŠãããããããã®ããã®é©åãªã«ãŒã«ãäœæããŸããã åæ§ã«ãããã©ã«ãã®äŸåé¢ä¿ãžã§ãã¬ãŒã¿ãŒã¯ãã¬ã¯ãµãŒãšããŒãµãŒãã³ã³ãã€ã«ããé åºã®æ±ºå®ã«å¯Ÿå¿ããŠããªããããããã€ãã®ã«ãŒã«ã§åœŒãæ¯æŽããŸããã
ããã§å®è¡ã§ããŸãïŒ
make depend
make
make pack
æåã®åŒã³åºãã¯ã³ã³ãã€ã«é åºãçæãã2çªç®ã¯ãµãŒããŒã³ãŒããã³ã³ãã€ã«ãã3çªç®ã¯ãµãŒããŒããŒãã«ãã£ãŠèªåçã«åŒã³åºãããjavascriptãã¡ã€ã«ãçæããŸããããã®åŒã³åºãã¯ããŒãžãã³ãã¬ãŒãã«ç»é²ããŸããã§ããã yui-compressorãžã®åŒã³åºããšåŸç¶ã®mvã®ã³ã¡ã³ããå€ããšãjsã³ãŒããå°ãå§çž®ã§ããŸãïŒç§ã®å Žåã400kbãã209kbãŸã§ïŒã
æåŸã«ocsigenserverã¢ã»ã³ããªããéç¥ããããšã¯ã¹ããŒãPATHãèšè¿°ããŠããã¹ãŠã®æ瀺ãå®äºããå¿ èŠããããŸãã
ãã®åŸã$ HOME / bin / ocsigen / binã«ç§»åããŠãã/ ocsigenserverãšèšããŸãã
ãã©ãŠã¶ãéããŠã解éãè©Šã¿ãŠãã ããã ãããŠãããªããæ tooããããªããããªãã¯ç§ãšæ¯ããããšãã§ããŸãïŒ sorokdva.net