Skip to content

haskell-github-trust/quickjs-hs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

aa516ed · May 19, 2023

History

49 Commits
May 19, 2023
May 19, 2023
May 19, 2023
May 19, 2023
Aug 26, 2020
Oct 1, 2020
Jan 6, 2021
Aug 23, 2020
Aug 28, 2020
Aug 23, 2020
May 19, 2023

Repository files navigation

quickjs-hs

Tests Cabal

This package provides a Haskell wrapper for the QuickJS Javascript Engine. It has been inspired by the quickjs-rs and ocaml-quickjs libraries.

Features

The functionality is quite basic and is currently limited to:

  • evaluating JS code
  • calling a JS function in the global scope
  • marshalling Aeson Values to and from JSValues.

Examples

Evaluate an expression:

import Quickjs

one_plus_two = quickjs $ do
  res <- eval "1+2"
  liftIO $ print res

Declare a function and call it on an argument:

call_f = quickjs $ do
  _ <- eval_ "f = (x) => x+1"
  res <- eval "f(2)"
  liftIO $ print res

Pass a Haskell value (which has a ToJSON instance) to the JS runtime:

aeson_marshall = quickjs $ do
  _ <- eval_ "f = (x) => x+1"
  res <- withJSValue (3::Int) $ \x -> call "f" [x]
  liftIO $ print res

Contributing

Please feel free to report bugs/submit feature requests via the github issue tracker and submit any pull requests to the git repository