File: hslua.hs

package info (click to toggle)
haskell-hslua 2.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 152 kB
  • sloc: haskell: 324; makefile: 6
file content (46 lines) | stat: -rw-r--r-- 1,556 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeApplications  #-}
{- |
Module      : Main
Copyright   : © 2022-2026 Albert Krewinkel
License     : MIT
Maintainer  : Albert Krewinkel <tarleb@hslua.org>

A Haskell-wrapped Lua interpreter with Haskell modules.
-}
module Main (main) where
import Control.Monad (when)
import HsLua.Core  as Lua
  (Exception, openlibs, pushboolean, registryindex, run, setfield)
import HsLua.Packaging (preloadModule)
import HsLua.CLI (EnvBehavior (IgnoreEnvVars), Settings (..), runStandalone)
import System.Environment (getArgs, getProgName)
import qualified HsLua.Module.Path    as Path
import qualified HsLua.Module.System  as System
import qualified HsLua.Module.Text    as Text
import qualified HsLua.Module.Version as Version
import qualified HsLua.Module.Zip     as Zip

-- | Run a default Lua interpreter.
main :: IO ()
main = do
  let settings = Settings
        { settingsVersionInfo = ""
        , settingsRunner = \envBehavior action -> run $ do
            when (envBehavior == IgnoreEnvVars) $ do
              pushboolean True
              setfield registryindex "LUA_NOENV"
            openlibs
            mapM_ preloadModule
              [ Path.documentedModule
              , System.documentedModule
              , Text.documentedModule
              , Version.documentedModule
              , Zip.documentedModule
              ]
            action
        , settingsHistory = Just ".hslua-history"
        }
  prg  <- getProgName
  args <- getArgs
  runStandalone @Lua.Exception settings prg args