[ANN] Halfway-usable Lua-ML

@perry I should have given more information in the announce indeed.

Yes, you can expose any OCaml values as Lua userdata and any functions as fallbacks. Here is my quick test of exposing lambdasoup to Lua:

utop # let st = I.mk () ;;
val st : I.state =
  {I.Value.globals = <abstr>; fallbacks = <abstr>; callstack = [];
   currentloc = None; startup = <abstr>}

utop # I.register_globals ["soup", lua_of_soup (Html.SoupNode (Soup.parse "<p>foo</p> <p>bar</p>"))] st;;
- : unit = ()

utop # I.dostring st "x = HTML.select(\"p\", soup); k, v = next(x); while k do print(v); k, v = next(x, k) end";;
<p>foo</p>
<p>bar</p>
2
- : I.value list = [I.Value.LuaValueBase.String "executed without errors"]

The module for that took quite a bit of yak shaving to get right, and there may be a better way around the phantom types than that artificial sum type, but here it is: https://gitlab.com/snippets/1883747

1 Like