Skip to content

Commit

Permalink
Simplfy require code, fix __dirname and __filename
Browse files Browse the repository at this point in the history
  • Loading branch information
fxfactorial committed Oct 19, 2015
1 parent 6662f25 commit 4e80a2f
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 19 deletions.
10 changes: 6 additions & 4 deletions _oasis
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
OASISFormat: 0.4
Name: nodejs
Version: 0.0.1
Version: 0.1
Synopsis: OCaml bindings for nodejs
Authors: Edgar Aroutiounian <edgar.factorial@gmail.com>
Maintainers: Edgar Aroutiounian <edgar.factorial@gmail.com>
Expand All @@ -10,16 +10,18 @@ Plugins: META (0.4), DevFiles (0.4)
BuildTools: ocamlbuild

Description:
These are OCaml bindings to Nodejs
Write OCaml, run on node

Get all the power of the Nodejs ecosystem with the type safety of OCaml
These are js_of_ocaml bindings to the node JavaScript API.
Get all the power of the node ecosystem with the type safety
of OCaml.

Library nodejs
Path: src
Modules: Nodejs, Nodejs_globals
# Every time you add a new module be sure to add it here to
# InternalModules field
InternalModules:
Http, Url, Nodejs_globals, Net, Events, Fs, Process
Http, Url, Net, Events, Fs, Process
CompiledObject: byte
BuildDepends: js_of_ocaml, js_of_ocaml.ppx
5 changes: 3 additions & 2 deletions examples/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ define colorecho
endef

run:all clean
# @npm install socket.io express
@npm install socket.io express
node chat_server.js

all:
Expand All @@ -18,8 +18,9 @@ all:
# clean:
# @rm -f chat_server2.cmi chat_server2.cmo \
# chat_server2.cmt a.out

clean:
@rm -f chat_server.cmi chat_server.cmo \
# chat_server.cmt a.out
chat_server.cmt a.out

.PHONY:clean
7 changes: 4 additions & 3 deletions opam/descr
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
OCaml bindings for nodejs
Write OCaml, run on node

These are OCaml bindings to Nodejs Get all the power of the Nodejs
ecosystem with the type safety of OCaml.
These are js_of_ocaml bindings to the node JavaScript API.
Get all the power of the node ecosystem with the type safety
of OCaml.
3 changes: 2 additions & 1 deletion opam/opam
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
opam-version: "1.2"
name: "nodejs"
version: "0.0.1"
version: "0.1"
maintainer: "Edgar Aroutiounian <edgar.factorial@gmail.com>"
authors: [ "Edgar Aroutiounian <edgar.factorial@gmail.com>" ]
license: "BSD-3-clause"
homepage: "https://github.com/fxfactorial/ocaml-nodejs"
bug-reports: "https://github.com/fxfactorial/ocaml-nodejs/issues"
dev-repo: "https://github.com/fxfactorial/ocaml-nodejs.git"
build: [
["oasis" "setup"]
["ocaml" "setup.ml" "-configure" "--prefix" prefix]
Expand Down
2 changes: 1 addition & 1 deletion src/events.ml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ class type events = object
end

let require () : events Js.t =
Nodejs_globals.require (Js.string "events")
Nodejs_globals.require "events"
2 changes: 1 addition & 1 deletion src/fs.ml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ class type fs = object
end

let require () : fs Js.t =
Nodejs_globals.require (Js.string "fs")
Nodejs_globals.require "fs"
2 changes: 1 addition & 1 deletion src/http.ml
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,4 @@ class type http = object
end

let require () : http Js.t =
Nodejs_globals.require (Js.string "http")
Nodejs_globals.require "http"
2 changes: 1 addition & 1 deletion src/net.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ class type net = object
end

let require () : net Js.t =
Nodejs_globals.require (Js.string "net")
Nodejs_globals.require "net"
14 changes: 10 additions & 4 deletions src/nodejs_globals.ml
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
let require (s : Js.js_string Js.t) =
Js.Unsafe.fun_call (Js.Unsafe.js_expr "require") [|Js.Unsafe.inject s|]
let require s =
Js.Unsafe.fun_call
(Js.Unsafe.js_expr "require")
[|Js.Unsafe.inject (Js.string s)|]

let console : Js.Unsafe.any Js.t = Js.Unsafe.global##.console

let __filename () : Js.js_string Js.t = Js.Unsafe.global##.__filename
let __filename () =
(Js.Unsafe.eval_string "__filename" : Js.js_string Js.t)
|> Js.to_string

let __dirname () : Js.js_string Js.t = Js.Unsafe.global##.__dirname
let __dirname () =
(Js.Unsafe.eval_string "__dirname" : Js.js_string Js.t)
|> Js.to_string
4 changes: 4 additions & 0 deletions src/process.ml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
class type process = object

method version : Js.js_string Js.t Js.readonly_prop

method platform : Js.js_string Js.t Js.readonly_prop

end

let process : process Js.t = Js.Unsafe.global##.process
2 changes: 1 addition & 1 deletion src/url.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ class type url = object
end

let require () : url Js.t =
Nodejs_globals.require (Js.string "url")
Nodejs_globals.require "url"

0 comments on commit 4e80a2f

Please sign in to comment.