hslua-core-2.0.0.2: Bindings to Lua, an embeddable scripting language
Copyright© 2007–2012 Gracjan Polak;
© 2012–2016 Ömer Sinan Ağacan;
© 2017-2021 Albert Krewinkel
LicenseMIT
MaintainerAlbert Krewinkel <tarleb+hslua@zeitkraut.de>
Stabilitybeta
Portabilitynon-portable (depends on GHC)
Safe HaskellNone
LanguageHaskell2010

HsLua.Core.Closures

Description

Expose Haskell functions as Lua closures.

Synopsis

Documentation

pushPreCFunction :: PreCFunction -> LuaE e () Source #

Converts a pre C function to a Lua function and pushes it to the stack.

Pre C functions collect parameters from the stack and return a CInt that represents number of return values left on the stack. See CFunction for more info.

pushHaskellFunction :: LuaError e => HaskellFunction e -> LuaE e () Source #

Pushes Haskell function as a callable userdata. All values created will be garbage collected. The function should behave similar to a CFunction.

Error conditions should be indicated by raising a catchable exception or by returning the result of error.

Example:

mod23 :: Lua NumResults
mod23 = do
  mn <- tointeger (nthBottom 1)
  case mn of
    Nothing -> pushstring "expected an integer" *> error
    Just n  -> pushinteger (n `mod` 23)
pushHaskellFunction mod23
setglobal "mod23"