luautils 0.1.1.2 → 0.1.2
raw patch · 4 files changed
+83/−10 lines, 4 filesdep +QuickCheckdep +luautilsdep +quickcheck-instancesdep ~basedep ~containersdep ~hslua
Dependencies added: QuickCheck, luautils, quickcheck-instances, test-framework, test-framework-quickcheck2, test-framework-th
Dependency ranges changed: base, containers, hslua
Files
- README +8/−4
- luautils.cabal +19/−4
- src/Scripting/LuaUtils.hs +13/−2
- tests/simple.hs +43/−0
README view
@@ -1,5 +1,5 @@-LuaUtils (luautils-0.1)-============================+LuaUtils (luautils-0.1.2)+========================= This package is an add-on to the @HsLua@ package by Gracjan Polak (http://hackage.haskell.org/package/hslua). @@ -7,13 +7,17 @@ Currently the following features are provided - -1. @Lua.StackValue@ instances for a variety of commonly used datatypes, such as Lists, Tuples, Either, Maybe etc.+1. @Lua.StackValue@ instances for a variety of commonly used datatypes, such as Lists, Maps, Tuples, Either, Maybe etc. 2. @luaDoString@ and @luaDoFile@ utility functions.-3. A way to dump the contents of the stack for debugging purposes.+3. @dumpStack@ function to dump the contents of the stack for debugging. Changelog ========= 0.1 : Intial release+0.1.1.0 : Added a Lua.StackValue instance for Text and Data.Map+0.1.1.1 : No Changes. Bumped version number for upload to Hackage+0.1.1.2 : Fixed bug with the StackValue instance for lists+0.1.2 : HsLua 0.3.9 compatibility; LuaDoFile and LuaDoString now return `IO ()` instead of `IO Int`
luautils.cabal view
@@ -1,5 +1,5 @@ Name: luautils-Version: 0.1.1.2+Version: 0.1.2 Synopsis: Helpers for Haskell integration with Lua Description: This package is an add-on to the @HsLua@ package by Gracjan Polak. HsLua only provides a very bare-bones wrapper over the Lua API, and this@@ -9,7 +9,7 @@ Author: Anupam Jain Maintainer: ajnsit@gmail.com Build-type: Simple-Cabal-version: >=1.6+Cabal-version: >=1.8 stability: Experimental Category: Scripting Extra-source-files: README@@ -20,8 +20,8 @@ source-repository this type: git- location: http://github.com/ajnsit/luautils/tree/v0.1.1.2- tag: v0.1.1.2+ location: http://github.com/ajnsit/luautils/tree/v0.1.2+ tag: v0.1.2 Library hs-source-dirs: src@@ -32,3 +32,18 @@ , custom-prelude >= 0.1 , text >= 0.11 exposed-modules: Scripting.LuaUtils++test-suite simple+ type: exitcode-stdio-1.0+ main-is: simple.hs+ build-depends: base+ , hslua+ , luautils+ , QuickCheck+ , test-framework+ , test-framework-th+ , test-framework-quickcheck2+ , quickcheck-instances+ , containers+ hs-source-dirs: tests+
src/Scripting/LuaUtils.hs view
@@ -129,6 +129,17 @@ valuetype _ = Lua.TUSERDATA +test :: IO ()+test = do+ l <- Lua.newstate+ Lua.push l (True,False,True,False,True)+ dumpStack l+ {-+ (x::Maybe (Bool,Bool)) <- Lua.peek l (-1)+ dumpStack l+ -}++ -- | Stackvalue instance for triples instance (Lua.StackValue a, Lua.StackValue b, Lua.StackValue c) => Lua.StackValue (a,b,c) where@@ -249,13 +260,13 @@ ----------------------- -- | Execute a String containing Lua Code-luaDoString :: Lua.LuaState -> String -> IO Int+luaDoString :: Lua.LuaState -> String -> IO () luaDoString l s = do Lua.loadstring l s "" Lua.call l 0 0 -- | Execute a Lua script file-luaDoFile :: Lua.LuaState -> String -> IO Int+luaDoFile :: Lua.LuaState -> String -> IO () luaDoFile l s = do Lua.loadfile l s Lua.call l 0 0
+ tests/simple.hs view
@@ -0,0 +1,43 @@+{-# LANGUAGE TemplateHaskell #-}++-- This module provides a set of QuickCheck properties that can be run through+-- test-framework to validate a number of expected behaviors of the library.+import Test.QuickCheck+import Test.QuickCheck.Monadic+import Test.Framework.TH+import Test.Framework.Providers.QuickCheck2+import Test.QuickCheck.Instances++import Data.Map (Map)+import qualified Data.Map as Map++import qualified Scripting.Lua as Lua+import Scripting.LuaUtils++import Data.Maybe (fromJust)++-- Check that the StackValue instance for a datatype works+testStackValueInstance :: (Eq t, Lua.StackValue t) => t -> Property+testStackValueInstance xs = monadicIO $ do+ x <- run $ do+ l <- Lua.newstate+ Lua.push l xs+ Lua.peek l (-1)+ assert $ xs == fromJust x++-- Properties for all supported data types+-- TODO: Write more tests+prop_lists :: [Int] -> Property+prop_lists = testStackValueInstance+prop_tuple :: (Int,Int) -> Property+prop_tuple = testStackValueInstance+prop_maps :: Map Int Int -> Property+prop_maps = testStackValueInstance++main :: IO ()+main = do+ verboseCheck prop_lists+ verboseCheck prop_tuple+ verboseCheck prop_maps+-- main = $defaultMainGenerator+