Script 'mail_helper' called by obssrc Hello community, here is the log from the commit of package ghc-hslua-core for openSUSE:Factory checked in at 2022-02-11 23:09:05 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/ghc-hslua-core (Old) and /work/SRC/openSUSE:Factory/.ghc-hslua-core.new.1956 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "ghc-hslua-core" Fri Feb 11 23:09:05 2022 rev:2 rq:953474 version:2.1.0 Changes: -------- --- /work/SRC/openSUSE:Factory/ghc-hslua-core/ghc-hslua-core.changes 2021-11-11 21:37:48.880949595 +0100 +++ /work/SRC/openSUSE:Factory/.ghc-hslua-core.new.1956/ghc-hslua-core.changes 2022-02-11 23:10:58.231216863 +0100 @@ -1,0 +2,9 @@ +Sat Jan 29 10:07:51 UTC 2022 - Peter Simons <[email protected]> + +- Update hslua-core to version 2.1.0. + Upstream has edited the change log file since the last release in + a non-trivial way, i.e. they did more than just add a new entry + at the top. You can review the file at: + http://hackage.haskell.org/package/hslua-core-2.1.0/src/CHANGELOG.md + +------------------------------------------------------------------- Old: ---- hslua-core-2.0.0.2.tar.gz New: ---- hslua-core-2.1.0.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ ghc-hslua-core.spec ++++++ --- /var/tmp/diff_new_pack.DQJrxy/_old 2022-02-11 23:10:58.699218217 +0100 +++ /var/tmp/diff_new_pack.DQJrxy/_new 2022-02-11 23:10:58.703218228 +0100 @@ -1,7 +1,7 @@ # # spec file for package ghc-hslua-core # -# Copyright (c) 2021 SUSE LLC +# Copyright (c) 2022 SUSE LLC # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -19,7 +19,7 @@ %global pkg_name hslua-core %bcond_with tests Name: ghc-%{pkg_name} -Version: 2.0.0.2 +Version: 2.1.0 Release: 0 Summary: Bindings to Lua, an embeddable scripting language License: MIT ++++++ hslua-core-2.0.0.2.tar.gz -> hslua-core-2.1.0.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/hslua-core-2.0.0.2/CHANGELOG.md new/hslua-core-2.1.0/CHANGELOG.md --- old/hslua-core-2.0.0.2/CHANGELOG.md 2001-09-09 03:46:40.000000000 +0200 +++ new/hslua-core-2.1.0/CHANGELOG.md 2001-09-09 03:46:40.000000000 +0200 @@ -1,48 +1,86 @@ # Changelog -`hslua-core` uses [PVP Versioning][1]. +`hslua-core` uses [PVP Versioning][]. -[1]: https://pvp.haskell.org +## hslua-core-2.1.0 -## hslua-core 2.0.0.2 +Released 29-01-2022. + +- The functions `rawget`, `rawgeti`, and `getref` now return the + type of the value that was pushed to the stack. + +- A new function `checkstack'` is added to HsLua.Core.Auxiliary + and exported from the main HsLua.Core module. The function + throws an exception if the stack cannot be grown to + accommodate a given number of elements; it is similar to + `luaL_checkstack`. + +- Added function `requiref`, which safely wraps the unsafe + `luaL_requiref` function. + +- New functions `pcallTrace`, `callTrace`, `dostringTrace`, and + `dofileTrace`: behaves like the respective unsuffixed + functions, but use a message handler that creates a stack + traceback on error. + +- Added function `rotate`, wrapping `lua_rotate`. + +- Package helper `requirehs` signature changed to + + ``` haskell + requirehs :: LuaError e + => Name -- ^ modname + -> (Name -> LuaE e ()) -- ^ openf + -> LuaE e () + ``` + + The function creating and pushing the module value now takes + the module name as an argument. It also behaves more like + `luaL_requiref` in that it reloads the module if the value in + the LOADED table is falsy. + +## hslua-core-2.0.0.2 Released 2021-11-03. -- Fixed output of `pushTypeMismatchError` when there is no value - at the given index. Previously the function would report the - value as type `string` and now reports it as `no value`. +- Fixed output of `pushTypeMismatchError` when there is no value + at the given index. Previously the function would report the + value as type `string` and now reports it as `no value`. -## hslua-core 2.0.0.1 +## hslua-core-2.0.0.1 Released 2021-10-29. -- Fixed bug in pushTypeMismatchError. The function did not use an - absolute stack index in one place, which sometimes lead to - incorrect actual types being reported. +- Fixed bug in pushTypeMismatchError. The function did not use + an absolute stack index in one place, which sometimes lead to + incorrect actual types being reported. -## hslua-core 2.0.0 +## hslua-core-2.0.0 Released 2021-10-21. -- Error handling has been reworked completely. The type of - exceptions used and handled by HsLua is now exposed to the type - system. The type `Lua` makes use of a default error type. Custom - error handling can be implemented by using the `LuaE` type with - an exception type that is an instance of class `LuaError`. - -- Added new module HsLua.Core.Userdata. It contains thin wrappers - around the functions available for creating - Haskell-value-wrapping userdata objects. - -- Added new module HsLua.Core.Closures, containing functions to - expose Haskell functions to Lua. - -- Reverted to using the auxlib `luaL_loadfile` function to load a - Lua file. Previously files were opened and read in Haskell, but - some functionality of the auxlib function was missing. +- Error handling has been reworked completely. The type of + exceptions used and handled by HsLua is now exposed to the + type system. The type `Lua` makes use of a default error type. + Custom error handling can be implemented by using the `LuaE` + type with an exception type that is an instance of class + `LuaError`. + +- Added new module HsLua.Core.Userdata. It contains thin + wrappers around the functions available for creating + Haskell-value-wrapping userdata objects. + +- Added new module HsLua.Core.Closures, containing functions to + expose Haskell functions to Lua. + +- Reverted to using the auxlib `luaL_loadfile` function to load + a Lua file. Previously files were opened and read in Haskell, + but some functionality of the auxlib function was missing. -## hslua-core 1.0.0 +## hslua-core-1.0.0 Released 2021-02-27. Extracted from hslua-1.3.0. + + [PVP Versioning]: https://pvp.haskell.org diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/hslua-core-2.0.0.2/LICENSE new/hslua-core-2.1.0/LICENSE --- old/hslua-core-2.0.0.2/LICENSE 2001-09-09 03:46:40.000000000 +0200 +++ new/hslua-core-2.1.0/LICENSE 2001-09-09 03:46:40.000000000 +0200 @@ -1,7 +1,7 @@ Copyright ?? 1994-2020 Lua.org, PUC-Rio. Copyright ?? 2007-2012 Gracjan Polak Copyright ?? 2012-2015 ??mer Sinan A??acan -Copyright ?? 2016-2021 Albert Krewinkel +Copyright ?? 2016-2022 Albert Krewinkel Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/hslua-core-2.0.0.2/README.md new/hslua-core-2.1.0/README.md --- old/hslua-core-2.0.0.2/README.md 2001-09-09 03:46:40.000000000 +0200 +++ new/hslua-core-2.1.0/README.md 2001-09-09 03:46:40.000000000 +0200 @@ -1,39 +1,39 @@ -# hslua-core +hslua-core +========== -[![Build status][GitHub Actions badge]][GitHub Actions] -[![AppVeyor Status]](https://ci.appveyor.com/project/tarleb/hslua-r2y18) -[![Hackage]](https://hackage.haskell.org/package/hslua-core) +[![Build status][]][1] [![AppVeyor Status][]][2] [![Hackage][]][3] Basic building blocks to interface Haskell and Lua in a Haskell-idiomatic style. -[GitHub Actions badge]: https://img.shields.io/github/workflow/status/hslua/hslua/CI.svg?logo=github -[GitHub Actions]: https://github.com/hslua/hslua/actions -[AppVeyor Status]: https://ci.appveyor.com/api/projects/status/ldutrilgxhpcau94/branch/main?svg=true -[Hackage]: https://img.shields.io/hackage/v/hslua-core.svg - + [Build status]: https://img.shields.io/github/workflow/status/hslua/hslua/CI.svg?logo=github + [1]: https://github.com/hslua/hslua/actions + [AppVeyor Status]: https://ci.appveyor.com/api/projects/status/ldutrilgxhpcau94/branch/main?svg=true + [2]: https://ci.appveyor.com/project/tarleb/hslua-r2y18 + [Hackage]: https://img.shields.io/hackage/v/hslua-core.svg + [3]: https://hackage.haskell.org/package/hslua-core Overview -------- -[Lua] is a small, well-designed, embeddable scripting language. It -has become the de-facto default to make programs extensible and is -widely used everywhere from servers over games and desktop +[Lua][] is a small, well-designed, embeddable scripting language. +It has become the de-facto default to make programs extensible and +is widely used everywhere from servers over games and desktop applications up to security software and embedded devices. This package provides the basic building blocks for coders to embed Lua into their programs. -This package is part of [HsLua], a Haskell framework built around -the embeddable scripting language [Lua]. +This package is part of [HsLua][], a Haskell framework built +around the embeddable scripting language [Lua][]. -[HsLua]: https://hslua.org/ -[Lua]: https://lua.org/ + [Lua]: https://lua.org/ + [HsLua]: https://hslua.org/ Interacting with Lua -------------------- HsLua core provides the `Lua` type to define Lua operations. The -operations are executed by calling `run`. A simple "Hello, World" +operations are executed by calling `run`. A simple ???Hello, World??? program, using the Lua `print` function, is given below: ``` haskell @@ -55,7 +55,7 @@ ### The Lua stack -Lua's API is stack-centered: most operations involve pushing +Lua???s API is stack-centered: most operations involve pushing values to the stack or receiving items from the stack. E.g., calling a function is performed by pushing the function onto the stack, followed by the function arguments in the order they should @@ -77,10 +77,9 @@ | | | | This package provides all basic building blocks to interact with -the Lua stack. If you'd like more comfort, please consider using +the Lua stack. If you???d like more comfort, please consider using the `hslua-packaging` and `hslua-classes` packages. - Error handling -------------- diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/hslua-core-2.0.0.2/hslua-core.cabal new/hslua-core-2.1.0/hslua-core.cabal --- old/hslua-core-2.0.0.2/hslua-core.cabal 2001-09-09 03:46:40.000000000 +0200 +++ new/hslua-core-2.1.0/hslua-core.cabal 2001-09-09 03:46:40.000000000 +0200 @@ -1,6 +1,6 @@ cabal-version: 2.2 name: hslua-core -version: 2.0.0.2 +version: 2.1.0 synopsis: Bindings to Lua, an embeddable scripting language description: Wrappers and helpers to bridge Haskell and <https://www.lua.org/ Lua>. @@ -15,7 +15,7 @@ maintainer: [email protected] copyright: ?? 2007???2012 Gracjan Polak; ?? 2012???2016 ??mer Sinan A??acan; - ?? 2017-2021 Albert Krewinkel + ?? 2017-2022 Albert Krewinkel category: Foreign build-type: Simple extra-source-files: README.md @@ -26,8 +26,9 @@ , GHC == 8.4.4 , GHC == 8.6.5 , GHC == 8.8.4 - , GHC == 8.10.4 + , GHC == 8.10.7 , GHC == 9.0.1 + , GHC == 9.2.1 source-repository head type: git @@ -38,9 +39,9 @@ build-depends: base >= 4.8 && < 5 , bytestring >= 0.10.2 && < 0.12 , exceptions >= 0.8 && < 0.11 - , lua >= 2.0.1 && < 2.1 + , lua >= 2.1 && < 2.2 , mtl >= 2.2 && < 2.3 - , text >= 1.0 && < 1.3 + , text >= 1.2 && < 2.1 ghc-options: -Wall -Wincomplete-record-updates -Wnoncanonical-monad-instances @@ -61,6 +62,7 @@ , HsLua.Core.Error , HsLua.Core.Package , HsLua.Core.Run + , HsLua.Core.Trace , HsLua.Core.Types , HsLua.Core.Unsafe , HsLua.Core.Userdata @@ -70,6 +72,7 @@ reexported-modules: lua:Lua hs-source-dirs: src default-extensions: LambdaCase + , StrictData other-extensions: CPP , DeriveDataTypeable , GeneralizedNewtypeDeriving @@ -87,7 +90,10 @@ , HsLua.Core.AuxiliaryTests , HsLua.Core.ClosuresTests , HsLua.Core.ErrorTests + , HsLua.Core.PackageTests + , HsLua.Core.PrimaryTests , HsLua.Core.RunTests + , HsLua.Core.TraceTests , HsLua.Core.UnsafeTests , HsLua.Core.UserdataTests , Test.Tasty.HsLua diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/hslua-core-2.0.0.2/src/HsLua/Core/Auxiliary.hs new/hslua-core-2.1.0/src/HsLua/Core/Auxiliary.hs --- old/hslua-core-2.0.0.2/src/HsLua/Core/Auxiliary.hs 2001-09-09 03:46:40.000000000 +0200 +++ new/hslua-core-2.1.0/src/HsLua/Core/Auxiliary.hs 2001-09-09 03:46:40.000000000 +0200 @@ -5,7 +5,7 @@ Module : HsLua.Core.Auxiliary Copyright : ?? 2007???2012 Gracjan Polak; ?? 2012???2016 ??mer Sinan A??acan; - ?? 2017-2021 Albert Krewinkel + ?? 2017-2022 Albert Krewinkel License : MIT Maintainer : Albert Krewinkel <[email protected]> Stability : beta @@ -15,7 +15,8 @@ -} module HsLua.Core.Auxiliary ( -- * The Auxiliary Library - dostring + checkstack' + , dostring , dofile , getmetafield , getmetatable' @@ -25,6 +26,7 @@ , loadstring , newmetatable , newstate + , requiref , tostring' , traceback , where' @@ -40,7 +42,7 @@ import Control.Monad ((<$!>)) import Data.ByteString (ByteString) import Data.String (IsString (fromString)) -import HsLua.Core.Error (LuaError, throwErrorAsException) +import HsLua.Core.Error import HsLua.Core.Types (LuaE, Name (Name), Status, StackIndex, liftLua, multret, runWith) import Lua (top) @@ -55,33 +57,44 @@ import qualified HsLua.Core.Types as Lua import qualified Foreign.Storable as Storable +-- | Grows the stack size to @top + sz@ elements, raising an error if +-- the stack cannot grow to that size. @msg@ is an additional text to go +-- into the error message (or the empty string for no additional text). +checkstack' :: LuaError e + => Int -- ^ sz (requested additional size) + -> String -- ^ msg + -> LuaE e () +checkstack' sz msg = + Lua.checkstack sz >>= \case + True -> pure () + False -> failLua $ + if msg == "" + then "stack overflow" + else "stack overflow (" ++ msg ++ ")" + -- | Loads and runs the given string. -- -- Returns 'Lua.OK' on success, or an error if either loading of the -- string or calling of the thunk failed. dostring :: ByteString -> LuaE e Status -dostring s = do - loadRes <- loadstring s - if loadRes == Lua.OK - then Lua.pcall 0 multret Nothing - else return loadRes +dostring s = loadstring s >>= \case + Lua.OK -> Lua.pcall 0 multret Nothing + err -> return err {-# INLINABLE dostring #-} -- | Loads and runs the given file. Note that the filepath is --- interpreted by Haskell, not Lua. The resulting chunk is named using +-- interpreted by Lua, not Haskell. The resulting chunk is named using -- the UTF8 encoded filepath. dofile :: FilePath -> LuaE e Status -dofile fp = do - loadRes <- loadfile fp - if loadRes == Lua.OK - then Lua.pcall 0 multret Nothing - else return loadRes +dofile fp = loadfile fp >>= \case + Lua.OK -> Lua.pcall 0 multret Nothing + err -> return err {-# INLINABLE dofile #-} -- | Pushes onto the stack the field @e@ from the metatable of the -- object at index @obj@ and returns the type of the pushed value. If -- the object does not have a metatable, or if the metatable does not --- have this field, pushes nothing and returns 'TypeNil'. +-- have this field, pushes nothing and returns 'Lua.TypeNil'. -- -- Wraps 'luaL_getmetafield'. getmetafield :: StackIndex -- ^ obj @@ -103,7 +116,7 @@ {-# INLINABLE getmetatable' #-} -- | Push referenced value from the table at the given index. -getref :: LuaError e => StackIndex -> Reference -> LuaE e () +getref :: LuaError e => StackIndex -> Reference -> LuaE e Lua.Type getref idx ref' = Lua.rawgeti idx (fromIntegral (Lua.fromReference ref')) {-# INLINABLE getref #-} @@ -158,8 +171,6 @@ -- As @'Lua.load'@, this function only loads the chunk; it does not run -- it. -- --- Note that the file is opened by Haskell, not Lua. --- -- See <https://www.lua.org/manual/5.3/manual.html#luaL_loadfile luaL_loadfile>. loadfile :: FilePath -- ^ filename -> LuaE e Status @@ -231,6 +242,27 @@ ref t = liftLua $ \l -> Lua.toReference <$> luaL_ref l t {-# INLINABLE ref #-} +-- | If @modname@ is not already present in @package.loaded@. calls +-- function @openf@ with string @modname@ as an argument and sets the +-- call result in @package.loaded[modname]@, as if that function has +-- been called through +-- <https://www.lua.org/manual/5.3/manual.html#pdf-require require>. +-- +-- If @glb@ is true, also stores the module into global @modname@. +-- +-- Leaves a copy of the module on the stack. +-- +-- See 'requirehs' for a version intended to be used with Haskell +-- actions. +requiref :: LuaError e + => Name -- ^ modname + -> Lua.CFunction -- ^ openf + -> Bool -- ^ glb + -> LuaE e () +requiref (Name name) openf glb = liftLuaThrow $ \l status' -> + B.useAsCString name $ \namePtr -> + hsluaL_requiref l namePtr openf (Lua.toLuaBool glb) status' + -- | Converts any Lua value at the given index to a 'ByteString' in a -- reasonable format. The resulting string is pushed onto the stack and -- also returned by the function. @@ -253,7 +285,7 @@ {-# INLINABLE tostring' #-} -- | Creates and pushes a traceback of the stack L1. If a message is --- given it appended at the beginning of the traceback. The level +-- given it is appended at the beginning of the traceback. The level -- parameter tells at which level to start the traceback. -- -- Wraps 'luaL_traceback'. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/hslua-core-2.0.0.2/src/HsLua/Core/Closures.hs new/hslua-core-2.1.0/src/HsLua/Core/Closures.hs --- old/hslua-core-2.0.0.2/src/HsLua/Core/Closures.hs 2001-09-09 03:46:40.000000000 +0200 +++ new/hslua-core-2.1.0/src/HsLua/Core/Closures.hs 2001-09-09 03:46:40.000000000 +0200 @@ -2,7 +2,7 @@ Module : HsLua.Core.Closures Copyright : ?? 2007???2012 Gracjan Polak; ?? 2012???2016 ??mer Sinan A??acan; - ?? 2017-2021 Albert Krewinkel + ?? 2017-2022 Albert Krewinkel License : MIT Maintainer : Albert Krewinkel <[email protected]> Stability : beta @@ -27,7 +27,7 @@ -- -- Pre C functions collect parameters from the stack and return a @CInt@ -- that represents number of return values left on the stack. --- See 'Lua.CFunction' for more info. +-- See 'Lua.Types.CFunction' for more info. pushPreCFunction :: PreCFunction -> LuaE e () pushPreCFunction preCFn = liftLua $ \l -> hslua_pushhsfunction l preCFn @@ -35,7 +35,7 @@ -- | Pushes Haskell function as a callable userdata. All values created -- will be garbage collected. The function should behave similar to a --- 'CFunction'. +-- 'Lua.Types.CFunction'. -- -- Error conditions should be indicated by raising a catchable exception -- or by returning the result of @'Lua.error'@. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/hslua-core-2.0.0.2/src/HsLua/Core/Error.hs new/hslua-core-2.1.0/src/HsLua/Core/Error.hs --- old/hslua-core-2.0.0.2/src/HsLua/Core/Error.hs 2001-09-09 03:46:40.000000000 +0200 +++ new/hslua-core-2.1.0/src/HsLua/Core/Error.hs 2001-09-09 03:46:40.000000000 +0200 @@ -8,7 +8,7 @@ {-# OPTIONS_GHC -Wno-warnings-deprecations #-} {-| Module : HsLua.Core.Error -Copyright : ?? 2017-2021 Albert Krewinkel +Copyright : ?? 2017-2022 Albert Krewinkel License : MIT Maintainer : Albert Krewinkel <[email protected]> @@ -151,7 +151,7 @@ -- -- | Takes a failable HsLua function and transforms it into a --- monadic 'Lua' operation. Throws an exception if an error +-- monadic 'LuaE' operation. Throws an exception if an error -- occured. liftLuaThrow :: forall e a. LuaError e => (Lua.State -> Ptr Lua.StatusCode -> IO a) @@ -179,7 +179,7 @@ -- the message failed. -- -- This helpful as a \"last resort\" method when implementing --- 'peekException'. +-- 'popException'. popErrorMessage :: Lua.State -> IO ByteString popErrorMessage l = alloca $ \lenPtr -> do cstr <- hsluaL_tolstring l (-1) lenPtr diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/hslua-core-2.0.0.2/src/HsLua/Core/Package.hs new/hslua-core-2.1.0/src/HsLua/Core/Package.hs --- old/hslua-core-2.0.0.2/src/HsLua/Core/Package.hs 2001-09-09 03:46:40.000000000 +0200 +++ new/hslua-core-2.1.0/src/HsLua/Core/Package.hs 2001-09-09 03:46:40.000000000 +0200 @@ -1,6 +1,6 @@ {-| Module : HsLua.Core.Package -Copyright : ?? 2019-2021 Albert Krewinkel +Copyright : ?? 2019-2022 Albert Krewinkel License : MIT Maintainer : Albert Krewinkel <[email protected]> Stability : alpha @@ -25,32 +25,32 @@ -- | Load a module, defined by a Haskell action, under the given -- name. -- --- Similar to @luaL_required@: After checking "loaded" table, --- calls @pushMod@ to push a module to the stack, and registers --- the result in @package.loaded@ table. --- --- The @pushMod@ function must push exactly one element to the top --- of the stack. This is not checked, but failure to do so will --- lead to problems. Lua's @package@ module must have been loaded --- by the time this function is invoked. +-- Similar to @luaL_requiref@: If @modname@ is not already present in +-- @package.loaded@, calls function @openf@ with string @modname@ as an +-- argument and sets the call result in @package.loaded[modname]@, as if +-- that function has been called through +-- <https://www.lua.org/manual/5.3/manual.html#pdf-require require>. -- -- Leaves a copy of the module on the stack. -requirehs :: LuaError e => Name -> LuaE e () -> LuaE e () -requirehs modname pushMod = do - -- get table of loaded modules - void $ getfield registryindex loaded - - -- Check whether module has already been loaded. - getfield top modname >>= \case -- LOADED[modname] - TypeNil -> do -- not loaded yet, load now - pop 1 -- remove LOADED[modname], i.e., nil - pushMod -- push module - pushvalue top -- make copy of module - -- add module under the given name (LOADED[modname] = module) +requirehs :: LuaError e + => Name -- ^ modname + -> (Name -> LuaE e ()) -- ^ openf + -> LuaE e () +requirehs modname openf = do + void $ getsubtable registryindex loaded + void $ getfield top modname + toboolean top >>= \case + True -> pure () -- package already loaded + False -> do + -- package not loaded, load it now + pop 1 -- remove field + oldtop <- gettop + openf modname + settop (oldtop + 1) + pushvalue top -- make copy of module (call result) setfield (nth 3) modname - _ -> return () - remove (nth 2) -- remove table of loaded modules + remove (nth 2) -- remove LOADED table -- | Registers a preloading function. Takes an module name and the -- Lua operation which produces the package. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/hslua-core-2.0.0.2/src/HsLua/Core/Primary.hs new/hslua-core-2.1.0/src/HsLua/Core/Primary.hs --- old/hslua-core-2.0.0.2/src/HsLua/Core/Primary.hs 2001-09-09 03:46:40.000000000 +0200 +++ new/hslua-core-2.1.0/src/HsLua/Core/Primary.hs 2001-09-09 03:46:40.000000000 +0200 @@ -3,7 +3,7 @@ Module : HsLua.Core.Primary Copyright : ?? 2007???2012 Gracjan Polak; ?? 2012???2016 ??mer Sinan A??acan; - ?? 2017-2021 Albert Krewinkel + ?? 2017-2022 Albert Krewinkel License : MIT Maintainer : Albert Krewinkel <[email protected]> Stability : beta @@ -38,7 +38,7 @@ -- | Execute an action only if the given index is a table. Throw an -- error otherwise. -ensureTable :: LuaError e => StackIndex -> (Lua.State -> IO ()) -> LuaE e () +ensureTable :: LuaError e => StackIndex -> (Lua.State -> IO a) -> LuaE e a ensureTable idx ioOp = do isTbl <- istable idx if isTbl @@ -711,8 +711,8 @@ -- metamethods). -- -- Wraps 'lua_rawget'. -rawget :: LuaError e => StackIndex -> LuaE e () -rawget n = ensureTable n (\l -> lua_rawget l n) +rawget :: LuaError e => StackIndex -> LuaE e Type +rawget n = ensureTable n (\l -> toType <$!> lua_rawget l n) {-# INLINABLE rawget #-} -- | Pushes onto the stack the value @t[n]@, where @t@ is the table at @@ -720,8 +720,8 @@ -- @__index@ metamethod. -- -- Wraps 'lua_rawgeti'. -rawgeti :: LuaError e => StackIndex -> Lua.Integer -> LuaE e () -rawgeti k n = ensureTable k (\l -> lua_rawgeti l k n) +rawgeti :: LuaError e => StackIndex -> Lua.Integer -> LuaE e Type +rawgeti k n = ensureTable k (\l -> toType <$!> lua_rawgeti l k n) {-# INLINABLE rawgeti #-} -- | Returns the raw "length" of the value at the given index: for @@ -756,7 +756,7 @@ -- | Sets the C function @f@ as the new value of global @name@. -- --- Wraps 'lua_register'. +-- Behaves like "lua_register". register :: LuaError e => Name -> CFunction -> LuaE e () register name f = do pushcfunction f @@ -782,6 +782,21 @@ replace n = liftLua $ \l -> lua_replace l n {-# INLINABLE replace #-} +-- | Rotates the stack elements between the valid index @idx@ and the +-- top of the stack. The elements are rotated @n@ positions in the +-- direction of the top, for a positive @n@, or @-n@ positions in the +-- direction of the bottom, for a negative @n@. The absolute value of +-- @n@ must not be greater than the size of the slice being rotated. +-- This function cannot be called with a pseudo-index, because a +-- pseudo-index is not an actual stack position. +-- +-- <https://www.lua.org/manual/5.3/manual.html#lua_rotate> +rotate :: StackIndex -- ^ @idx@ + -> Int -- ^ @n@ + -> LuaE e () +rotate idx n = liftLua $ \l -> lua_rotate l idx (fromIntegral n) +{-# INLINABLE rotate #-} + -- | Does the equivalent to @t[k] = v@, where @t@ is the value at the -- given index and @v@ is the value at the top of the stack. -- diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/hslua-core-2.0.0.2/src/HsLua/Core/Run.hs new/hslua-core-2.1.0/src/HsLua/Core/Run.hs --- old/hslua-core-2.0.0.2/src/HsLua/Core/Run.hs 2001-09-09 03:46:40.000000000 +0200 +++ new/hslua-core-2.1.0/src/HsLua/Core/Run.hs 2001-09-09 03:46:40.000000000 +0200 @@ -2,13 +2,13 @@ Module : HsLua.Core.Run Copyright : ?? 2007???2012 Gracjan Polak; ?? 2012???2016 ??mer Sinan A??acan; - ?? 2017-2021 Albert Krewinkel + ?? 2017-2022 Albert Krewinkel License : MIT Maintainer : Albert Krewinkel <[email protected]> Stability : beta Portability : non-portable (depends on GHC) -Helper functions to run 'Lua' computations. +Helper functions to run 'LuaE' computations. -} module HsLua.Core.Run ( run diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/hslua-core-2.0.0.2/src/HsLua/Core/Trace.hs new/hslua-core-2.1.0/src/HsLua/Core/Trace.hs --- old/hslua-core-2.0.0.2/src/HsLua/Core/Trace.hs 1970-01-01 01:00:00.000000000 +0100 +++ new/hslua-core-2.1.0/src/HsLua/Core/Trace.hs 2001-09-09 03:46:40.000000000 +0200 @@ -0,0 +1,69 @@ +{-# LANGUAGE TypeApplications #-} +{-| +Module : HsLua.Core.Trace +Copyright : ?? 2017-2022 Albert Krewinkel +License : MIT +Maintainer : Albert Krewinkel <[email protected]> + +Helper functions to call Lua functions with tracebacks. +-} +module HsLua.Core.Trace + ( pcallTrace + , callTrace + , dofileTrace + , dostringTrace + ) where + +import Data.ByteString (ByteString) +import Foreign.C.Types +import HsLua.Core.Auxiliary (loadfile, loadstring, tostring', traceback) +import HsLua.Core.Error (Exception, LuaError, throwErrorAsException) +import HsLua.Core.Primary (gettop, insert, pcall, pushcfunction, remove) +import HsLua.Core.Run (runWith) +import HsLua.Core.Types + ( CFunction, LuaE, NumArgs (..), NumResults (..), PreCFunction + , Status (OK), State (..), multret ) + +-- | Like @'pcall'@, but sets an appropriate message handler function, +-- thereby adding a stack traceback if an error occurs. +pcallTrace :: NumArgs -> NumResults -> LuaE e Status +pcallTrace nargs@(NumArgs nargsint) nres = do + curtop <- gettop + let base = curtop - fromIntegral nargsint -- function index + pushcfunction hsluaL_msghandler_ptr + insert base -- insert msghandler below function + status' <- pcall nargs nres (Just base) + remove base + return status' + +-- | Like @'call'@, but adds a traceback if an error occurs. +callTrace :: LuaError e => NumArgs -> NumResults -> LuaE e () +callTrace nargs nres = pcallTrace nargs nres >>= \case + OK -> pure () + _ -> throwErrorAsException + +-- | Run the given file as a Lua program, while also adding a +-- traceback to the error message if an error occurs. +dofileTrace :: FilePath -> LuaE e Status +dofileTrace fp = loadfile fp >>= \case + OK -> pcallTrace 0 multret + s -> pure s + +dostringTrace :: ByteString -> LuaE e Status +dostringTrace s = loadstring s >>= \case + OK -> pcallTrace 0 multret + err -> pure err + +-- | Helper function used as message handler if the function given to +-- pcall fails. +hsluaL_msghandler :: State -> IO NumResults +hsluaL_msghandler l = runWith l $ do + msg <- tostring' @Exception 1 + traceback l (Just msg) 2 + pure (NumResults 1) + +-- Turn message handler into a CFunction by exporting it, then importing +-- at pointer to it. +foreign export ccall hsluaL_msghandler :: PreCFunction +foreign import ccall "&hsluaL_msghandler" + hsluaL_msghandler_ptr:: CFunction diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/hslua-core-2.0.0.2/src/HsLua/Core/Types.hs new/hslua-core-2.1.0/src/HsLua/Core/Types.hs --- old/hslua-core-2.0.0.2/src/HsLua/Core/Types.hs 2001-09-09 03:46:40.000000000 +0200 +++ new/hslua-core-2.1.0/src/HsLua/Core/Types.hs 2001-09-09 03:46:40.000000000 +0200 @@ -4,7 +4,7 @@ Module : HsLua.Core.Types Copyright : ?? 2007???2012 Gracjan Polak; ?? 2012???2016 ??mer Sinan A??acan; - ?? 2017-2021 Albert Krewinkel + ?? 2017-2022 Albert Krewinkel License : MIT Maintainer : Albert Krewinkel <[email protected]> Stability : beta @@ -312,7 +312,7 @@ -- Special values -- --- | Option for multiple returns in @'pcall'@. +-- | Option for multiple returns in @'HsLua.Core.pcall'@. multret :: NumResults multret = LUA_MULTRET diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/hslua-core-2.0.0.2/src/HsLua/Core/Unsafe.hs new/hslua-core-2.1.0/src/HsLua/Core/Unsafe.hs --- old/hslua-core-2.0.0.2/src/HsLua/Core/Unsafe.hs 2001-09-09 03:46:40.000000000 +0200 +++ new/hslua-core-2.1.0/src/HsLua/Core/Unsafe.hs 2001-09-09 03:46:40.000000000 +0200 @@ -1,7 +1,7 @@ {-# OPTIONS_GHC -Wno-warnings-deprecations #-} {-| Module : HsLua.Core.Unsafe -Copyright : ?? 2019-2021 Albert Krewinkel +Copyright : ?? 2019-2022 Albert Krewinkel License : MIT Maintainer : Albert Krewinkel <[email protected]> @@ -24,7 +24,7 @@ -- __WARNING__: @lua_next@ is unsafe in Haskell: This function will -- cause an unrecoverable crash an error if the given key is neither -- @nil@ nor present in the table. Consider using the safe --- @'HsLua.Core.Primary.next'@ function in HsLua.Core instead. +-- @'HsLua.Core.next'@ function in HsLua.Core instead. next :: StackIndex -> LuaE e Bool next idx = liftLua $ \l -> fromLuaBool <$!> lua_next l idx {-# INLINABLE next #-} diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/hslua-core-2.0.0.2/src/HsLua/Core/Userdata.hs new/hslua-core-2.1.0/src/HsLua/Core/Userdata.hs --- old/hslua-core-2.0.0.2/src/HsLua/Core/Userdata.hs 2001-09-09 03:46:40.000000000 +0200 +++ new/hslua-core-2.1.0/src/HsLua/Core/Userdata.hs 2001-09-09 03:46:40.000000000 +0200 @@ -3,7 +3,7 @@ Module : HsLua.Core.Userdata Copyright : ?? 2007???2012 Gracjan Polak; ?? 2012???2016 ??mer Sinan A??acan; - ?? 2017-2021 Albert Krewinkel + ?? 2017-2022 Albert Krewinkel License : MIT Maintainer : Albert Krewinkel <[email protected]> Stability : beta diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/hslua-core-2.0.0.2/src/HsLua/Core/Utf8.hs new/hslua-core-2.1.0/src/HsLua/Core/Utf8.hs --- old/hslua-core-2.0.0.2/src/HsLua/Core/Utf8.hs 2001-09-09 03:46:40.000000000 +0200 +++ new/hslua-core-2.1.0/src/HsLua/Core/Utf8.hs 2001-09-09 03:46:40.000000000 +0200 @@ -1,6 +1,6 @@ {-| Module : HsLua.Core.Utf8 -Copyright : ?? 2018-2021 Albert Krewinkel +Copyright : ?? 2018-2022 Albert Krewinkel License : MIT Maintainer : Albert Krewinkel <[email protected]> Stability : beta diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/hslua-core-2.0.0.2/src/HsLua/Core.hs new/hslua-core-2.1.0/src/HsLua/Core.hs --- old/hslua-core-2.0.0.2/src/HsLua/Core.hs 2001-09-09 03:46:40.000000000 +0200 +++ new/hslua-core-2.1.0/src/HsLua/Core.hs 2001-09-09 03:46:40.000000000 +0200 @@ -2,7 +2,7 @@ Module : HsLua.Core Copyright : ?? 2007???2012 Gracjan Polak; ?? 2012???2016 ??mer Sinan A??acan; - ?? 2017-2021 Albert Krewinkel + ?? 2017-2022 Albert Krewinkel License : MIT Maintainer : Albert Krewinkel <[email protected]> Stability : beta @@ -58,6 +58,7 @@ , pushvalue , copy , insert + , rotate , pop , remove , replace @@ -154,12 +155,14 @@ , openstring , opentable -- * Auxiliary library + , checkstack' , dostring , dofile , getmetafield , getmetatable' , getsubtable , newmetatable + , requiref , tostring' , traceback , where' @@ -175,6 +178,11 @@ -- ** Registry fields , loaded , preload + -- ** Running with tracebacks + , pcallTrace + , callTrace + , dofileTrace + , dostringTrace -- * Haskell userdata values -- -- | Push arbitrary Haskell values to the Lua stack. @@ -210,5 +218,6 @@ import HsLua.Core.Package import HsLua.Core.Primary import HsLua.Core.Run +import HsLua.Core.Trace import HsLua.Core.Types as Lua import HsLua.Core.Userdata diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/hslua-core-2.0.0.2/test/HsLua/Core/AuxiliaryTests.hs new/hslua-core-2.1.0/test/HsLua/Core/AuxiliaryTests.hs --- old/hslua-core-2.0.0.2/test/HsLua/Core/AuxiliaryTests.hs 2001-09-09 03:46:40.000000000 +0200 +++ new/hslua-core-2.1.0/test/HsLua/Core/AuxiliaryTests.hs 2001-09-09 03:46:40.000000000 +0200 @@ -7,16 +7,28 @@ import Data.ByteString (ByteString) import Data.Maybe (fromMaybe) import HsLua.Core (nth) -import Test.Tasty.HsLua ((?:), (=:), pushLuaExpr, shouldBeResultOf) +import Test.Tasty.HsLua ( (?:), (=:), pushLuaExpr, shouldBeResultOf + , shouldBeErrorMessageOf) import Test.Tasty (TestTree, testGroup) import Test.Tasty.HUnit ((@=?)) +import qualified Lua import qualified HsLua.Core as Lua -- | Specifications for Attributes parsing functions. tests :: TestTree tests = testGroup "Auxiliary" - [ testGroup "getsubtable" + [ testGroup "checkstack'" + [ "returns unit if stack space can be provided" =: + () `shouldBeResultOf` Lua.checkstack' 2 "test" + + -- testing the error case is not possible for some reason + -- , "fails if too much stack space is requested" =: + -- "stack overflow (test)"`shouldBeErrorMessageOf` + -- Lua.checkstack' maxBound "test" + ] + + , testGroup "getsubtable" [ "gets a subtable from field" =: [5, 8] `shouldBeResultOf` do pushLuaExpr @Lua.Exception "{foo = {5, 8}}" @@ -81,6 +93,34 @@ Lua.getmetatable' "yep" ] + , testGroup "requiref" + [ "can load a module" =: do + Lua.TypeTable `shouldBeResultOf` do + Lua.openlibs + Lua.requiref "mathematics" Lua.luaopen_math False + Lua.ltype Lua.top + + , "returns () on success" =: do + () `shouldBeResultOf` do + Lua.openlibs + -- already loaded + Lua.requiref "math" Lua.luaopen_math False + + , "sets global if flag is set" =: do + Lua.TypeTable `shouldBeResultOf` do + Lua.openlibs + Lua.requiref "foo" Lua.luaopen_math True + Lua.pop 1 + Lua.getglobal "foo" + + , "catches errors" =: do + "attempt to index a nil value" `shouldBeErrorMessageOf` do + -- unset registry + Lua.pushnil + Lua.copy Lua.top Lua.registryindex + Lua.requiref "math" Lua.luaopen_package False + ] + , testGroup "where'" [ "return location in chunk" =: "test:1: nope, not yet" `shouldBeResultOf` do diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/hslua-core-2.0.0.2/test/HsLua/Core/ClosuresTests.hs new/hslua-core-2.1.0/test/HsLua/Core/ClosuresTests.hs --- old/hslua-core-2.0.0.2/test/HsLua/Core/ClosuresTests.hs 2001-09-09 03:46:40.000000000 +0200 +++ new/hslua-core-2.1.0/test/HsLua/Core/ClosuresTests.hs 2001-09-09 03:46:40.000000000 +0200 @@ -2,7 +2,7 @@ {-# OPTIONS_GHC -fno-warn-deprecations #-} {-| Module : HsLua.Core.ClosuresTests -Copyright : ?? 2017-2021 Albert Krewinkel +Copyright : ?? 2017-2022 Albert Krewinkel License : MIT Maintainer : Albert Krewinkel <[email protected]> diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/hslua-core-2.0.0.2/test/HsLua/Core/PackageTests.hs new/hslua-core-2.1.0/test/HsLua/Core/PackageTests.hs --- old/hslua-core-2.0.0.2/test/HsLua/Core/PackageTests.hs 1970-01-01 01:00:00.000000000 +0100 +++ new/hslua-core-2.1.0/test/HsLua/Core/PackageTests.hs 2001-09-09 03:46:40.000000000 +0200 @@ -0,0 +1,74 @@ +{-# LANGUAGE OverloadedStrings #-} +{-| +Module : HsLua.Core.RunTests +Copyright : ?? 2017-2022 Albert Krewinkel +License : MIT + +Maintainer : Albert Krewinkel <[email protected]> +Stability : stable +Portability : portable + +Tests for different convenience functions to run Lua operations. +-} +module HsLua.Core.PackageTests (tests) where + +import HsLua.Core as Lua +import Test.Tasty.HsLua ((=:), pushLuaExpr, shouldBeResultOf) +import Test.Tasty (TestTree, testGroup) + +-- | Specifications for Attributes parsing functions. +tests :: TestTree +tests = testGroup "Package" + [ testGroup "requirehs" + [ "call the given function" =: + "test" `shouldBeResultOf` do + Lua.openlibs + let openf (Lua.Name name) = Lua.pushstring name + Lua.requirehs "test" openf + Lua.tostring' Lua.top + + , "doesn't call function if module has been loaded" =: + "foo" `shouldBeResultOf` do + Lua.openlibs + Lua.requirehs "test" (const $ Lua.pushstring "foo") + Lua.pop 1 + Lua.requirehs "test" (const $ Lua.failLua "nope") + Lua.tostring' Lua.top + + , "pushes module to stack" =: + 1 `shouldBeResultOf` do + Lua.openlibs + old <- Lua.gettop + Lua.requirehs "foo" (\_ -> Lua.pushnumber 5.0 *> pushboolean True) + new <- Lua.gettop + return (new - old) + + , "module can be loaded with `require`" =: + let testModule = "string as a module" + in Just testModule `shouldBeResultOf` do + Lua.openlibs + Lua.requirehs "test.module" (const (Lua.pushstring testModule)) + pushLuaExpr "require 'test.module'" + Lua.tostring Lua.top + + ] + + , testGroup "preloadhs" + [ "does not modify the stack" =: + 0 `shouldBeResultOf` do + Lua.openlibs + old <- Lua.gettop + Lua.preloadhs "foo" (1 <$ Lua.pushnumber 5.0) + new <- Lua.gettop + return (new - old) + + , "module can be loaded with `require`" =: + let testModule = "string as a module" + in Just testModule `shouldBeResultOf` do + Lua.openlibs + Lua.preloadhs "test.module" (1 <$ Lua.pushstring testModule) + pushLuaExpr "require 'test.module'" + Lua.tostring Lua.top + ] + + ] diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/hslua-core-2.0.0.2/test/HsLua/Core/PrimaryTests.hs new/hslua-core-2.1.0/test/HsLua/Core/PrimaryTests.hs --- old/hslua-core-2.0.0.2/test/HsLua/Core/PrimaryTests.hs 1970-01-01 01:00:00.000000000 +0100 +++ new/hslua-core-2.1.0/test/HsLua/Core/PrimaryTests.hs 2001-09-09 03:46:40.000000000 +0200 @@ -0,0 +1,27 @@ +{-# LANGUAGE OverloadedStrings #-} +{-| Tests for the primary library. +-} +module HsLua.Core.PrimaryTests (tests) where + +import HsLua.Core +import Test.Tasty.HsLua ((=:), shouldBeResultOf) +import Test.Tasty (TestTree, testGroup) + +-- | Specifications for Attributes parsing functions. +tests :: TestTree +tests = testGroup "Primary" + [ testGroup "rotate'" + [ "rotates stack" =: + (Just 2, Just 1, Just 4, Just 3) `shouldBeResultOf` do + pushnumber 4 + pushnumber 3 + pushnumber 2 + pushnumber 1 + rotate (nth 4) 2 + (,,,) + <$> tonumber (nth 4) + <*> tonumber (nth 3) + <*> tonumber (nth 2) + <*> tonumber (nth 1) + ] + ] diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/hslua-core-2.0.0.2/test/HsLua/Core/RunTests.hs new/hslua-core-2.1.0/test/HsLua/Core/RunTests.hs --- old/hslua-core-2.0.0.2/test/HsLua/Core/RunTests.hs 2001-09-09 03:46:40.000000000 +0200 +++ new/hslua-core-2.1.0/test/HsLua/Core/RunTests.hs 2001-09-09 03:46:40.000000000 +0200 @@ -3,7 +3,7 @@ {-# OPTIONS_GHC -fno-warn-deprecations #-} {-| Module : HsLua.Core.RunTests -Copyright : ?? 2017-2021 Albert Krewinkel +Copyright : ?? 2017-2022 Albert Krewinkel License : MIT Maintainer : Albert Krewinkel <[email protected]> diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/hslua-core-2.0.0.2/test/HsLua/Core/TraceTests.hs new/hslua-core-2.1.0/test/HsLua/Core/TraceTests.hs --- old/hslua-core-2.0.0.2/test/HsLua/Core/TraceTests.hs 1970-01-01 01:00:00.000000000 +0100 +++ new/hslua-core-2.1.0/test/HsLua/Core/TraceTests.hs 2001-09-09 03:46:40.000000000 +0200 @@ -0,0 +1,58 @@ +{-# LANGUAGE OverloadedStrings #-} +{-| +Module : HsLua.Core.TraceTests +Copyright : ?? 2017-2022 Albert Krewinkel +License : MIT + +Maintainer : Albert Krewinkel <[email protected]> +Stability : stable +Portability : portable + +Test call functions that produce traces on error. +-} +module HsLua.Core.TraceTests (tests) where + +import Data.ByteString (isInfixOf) +import HsLua.Core as Lua +import Test.Tasty.HsLua ( (=:), shouldBeResultOf, shouldHoldForResultOf + , pushLuaExpr) +import Test.Tasty (TestTree, testGroup) +import qualified Data.List as List + +-- | Specifications for Attributes parsing functions. +tests :: TestTree +tests = testGroup "Trace" + [ testGroup "pcallTrace" + [ "Calls the function" =: + "motor" `shouldBeResultOf` do + openlibs + pushLuaExpr "function () return 'motor' end" + OK <- pcallTrace 0 1 + tostring' top + + , "Adds a traceback" =: + ("\nstack traceback:\n" `isInfixOf`) `shouldHoldForResultOf` do + openlibs + pushLuaExpr "function (b) error(tostring(b)) end" + pushinteger 23 + ErrRun <- pcallTrace 1 1 + tostring' top + ] + , testGroup "callTrace" + [ "Calls the function" =: + "motor" `shouldBeResultOf` do + openlibs + pushLuaExpr "function () return 'motor' end" + callTrace 0 1 + tostring' top + + , "Adds a traceback" =: + ("\nstack traceback:\n" `List.isInfixOf`) `shouldHoldForResultOf` do + either show (const $ Prelude.error "should not succeed") <$> try + (do openlibs + pushLuaExpr "function (b) error(tostring(b)) end" + pushinteger 23 + callTrace 1 1 + tostring' top) + ] + ] diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/hslua-core-2.0.0.2/test/HsLua/Core/UnsafeTests.hs new/hslua-core-2.1.0/test/HsLua/Core/UnsafeTests.hs --- old/hslua-core-2.0.0.2/test/HsLua/Core/UnsafeTests.hs 2001-09-09 03:46:40.000000000 +0200 +++ new/hslua-core-2.1.0/test/HsLua/Core/UnsafeTests.hs 2001-09-09 03:46:40.000000000 +0200 @@ -2,7 +2,7 @@ {-# LANGUAGE OverloadedStrings #-} {-| Module : HsLua.Core.UnsafeTests -Copyright : ?? 2021 Albert Krewinkel +Copyright : ?? 2021-2022 Albert Krewinkel License : MIT Maintainer : Albert Krewinkel <[email protected]> Stability : beta diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/hslua-core-2.0.0.2/test/HsLua/Core/UserdataTests.hs new/hslua-core-2.1.0/test/HsLua/Core/UserdataTests.hs --- old/hslua-core-2.0.0.2/test/HsLua/Core/UserdataTests.hs 2001-09-09 03:46:40.000000000 +0200 +++ new/hslua-core-2.1.0/test/HsLua/Core/UserdataTests.hs 2001-09-09 03:46:40.000000000 +0200 @@ -1,7 +1,7 @@ {-# LANGUAGE OverloadedStrings #-} {-| Module : HsLua.Core.UserdataTests -Copyright : ?? 2017-2021 Albert Krewinkel +Copyright : ?? 2017-2022 Albert Krewinkel License : MIT Maintainer : Albert Krewinkel <[email protected]> diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/hslua-core-2.0.0.2/test/HsLua/CoreTests.hs new/hslua-core-2.1.0/test/HsLua/CoreTests.hs --- old/hslua-core-2.0.0.2/test/HsLua/CoreTests.hs 2001-09-09 03:46:40.000000000 +0200 +++ new/hslua-core-2.1.0/test/HsLua/CoreTests.hs 2001-09-09 03:46:40.000000000 +0200 @@ -3,7 +3,7 @@ {-# OPTIONS_GHC -fno-warn-deprecations #-} {-| Module : HsLua.CoreTests -Copyright : ?? 2017-2021 Albert Krewinkel +Copyright : ?? 2017-2022 Albert Krewinkel License : MIT Maintainer : Albert Krewinkel <[email protected]> @@ -33,8 +33,12 @@ import qualified Prelude import qualified Data.ByteString as B import qualified HsLua.Core.AuxiliaryTests +import qualified HsLua.Core.ClosuresTests import qualified HsLua.Core.ErrorTests +import qualified HsLua.Core.PackageTests +import qualified HsLua.Core.PrimaryTests import qualified HsLua.Core.RunTests +import qualified HsLua.Core.TraceTests import qualified HsLua.Core.UnsafeTests import qualified HsLua.Core.UserdataTests import qualified Foreign.Marshal as Foreign @@ -443,7 +447,11 @@ res <- run @Lua.Exception luaOp assertEqual "error handling leaks values to the stack" 0 res + , HsLua.Core.PrimaryTests.tests + , HsLua.Core.ClosuresTests.tests + , HsLua.Core.PackageTests.tests , HsLua.Core.RunTests.tests + , HsLua.Core.TraceTests.tests , HsLua.Core.UnsafeTests.tests , HsLua.Core.UserdataTests.tests ] diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/hslua-core-2.0.0.2/test/Test/HsLua/Arbitrary.hs new/hslua-core-2.1.0/test/Test/HsLua/Arbitrary.hs --- old/hslua-core-2.0.0.2/test/Test/HsLua/Arbitrary.hs 2001-09-09 03:46:40.000000000 +0200 +++ new/hslua-core-2.1.0/test/Test/HsLua/Arbitrary.hs 2001-09-09 03:46:40.000000000 +0200 @@ -2,7 +2,7 @@ {-# OPTIONS_GHC -fno-warn-orphans #-} {-| Module : HsLua.Core.RunTests -Copyright : ?? 2017-2021 Albert Krewinkel +Copyright : ?? 2017-2022 Albert Krewinkel License : MIT Maintainer : Albert Krewinkel <[email protected]> diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/hslua-core-2.0.0.2/test/Test/Tasty/HsLua.hs new/hslua-core-2.1.0/test/Test/Tasty/HsLua.hs --- old/hslua-core-2.0.0.2/test/Test/Tasty/HsLua.hs 2001-09-09 03:46:40.000000000 +0200 +++ new/hslua-core-2.1.0/test/Test/Tasty/HsLua.hs 2001-09-09 03:46:40.000000000 +0200 @@ -1,7 +1,7 @@ {-# LANGUAGE OverloadedStrings #-} {-| Module : Test.Tasty.HsLua -Copyright : ?? 2017-2021 Albert Krewinkel +Copyright : ?? 2017-2022 Albert Krewinkel License : MIT Maintainer : Albert Krewinkel <[email protected]> Stability : beta diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/hslua-core-2.0.0.2/test/test-hslua-core.hs new/hslua-core-2.1.0/test/test-hslua-core.hs --- old/hslua-core-2.0.0.2/test/test-hslua-core.hs 2001-09-09 03:46:40.000000000 +0200 +++ new/hslua-core-2.1.0/test/test-hslua-core.hs 2001-09-09 03:46:40.000000000 +0200 @@ -1,6 +1,6 @@ {-| Module : Main -Copyright : ?? 2017-2021 Albert Krewinkel +Copyright : ?? 2017-2022 Albert Krewinkel License : MIT Maintainer : Albert Krewinkel <[email protected]>
