hslua-packaging: Utilities to build Lua modules.

[ foreign, library, mit ] [ Propose Tags ] [ Report a vulnerability ]

Utilities to package up Haskell functions and values into a Lua module.

This package is part of HsLua, a Haskell framework built around the embeddable scripting language Lua.


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 2.0.0, 2.1.0, 2.2.0, 2.2.0.1, 2.2.1, 2.3.0, 2.3.1
Change log CHANGELOG.md
Dependencies base (>=4.11 && <5), containers (>=0.5.9 && <0.8), hslua-core (>=2.2.1 && <2.4), hslua-marshalling (>=2.2.1 && <2.4), hslua-objectorientation (>=2.3 && <2.4), hslua-typing (>=0.1 && <0.2), mtl (>=2.2 && <2.4), text (>=1.2 && <2.2) [details]
Tested with ghc ==8.4.4, ghc ==8.6.5, ghc ==8.8.4, ghc ==8.10.3, ghc ==9.0.2, ghc ==9.2.8, ghc ==9.4.8, ghc ==9.6.3, ghc ==9.8.1
License MIT
Copyright © 2019-2024 Albert Krewinkel
Author Albert Krewinkel
Maintainer tarleb@hslua.org
Category Foreign
Home page https://hslua.org/
Bug tracker https://github.com/hslua/hslua/issues
Source repo head: git clone https://github.com/hslua/hslua.git(hslua-packaging)
Uploaded by tarleb at 2024-01-18T16:49:46Z
Distributions Arch:2.3.1, Fedora:2.3.0, LTSHaskell:2.3.1, NixOS:2.3.1, Stackage:2.3.1, openSUSE:2.3.1
Reverse Dependencies 6 direct, 182 indirect [details]
Downloads 10296 total (228 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2024-01-18 [all 1 reports]

Readme for hslua-packaging-2.3.1

[back to package description]

hslua-packaging

Build status AppVeyor Status Hackage

Utilities to package up Haskell functions and values into a Lua module.

This package is part of HsLua, a Haskell framework built around the embeddable scripting language Lua.

Functions

It is rarely enough to just expose Haskell functions to Lua, they must also be documented. This library allows to combine both into one step, as one would do in source files.

Functions can be exposed to Lua if they follow the type

a_0 -> a_1 -> ... -> a_n -> LuaE e b

where each a~i~, 0 ≤ i ≤ n can be retrieved from the Lua stack.

Let's look at an example: we want to expose the factorial function, making use of Haskell's arbitrary size integers. Below is how we would document and expose it to Lua.

-- | Calculate the factorial of a number.
factorial :: DocumentedFunction Lua.Exception
factorial = defun "factorial"
  ### liftPure (\n -> product [1..n])
  <#> n
  =#> productOfNumbers
  #? "Calculates the factorial of a positive integer."
  `since` makeVersion [1,0,0]
 where
   n :: Parameter Lua.Exception Integer
   n = parameter peekIntegral "integer"
         "n"
         "number for which the factorial is computed"

   productOfNumbers :: FunctionResults Lua.Exception Integer
   productOfNumbers =
     functionResult pushIntegral "integer"
       "produce of all numbers from 1 upto n"

This produces a value which can be pushed to Lua as a function

pushDocumentedFunction factorial
setglobal "factorial"

and can then be called from Lua

> factorial(4)
24
> factorial(23)
"25852016738884976640000"

The documentation can be rendered as Markdown with renderFunction:

factorial (n)

Calculates the factorial of a positive integer.

*Since: 1.0.0*

Parameters:

n
:   number for which the factorial is computed (integer)

Returns:

 - product of all integers from 1 upto n (integer)