Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/haskell-github-trust/quickjs-hs
Haskell bindings for the QuickJS library
https://github.com/haskell-github-trust/quickjs-hs
haskell quickjs
Last synced: about 2 months ago
JSON representation
Haskell bindings for the QuickJS library
- Host: GitHub
- URL: https://github.com/haskell-github-trust/quickjs-hs
- Owner: haskell-github-trust
- License: mit
- Created: 2020-08-23T17:08:50.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-05-19T10:42:30.000Z (over 1 year ago)
- Last Synced: 2024-04-24T14:58:44.682Z (10 months ago)
- Topics: haskell, quickjs
- Language: Haskell
- Homepage: https://hackage.haskell.org/package/quickjs-hs
- Size: 967 KB
- Stars: 5
- Watchers: 1
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: ChangeLog.md
- License: LICENSE
Awesome Lists containing this project
README
# quickjs-hs
![Tests Cabal](https://github.com/goodlyrottenapple/quickjs-hs/workflows/Tests%20Cabal/badge.svg)
This package provides a Haskell wrapper for the [QuickJS](https://bellard.org/quickjs/) Javascript Engine. It has been inspired by the [quickjs-rs](https://github.com/theduke/quickjs-rs) and [ocaml-quickjs](https://github.com/dhcmrlchtdj/ocaml-quickjs) libraries.
## FeaturesThe functionality is quite basic and is currently limited to:
- evaluating JS code
- calling a JS function in the global scope
- marshalling [Aeson Values](https://hackage.haskell.org/package/aeson-1.5.3.0/docs/Data-Aeson.html#t:Value) to and from JSValues.## Examples
Evaluate an expression:```haskell
import Quickjsone_plus_two = quickjs $ do
res <- eval "1+2"
liftIO $ print res
```Declare a function and call it on an argument:
```haskell
call_f = quickjs $ do
_ <- eval_ "f = (x) => x+1"
res <- eval "f(2)"
liftIO $ print res
```Pass a Haskell value (which has a [ToJSON](https://hackage.haskell.org/package/aeson-1.5.3.0/docs/Data-Aeson.html#t:ToJSON) instance) to the JS runtime:
```haskell
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](https://github.com/goodlyrottenapple/quickjs-hs/issues) and submit any pull requests to the [git repository](https://github.com/goodlyrottenapple/quickjs-hs/)