package ezlua
All checked builds passInstall
dune-project
Dependency
Authors
Maintainers
Sources
sha256=068f8c0b85e191a3ee4dc7542107b12469a4f28b059df2998a6ec433da8417cc
sha512=3415748b360863c48519ded9506b6d58e70cc84936b33964bb33e336588b30fb0e1899f2f0789d142c3bbc153b834005af1c42dc6d59c03b3e1efd91427b7aa5
Description
Added to opam-repository:
README
ezlua 
Trying to make it easier to use Lua from OCaml.
ppx
ppx_ezlua provides two features: automatic encoder/decoder derivation for custom types, and a let%lua syntax for wrapping OCaml functions as Lua callbacks.
[@@deriving ezlua]
Annotate a type declaration to generate <name>_to_lua and <name>_of_lua functions automatically.
Records become Lua tables keyed by field name. Variants become tables with a "tag" field (and an optional "value" or "values" field for payloads).
type point = {
x: float;
y: float;
}
[@@deriving ezlua]
(* generates:
val point_to_lua : point Ezlua.to_lua
val point_of_lua : point Ezlua.of_lua *)
let () =
let state = Ezlua.create () in
let p = { x = 1.0; y = 2.5 } in
Ezlua.set_global state "p" point_to_lua p;
ignore (Ezlua.run state "assert(p.x == 1.0 and p.y == 2.5)")let%lua
Define an OCaml function and get a matching <name>_lua callback suitable for Ezlua.add_function. All parameters and the return type must be annotated.
let%lua add (x : int) (y : int) : int = x + y
(* generates:
val add : int -> int -> int
val add_lua : Lua_api_lib.oCamlFunction *)
let () =
let state = Ezlua.create () in
Ezlua.add_function state "add" add_lua;
ignore (Ezlua.run state "assert(add(1, 2) == 3)")Argument decoding errors are reported back to Lua via LuaL.error with a message that includes the argument position and name.
Encoding conventions
This table describes how OCaml values map to Lua values.
OCaml type | Lua representation |
|---|---|
| number (integer) |
| number |
| string |
| boolean |
|
|
| table |
|
|
| table |
N-tuple ( | table |
record | table keyed by field name, e.g. |
variant (no payload) |
|
variant (single payload) |
|
variant (tuple payload) |
|
Pairs use the Encode.pair/Decode.pair library functions. Larger tuples generate inline table code directly.
Optional Dependencies
None
Used by (1)
Conflicts
None
Build status
Results of building ezlua with each compiler on check.ci.ocaml.org, run of against opam-repository 8a77e58. All results for this package.
Each result links to its build log. To keep crawlers from overloading the site, build logs require a GitHub sign-in (see ocurrent/opam-health-check). On your first log, GitHub asks you to “Authorize opam-health-check”, the OCurrent app that runs these checks; it sees only your public profile, not your repositories. The sign-in lasts 30 days.
| Version | OCaml 4.11 | OCaml 4.14 | OCaml 5.2 | OCaml 5.4 | OCaml 5.5 |
|---|---|---|---|---|---|
| 0.1 (this version) | n/a | good | good | good | good |
- good Package successfully built
- partial One of the dependencies failed to build
- bad Package failed to build
- n/a Package is not available in this environment
- internal Internal failure