hslua-core: Bindings to Lua, an embeddable scripting language

[ foreign, library, mit ] [ Propose Tags ]

Wrappers and helpers to bridge Haskell and Lua.

It builds upon the lua package, which allows to bundle a Lua interpreter with a Haskell program.


[Skip to Readme]
Versions [faq] 1.0.0
Change log CHANGELOG.md
Dependencies base (>=4.8 && <5), bytestring (>=0.10.2 && <0.11), exceptions (>=0.8 && <0.11), lua (==2.0.*), mtl (==2.2.*), text (>=1.0 && <1.3) [details]
License MIT
Copyright © 2007–2012 Gracjan Polak; © 2012–2016 Ömer Sinan Ağacan; © 2017-2021 Albert Krewinkel
Author Albert Krewinkel, Gracjan Polak, Ömer Sinan Ağacan
Maintainer albert+hslua@zeitkraut.de
Category Foreign
Home page https://hslua.github.io/
Bug tracker https://github.com/hslua/hslua/issues
Source repo head: git clone https://github.com/hslua/hslua.git
Uploaded by tarleb at 2021-02-27T12:47:51Z
Distributions NixOS:1.0.0
Downloads 28 total (5 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Hackage Matrix CI
Docs not available [build log]
All reported builds failed as of 2021-02-27 [all 2 reports]

Modules

  • HsLua
    • HsLua.Core
      • HsLua.Core.Error
      • HsLua.Core.Run
      • HsLua.Core.Types
      • HsLua.Core.Utf8
  • Lua

Downloads

Maintainer's Corner

For package maintainers and hackage trustees


Readme for hslua-core-1.0.0

[back to package description]

hslua-core

Build status AppVeyor Status Hackage

Basic building blocks to interface Haskell and Lua in a Haskell-idiomatic style.

Overview

Lua is a small, well-designed, embeddable scripting language. It has become the de-facto default to make programs extensible and is widely used everywhere from servers over games and desktop applications up to security software and embedded devices. This package provides the basic building blocks for coders to embed Lua into their programs.

Interacting with Lua

HsLua core provides the Lua type to define Lua operations. The operations are executed by calling run. A simple "Hello, World" program, using the Lua print function, is given below:

import HsLua.Core.Lua as Lua

main :: IO ()
main = Lua.run prog
  where
    prog :: Lua ()
    prog = do
      Lua.openlibs  -- load Lua libraries so we can use 'print'
      Lua.getglobal "print"            -- push print function
      Lua.pushstring "Hello, World!"   -- push string argument
      Lua.call
        (NumArgs 1)    -- number of arguments passed to the function
        (NumResults 0) -- number of results expected
                       -- as return values

The Lua stack

Lua's API is stack-centered: most operations involve pushing values to the stack or receiving items from the stack. E.g., calling a function is performed by pushing the function onto the stack, followed by the function arguments in the order they should be passed to the function. The API function call then invokes the function with given numbers of arguments, pops the function and parameters off the stack, and pushes the results.

,----------.
|  arg 3   |
+----------+
|  arg 2   |
+----------+
|  arg 1   |
+----------+                  ,----------.
| function |    call 3 1      | result 1 |
+----------+   ===========>   +----------+
|          |                  |          |
|  stack   |                  |  stack   |
|          |                  |          |

This package provides all basic building blocks to interact with the Lua stack. If you'd like more comfort, please consider using the hslua package.