{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
module Test.Tasty.Lua.Module
( pushModule )
where
import Data.ByteString (ByteString)
import Data.FileEmbed
import HsLua.Core
( HaskellFunction, LuaError, NumResults (..), Status (OK)
, dostringTrace, nth, rawset, throwErrorAsException )
import HsLua.Marshalling (pushName)
import Test.Tasty.Lua.Arbitrary
tastyScript :: ByteString
tastyScript :: ByteString
tastyScript = $(embedFile "tasty.lua")
pushModule :: LuaError e => HaskellFunction e
pushModule :: HaskellFunction e
pushModule = ByteString -> LuaE e Status
forall e. ByteString -> LuaE e Status
dostringTrace ByteString
tastyScript LuaE e Status -> (Status -> HaskellFunction e) -> HaskellFunction e
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Status
OK -> CInt -> NumResults
NumResults CInt
1 NumResults -> LuaE e () -> HaskellFunction e
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ do
Name -> LuaE e ()
forall e. Name -> LuaE e ()
pushName Name
"arbitrary"
LuaE e ()
forall e. LuaE e ()
pushArbitraryTable
StackIndex -> LuaE e ()
forall e. LuaError e => StackIndex -> LuaE e ()
rawset (CInt -> StackIndex
nth CInt
3)
LuaE e ()
forall e. LuaError e => LuaE e ()
registerDefaultGenerators
Status
_ -> HaskellFunction e
forall e a. LuaError e => LuaE e a
throwErrorAsException
{-# INLINABLE pushModule #-}