Skip to content

Commit

Permalink
Merge pull request #5 from berke/master
Browse files Browse the repository at this point in the history
Example doesn't compile
  • Loading branch information
johnelse committed Apr 21, 2014
2 parents 1591886 + 418e734 commit e0b4626
Show file tree
Hide file tree
Showing 7 changed files with 139 additions and 17 deletions.
31 changes: 21 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,24 @@ messages in that channel to stdout:
open Irc_client_lwt.Io
module C = Irc_client_lwt.Client
let host = "localhost"
let port = 6667
let realname = "Demo IRC bot"
let nick = "demoirc"
let username = nick
let channel = "#demo_irc"
let message = "Hello, world! This is a test from ocaml-irc-client"
let string_opt_to_string = function
| None -> "None"
| Some s -> Printf.sprintf "Some %s" s
let string_list_to_string string_list =
Printf.sprintf "[%s]" (String.concat "; " string_list)
let callback input =
let callback ~connection ~result =
let open Irc_message in
match input with
match result with
| Message {prefix=prefix; command=command; params=params; trail=trail} ->
Lwt_io.printf "Got message: prefix=%s; command=%s; params=%s; trail=%s\n"
(string_opt_to_string prefix)
Expand All @@ -41,14 +49,14 @@ let callback input =
Lwt_io.printf "Failed to parse \"%s\" because: %s" raw error
let lwt_main =
C.connect ~server:"1.2.3.4" ~port:6667 ~username:"demo_irc_bot"
~mode:0 ~realname:"Demo IRC bot" ~nick:"demo_irc_bot" ~password:"foo"
>>= (fun connection ->
Lwt_io.printl "Connected"
>>= (fun () -> C.send_join ~connection ~channel:"#mychannel")
>>= (fun () -> C.send_privmsg ~connection ~target:"#mychannel" ~message:"hi")
>>= (fun () -> C.listen ~connection ~callback)
>>= (fun () -> C.send_quit ~connection))
Lwt_unix.gethostbyname host
>>= fun he -> C.connect ~addr:(he.Lwt_unix.h_addr_list.(0))
~port ~username ~mode:0 ~realname ~nick ()
>>= fun connection -> Lwt_io.printl "Connected"
>>= fun () -> C.send_join ~connection ~channel
>>= fun () -> C.send_privmsg ~connection ~target:channel ~message
>>= fun () -> C.listen ~connection ~callback
>>= fun () -> C.send_quit ~connection
let _ = Lwt_main.run lwt_main
```
Expand All @@ -58,3 +66,6 @@ Compile the above with:
```
ocamlfind ocamlopt -package irc-client.lwt -linkpkg code.ml
```

Alternatively, you can find it under the examples/ directory as exampel1.ml;
enable its compilation during config time with --enable-examples.
11 changes: 11 additions & 0 deletions _oasis
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ Flag unix
Description: build the Unix library
Default: false

Flag examples
Description: build examples
Default: false

Library irc_client
Path: lib
Findlibname: irc-client
Expand All @@ -42,6 +46,13 @@ Library irc_client_unix
ByteOpt: -bin-annot
NativeOpt: -bin-annot
Modules: Irc_client_unix

Executable example1
Build$: flag(examples)
Path: examples
MainIs: example1.ml
Install: false
BuildDepends: irc-client.lwt

Executable test_parser
Build$: flag(tests)
Expand Down
13 changes: 12 additions & 1 deletion _tags
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# OASIS_START
# DO NOT EDIT (digest: dddbc701e59d2a5067e6fe796dfb4c25)
# DO NOT EDIT (digest: 2c63affb981f14009fa216c9363913b0)
# Ignore VCS directories, you can use the same kind of rule outside
# OASIS_START/STOP if you want to exclude directories that contains
# useless stuff for the build process
Expand Down Expand Up @@ -36,6 +36,17 @@
<unix/irc_client_unix.{cma,cmxa}>: oasis_library_irc_client_unix_native
<unix/*.ml{,i}>: oasis_library_irc_client_unix_native
<unix/*.ml{,i}>: use_irc_client
# Executable example1
"examples/example1.byte": use_irc_client_lwt
"examples/example1.byte": use_irc_client
"examples/example1.byte": pkg_lwt
"examples/example1.byte": pkg_lwt.syntax
"examples/example1.byte": pkg_lwt.unix
<examples/*.ml{,i}>: use_irc_client_lwt
<examples/*.ml{,i}>: use_irc_client
<examples/*.ml{,i}>: pkg_lwt
<examples/*.ml{,i}>: pkg_lwt.syntax
<examples/*.ml{,i}>: pkg_lwt.unix
# Executable test_parser
"test/test_parser.byte": use_irc_client
"test/test_parser.byte": pkg_oUnit
Expand Down
43 changes: 43 additions & 0 deletions examples/example1.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
open Irc_client_lwt.Io
module C = Irc_client_lwt.Client

let host = "totoritoto.gogol.zoooooopt.blah"
let port = 16667
let realname = "Demo IRC bot"
let nick = "demoirc"
let username = nick
let channel = "#demo_irc"
let message = "Hello, world! This is a test from ocaml-irc-client"

let string_opt_to_string = function
| None -> "None"
| Some s -> Printf.sprintf "Some %s" s

let string_list_to_string string_list =
Printf.sprintf "[%s]" (String.concat "; " string_list)

let callback ~connection ~result =
let open Irc_message in
match result with
| Message {prefix=prefix; command=command; params=params; trail=trail} ->
Lwt_io.printf "Got message: prefix=%s; command=%s; params=%s; trail=%s\n"
(string_opt_to_string prefix)
command
(string_list_to_string params)
(string_opt_to_string trail)
| Parse_error (raw, error) ->
Lwt_io.printf "Failed to parse \"%s\" because: %s" raw error

let lwt_main =
Lwt_unix.gethostbyname host
>>= fun he -> C.connect ~addr:(he.Lwt_unix.h_addr_list.(0))
~port ~username ~mode:0 ~realname ~nick ()
>>= fun connection -> Lwt_io.printl "Connected"
>>= fun () -> C.send_join ~connection ~channel
>>= fun () -> C.send_privmsg ~connection ~target:channel ~message
>>= fun () -> C.listen ~connection ~callback
>>= fun () -> C.send_quit ~connection

let _ = Lwt_main.run lwt_main

(* ocamlfind ocamlopt -package irc-client.lwt -linkpkg code.ml *)
2 changes: 2 additions & 0 deletions lwt/irc_client_lwt.mli
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module Io : Irc_transport.IO with type 'a t = 'a Lwt.t

module Client : sig
type connection_t

Expand Down
12 changes: 9 additions & 3 deletions myocamlbuild.ml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(* OASIS_START *)
(* DO NOT EDIT (digest: 10c6e705428ed417ee23076695e9c827) *)
(* DO NOT EDIT (digest: 6a2b4d6aec635df1d40fc1fbfd8327af) *)
module OASISGettext = struct
(* # 21 "src/oasis/OASISGettext.ml" *)

Expand Down Expand Up @@ -545,12 +545,18 @@ let package_default =
],
[(OASISExpr.EBool true, S [A "-bin-annot"])])
];
includes = [("unix", ["lib"]); ("test", ["lib"]); ("lwt", ["lib"])]
includes =
[
("unix", ["lib"]);
("test", ["lib"]);
("lwt", ["lib"]);
("examples", ["lwt"])
]
}
;;

let dispatch_default = MyOCamlbuildBase.dispatch_default package_default;;

# 555 "myocamlbuild.ml"
# 561 "myocamlbuild.ml"
(* OASIS_STOP *)
Ocamlbuild_plugin.dispatch dispatch_default;;
44 changes: 41 additions & 3 deletions setup.ml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(* setup.ml generated for the first time by OASIS v0.3.0 *)

(* OASIS_START *)
(* DO NOT EDIT (digest: 6f7863c4200f8fc7d5e50d2b48b2e2b9) *)
(* DO NOT EDIT (digest: df476ea97960939999849d7010bab404) *)
(*
Regenerated by OASIS v0.3.0
Visit http://oasis.forge.ocamlcore.org for more information and
Expand Down Expand Up @@ -5817,6 +5817,16 @@ let setup_t =
flag_description = Some "build the Unix library";
flag_default = [(OASISExpr.EBool true, false)]
});
Flag
({
cs_name = "examples";
cs_data = PropList.Data.create ();
cs_plugin_data = []
},
{
flag_description = Some "build examples";
flag_default = [(OASISExpr.EBool true, false)]
});
Library
({
cs_name = "irc_client";
Expand Down Expand Up @@ -5927,6 +5937,33 @@ let setup_t =
lib_findlib_name = Some "unix";
lib_findlib_containers = []
});
Executable
({
cs_name = "example1";
cs_data = PropList.Data.create ();
cs_plugin_data = []
},
{
bs_build =
[
(OASISExpr.EBool true, false);
(OASISExpr.EFlag "examples", true)
];
bs_install = [(OASISExpr.EBool true, false)];
bs_path = "examples";
bs_compiled_object = Byte;
bs_build_depends = [InternalLibrary "irc_client_lwt"];
bs_build_tools = [ExternalTool "ocamlbuild"];
bs_c_sources = [];
bs_data_files = [];
bs_ccopt = [(OASISExpr.EBool true, [])];
bs_cclib = [(OASISExpr.EBool true, [])];
bs_dlllib = [(OASISExpr.EBool true, [])];
bs_dllpath = [(OASISExpr.EBool true, [])];
bs_byteopt = [(OASISExpr.EBool true, [])];
bs_nativeopt = [(OASISExpr.EBool true, [])]
},
{exec_custom = false; exec_main_is = "example1.ml"});
Executable
({
cs_name = "test_parser";
Expand Down Expand Up @@ -6016,14 +6053,15 @@ let setup_t =
};
oasis_fn = Some "_oasis";
oasis_version = "0.3.0";
oasis_digest = Some " \185\165c\018`\003)\203\186\238\019z\031\241\181";
oasis_digest =
Some "\249\151\186\000\161#\023\0173\168\148\247\243\187\209&";
oasis_exec = None;
oasis_setup_args = [];
setup_update = false
};;

let setup () = BaseSetup.setup setup_t;;

# 6028 "setup.ml"
# 6066 "setup.ml"
(* OASIS_STOP *)
let () = setup ();;

0 comments on commit e0b4626

Please sign in to comment.