HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Modulehslua-core-2.3.2Haskell2010

HsLua.Core.Closures

Expose Haskell functions as Lua closures.

  • 2 values
valuepushPreCFunction :: PreCFunction -> LuaE e ()
#

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.

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 Lua.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"