lua 2.2.1 → 2.3.0
raw patch · 21 files changed
+305/−43 lines, 21 filesdep ~basePVP ok
version bump matches the API change (PVP)
Dependency ranges changed: base
API changes (from Hackage documentation)
+ Lua: hsluaL_setwarnf :: State -> IO ()
+ Lua: pattern LUA_COPYRIGHT :: String
+ Lua: pattern LUA_RELEASE :: String
+ Lua: pattern LUA_VERSION :: String
+ Lua.Constants: pattern LUA_COPYRIGHT :: String
+ Lua.Constants: pattern LUA_RELEASE :: String
+ Lua.Constants: pattern LUA_VERSION :: String
+ Lua.Types: type PreWarnFunction = Ptr () -> CString -> LuaBool -> IO ()
+ Lua.Warn: hsluaL_setwarnf :: State -> IO ()
Files
- CHANGELOG.md +22/−0
- LICENSE +1/−1
- README.md +2/−2
- cbits/hslua/hslwarn.c +157/−0
- lua.cabal +19/−8
- src/Lua.hs +10/−2
- src/Lua/Auxiliary.hs +2/−2
- src/Lua/Call.hs +2/−2
- src/Lua/Constants.hsc +31/−4
- src/Lua/Ersatz.hs +2/−2
- src/Lua/Ersatz/Auxiliary.hs +2/−2
- src/Lua/Ersatz/Functions.hs +2/−2
- src/Lua/Lib.hs +2/−2
- src/Lua/Primary.hs +2/−2
- src/Lua/Types.hsc +9/−2
- src/Lua/Userdata.hs +2/−2
- src/Lua/Warn.hs +28/−0
- test/Lua/ErsatzTests.hs +2/−2
- test/Lua/PrimaryTests.hs +2/−2
- test/Lua/UnsafeTests.hs +2/−2
- test/test-lua.hs +4/−2
CHANGELOG.md view
@@ -2,6 +2,28 @@ `lua` uses [PVP Versioning][]. +## lua-2.3.0++Released 2023-03-13.++- New function `hslua_setwarnf`: The function allows to set a+ C function as a hook that is called on all complete warning+ messages. It is intended as a simple way to set a custom+ warning function.++- Export version and copyright info from Lua.Constants: the+ following patterns are made available, with content identical+ to that of the respective C functions: `LUA_VERSION`,+ `LUA_RELEASE`, and `LUA_COPYRIGHT`.++- Added a new flag `cross-compile`. When enabled, the code is+ setup in a way that allows cross-compilation of the package,+ but some of the string constants will be hard-coded and may+ not match the Lua version against which the library is+ compiled.++- `Type` is now an instance of `Read`.+ ## lua-2.2.1 Released 2022-06-19.
LICENSE view
@@ -1,7 +1,7 @@ Copyright © 1994-2022 Lua.org, PUC-Rio. Copyright © 2007-2012 Gracjan Polak Copyright © 2012-2015 Ömer Sinan Ağacan-Copyright © 2016-2022 Albert Krewinkel+Copyright © 2016-2023 Albert Krewinkel Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the
README.md view
@@ -24,8 +24,8 @@ enable coders to embed the language into their programs, making them scriptable. -*Lua* ships with the official Lua interpreter, version 5.4.2.-Cabal flags allow to compile against a system-wide Lua+This package ships with the official Lua interpreter, version+5.4.4. Cabal flags allow to compile against a system-wide Lua installation instead, if desired. Build flags
+ cbits/hslua/hslwarn.c view
@@ -0,0 +1,157 @@+/*+** Large parts of the below code are adapted from the default warning+** functions defined in lauxlib.c.+**+** See Copyright Notice in lua.h+*/++#include <stdio.h>+#include <stdlib.h>+#include <string.h>++#include "lua.h"+#include "lauxlib.h"++#define HSLUA_RFLD_WARNF "HsLua warn hook"+#define HSLUA_RFLD_WARNINGS "HsLua warnings"++/* print an error message */+#if !defined(lua_writestringerror)+#define lua_writestringerror(s,p) \+ (fprintf(stderr, (s), (p)), fflush(stderr))+#endif++/*+** Initializes the warnings table.+*/+static void reset_warnings (lua_State *L) {+ lua_createtable(L, 1, 0);+ lua_setfield(L, LUA_REGISTRYINDEX, HSLUA_RFLD_WARNINGS);+}++/*+** Stores the warning in the registry.+*/+static void store_warning (lua_State *L, const char *message) {+ if (lua_getfield(L, LUA_REGISTRYINDEX, HSLUA_RFLD_WARNINGS) != LUA_TTABLE) {+ return;+ }+ lua_pushstring(L, message);+ lua_seti(L, -2, luaL_len(L, -2) + 1); /* append message */+ lua_pop(L, 1); /* messages table */+}++/* Concatenates all collected warnings and pushes the result to the stack. */+static void pushwarning (lua_State *L) {+ if (lua_getfield(L, LUA_REGISTRYINDEX, HSLUA_RFLD_WARNINGS) != LUA_TTABLE) {+ lua_pushliteral(L, "");+ return;+ }++ int tblidx = lua_absindex(L, -1);+ lua_Integer last = luaL_len(L, tblidx);+ luaL_Buffer b;+ luaL_buffinit(L, &b);+ for (int i = 1; i <= last; i++) {+ if (lua_geti(L, tblidx, i) != LUA_TSTRING) {+ /* not a string; skip it silently */+ lua_pop(L, 1);+ } else {+ luaL_addvalue(&b);+ }+ }+ lua_remove(L, -2); /* warnings table */+ luaL_pushresult(&b);+}++static void call_warn_hook (lua_State *L) {+ if (lua_getfield(L, LUA_REGISTRYINDEX, HSLUA_RFLD_WARNF) == LUA_TFUNCTION) {+ pushwarning(L);+ lua_call(L, 1, 0);+ }+}++/*+** Warning functions:+** warnfoff: warning system is off+** warnfon: ready to start a new message+** warnfcont: previous message is to be continued+*/+static void warnfoff (void *ud, const char *message, int tocont);+static void warnfon (void *ud, const char *message, int tocont);+static void warnfcont (void *ud, const char *message, int tocont);++/*+** Check whether message is a control message. If so, execute the+** control or ignore it if unknown.+*/+static int checkcontrol (lua_State *L, const char *message, int tocont) {+ if (tocont || *(message++) != '@') /* not a control message? */+ return 0;+ else {+ if (strcmp(message, "off") == 0)+ lua_setwarnf(L, warnfoff, L); /* turn warnings off */+ else if (strcmp(message, "on") == 0)+ lua_setwarnf(L, warnfon, L); /* turn warnings on */+ return 1; /* it was a control message */+ }+}++/*+** Does not write the warning to stderr, but still records the message+** so it can be processed by the custom hook.+*/+static void warnfoff (void *ud, const char *message, int tocont) {+ lua_State *L = (lua_State *)ud;+ if (checkcontrol(L, message, tocont)) {+ return; /* nothing else to be done */+ }+ store_warning(L, message);+ if (!tocont) { /* last part */+ call_warn_hook(L); /* call the warnings hook */+ reset_warnings(L); /* reset warnings table */+ }+}+++/*+** Writes the message and handle 'tocont', finishing the message+** if needed and setting the next warn function.+*/+static void warnfcont (void *ud, const char *message, int tocont) {+ lua_State *L = (lua_State *)ud;+ lua_writestringerror("%s", message); /* write message */+ store_warning(L, message);+ if (tocont) /* not the last part? */+ lua_setwarnf(L, warnfcont, L); /* to be continued */+ else { /* last part */+ lua_writestringerror("%s", "\n"); /* finish message with end-of-line */+ lua_setwarnf(L, warnfon, L); /* next call is a new message */+ call_warn_hook(L); /* call the warnings hook */+ reset_warnings(L); /* reset warnings table */+ }+}++/*+** Records a warning, and writes a warning prefix followed by the+** warning to stderr.+*/+static void warnfon (void *ud, const char *message, int tocont) {+ lua_State *L = (lua_State *)ud;+ if (checkcontrol(L, message, tocont)) /* control message? */+ return; /* nothing else to be done */+ lua_writestringerror("%s", "Lua warning: "); /* start a new warning */+ warnfcont(ud, message, tocont); /* finish processing */+}+++/*+** Sets the object at the top of the stack as the function that is+** called on the concatenated warning messages. Pops the function from+** the stack.+*/+void hsluaL_setwarnf (lua_State *L) {+ lua_setfield(L, LUA_REGISTRYINDEX, HSLUA_RFLD_WARNF);+ reset_warnings(L);+ lua_setwarnf(L, warnfoff, L);+}
lua.cabal view
@@ -1,6 +1,6 @@ cabal-version: 2.2 name: lua-version: 2.2.1+version: 2.3.0 synopsis: Lua, an embeddable scripting language description: This package provides bindings and types to bridge Haskell and <https://www.lua.org/ Lua>.@@ -13,24 +13,23 @@ license: MIT license-file: LICENSE author: Albert Krewinkel-maintainer: Albert Krewinkel <albert+hslua@zeitkraut.de>+maintainer: Albert Krewinkel <tarleb@hslua.org> copyright: © 2007–2012 Gracjan Polak; © 2012–2016 Ömer Sinan Ağacan;- © 2017-2022 Albert Krewinkel+ © 2017-2023 Albert Krewinkel category: Foreign build-type: Simple extra-source-files: cbits/lua-5.4.4/*.h , cbits/hslua/*.h , README.md , CHANGELOG.md-tested-with: GHC == 8.0.2- , GHC == 8.2.2- , GHC == 8.4.4+tested-with: GHC == 8.4.4 , GHC == 8.6.5 , GHC == 8.8.4 , GHC == 8.10.7 , GHC == 9.0.2- , GHC == 9.2.3+ , GHC == 9.2.5+ , GHC == 9.4.4 source-repository head type: git@@ -75,9 +74,16 @@ description: Use @pkg-config@ to discover library and include paths. Setting this flag implies `system-lua`. +flag cross-compile+ default: False+ manual: True+ description: Avoids constructs that would prevent cross-compilation.+ The Lua version constants may become inaccurate when+ this flag is enabled.+ common common-options default-language: Haskell2010- build-depends: base >= 4.8 && < 5+ build-depends: base >= 4.11 && < 5 ghc-options: -Wall -Wincomplete-record-updates -Wnoncanonical-monad-instances@@ -100,6 +106,9 @@ if flag(allow-unsafe-gc) cpp-options: -DALLOW_UNSAFE_GC + if flag(cross-compile)+ cpp-options: -D_LUA_NO_CONST_STR+ library import: common-options exposed-modules: Lua@@ -113,6 +122,7 @@ , Lua.Primary , Lua.Types , Lua.Userdata+ , Lua.Warn hs-source-dirs: src default-extensions: CApiFFI , ForeignFunctionInterface@@ -126,6 +136,7 @@ , cbits/hslua/hslcall.c , cbits/hslua/hslauxlib.c , cbits/hslua/hslua.c+ , cbits/hslua/hslwarn.c include-dirs: cbits/hslua includes: lua.h , luaconf.h
src/Lua.hs view
@@ -2,9 +2,9 @@ {-# LANGUAGE PatternSynonyms #-} {-| Module : Lua-Copyright : © 2021-2022 Albert Krewinkel+Copyright : © 2021-2023 Albert Krewinkel License : MIT-Maintainer : Albert Krewinkel <tarleb+hslua@zeitkraut.de>+Maintainer : Albert Krewinkel <tarleb@hslua.org> Stability : beta Portability : portable @@ -241,6 +241,8 @@ , hslua_concat , hslua_arith , hslua_compare+ -- ** Simplified warnings handling+ , hsluaL_setwarnf -- * Standard Lua libraries , luaopen_base@@ -254,6 +256,11 @@ -- * Push Haskell functions , hslua_pushhsfunction++ -- * Version and copyright info+ , pattern LUA_VERSION+ , pattern LUA_RELEASE+ , pattern LUA_COPYRIGHT ) where import Foreign.C (CInt)@@ -265,6 +272,7 @@ import Lua.Lib import Lua.Primary import Lua.Types as Lua+import Lua.Warn -- | Runs operations on a new Lua @'Lua.State'@. The state is created -- when the function is called and closed on return. The state, and all
src/Lua/Auxiliary.hs view
@@ -3,9 +3,9 @@ Module : Lua.Auxiliary Copyright : © 2007–2012 Gracjan Polak; © 2012–2016 Ömer Sinan Ağacan;- © 2017-2022 Albert Krewinkel+ © 2017-2023 Albert Krewinkel License : MIT-Maintainer : Albert Krewinkel <tarleb+hslua@zeitkraut.de>+Maintainer : Albert Krewinkel <tarleb@hslua.org> Stability : beta Portability : non-portable (depends on GHC)
src/Lua/Call.hs view
@@ -3,9 +3,9 @@ Module : Lua.Call Copyright : © 2007–2012 Gracjan Polak; © 2012–2016 Ömer Sinan Ağacan;- © 2017-2022 Albert Krewinkel+ © 2017-2023 Albert Krewinkel License : MIT-Maintainer : Albert Krewinkel <tarleb+hslua@zeitkraut.de>+Maintainer : Albert Krewinkel <tarleb@hslua.org> Stability : beta Portability : non-portable (depends on GHC)
src/Lua/Constants.hsc view
@@ -3,17 +3,21 @@ Module : Lua.Constants Copyright : © 2007–2012 Gracjan Polak; © 2012–2016 Ömer Sinan Ağacan;- © 2017-2022 Albert Krewinkel+ © 2017-2023 Albert Krewinkel License : MIT-Maintainer : Albert Krewinkel <tarleb+hslua@zeitkraut.de>+Maintainer : Albert Krewinkel <tarleb@hslua.org> Stability : beta Portability : ForeignFunctionInterface Lua constants -} module Lua.Constants- ( -- * Special values- pattern LUA_MULTRET+ ( -- * Version and copyright information+ pattern LUA_VERSION+ , pattern LUA_RELEASE+ , pattern LUA_COPYRIGHT+ -- * Special values+ , pattern LUA_MULTRET -- * Pseudo-indices , pattern LUA_REGISTRYINDEX -- * Basic types@@ -79,6 +83,29 @@ #include <lua.h> #include <lauxlib.h>++--+-- Version and copyright info+--++-- | Lua version information in the form "@Lua MAJOR.MINOR@".+pattern LUA_VERSION :: String++-- | Lua version information in the form "@Lua MAJOR.MINOR.RELEASE@".+pattern LUA_RELEASE :: String++-- | Lua copyright information; includes the Lua release+pattern LUA_COPYRIGHT :: String++#ifdef _LUA_NO_CONST_STR+pattern LUA_VERSION = "Lua 5.4"+pattern LUA_RELEASE = "Lua 5.4.4"+pattern LUA_COPYRIGHT = "Lua 5.4.4 Copyright (C) 1994-2022 Lua.org, PUC-Rio"+#else+pattern LUA_RELEASE = #{const_str LUA_RELEASE}+pattern LUA_VERSION = #{const_str LUA_VERSION}+pattern LUA_COPYRIGHT = #{const_str LUA_COPYRIGHT}+#endif -- -- Special values
src/Lua/Ersatz.hs view
@@ -2,9 +2,9 @@ Module : Lua.Ersatz Copyright : © 2007–2012 Gracjan Polak; © 2012–2016 Ömer Sinan Ağacan;- © 2017-2022 Albert Krewinkel+ © 2017-2023 Albert Krewinkel License : MIT-Maintainer : Albert Krewinkel <tarleb+hslua@zeitkraut.de>+Maintainer : Albert Krewinkel <tarleb@hslua.org> Stability : beta Ersatz functions for Lua API items which may, directly or indirectly,
src/Lua/Ersatz/Auxiliary.hs view
@@ -2,9 +2,9 @@ Module : Lua.Ersatz.Auxiliary Copyright : © 2007–2012 Gracjan Polak; © 2012–2016 Ömer Sinan Ağacan;- © 2017-2022 Albert Krewinkel+ © 2017-2023 Albert Krewinkel License : MIT-Maintainer : Albert Krewinkel <tarleb+hslua@zeitkraut.de>+Maintainer : Albert Krewinkel <tarleb@hslua.org> Stability : beta Portability : non-portable (depends on GHC)
src/Lua/Ersatz/Functions.hs view
@@ -3,9 +3,9 @@ Module : Lua.Ersatz.Functions Copyright : © 2007–2012 Gracjan Polak; © 2012–2016 Ömer Sinan Ağacan;- © 2017-2022 Albert Krewinkel+ © 2017-2023 Albert Krewinkel License : MIT-Maintainer : Albert Krewinkel <tarleb+hslua@zeitkraut.de>+Maintainer : Albert Krewinkel <tarleb@hslua.org> Stability : beta Portability : ForeignFunctionInterface, CPP
src/Lua/Lib.hs view
@@ -2,9 +2,9 @@ Module : Lua.Lib Copyright : © 2007–2012 Gracjan Polak; © 2012–2016 Ömer Sinan Ağacan;- © 2017-2022 Albert Krewinkel+ © 2017-2023 Albert Krewinkel License : MIT-Maintainer : Albert Krewinkel <tarleb+hslua@zeitkraut.de>+Maintainer : Albert Krewinkel <tarleb@hslua.org> Stability : beta Portability : ForeignFunctionInterface, CPP
src/Lua/Primary.hs view
@@ -3,9 +3,9 @@ Module : Lua.Primary Copyright : © 2007–2012 Gracjan Polak; © 2012–2016 Ömer Sinan Ağacan;- © 2017-2022 Albert Krewinkel+ © 2017-2023 Albert Krewinkel License : MIT-Maintainer : Albert Krewinkel <tarleb+hslua@zeitkraut.de>+Maintainer : Albert Krewinkel <tarleb@hslua.org> Stability : beta Portability : ForeignFunctionInterface, CPP
src/Lua/Types.hsc view
@@ -5,9 +5,9 @@ Module : Lua.Types Copyright : © 2007–2012 Gracjan Polak; © 2012–2016 Ömer Sinan Ağacan;- © 2017-2022 Albert Krewinkel+ © 2017-2023 Albert Krewinkel License : MIT-Maintainer : Albert Krewinkel <tarleb+hslua@zeitkraut.de>+Maintainer : Albert Krewinkel <tarleb@hslua.org> Stability : beta Portability : non-portable (depends on GHC) @@ -20,6 +20,7 @@ , CFunction , PreCFunction , WarnFunction+ , PreWarnFunction , LuaBool (..) , Integer (..) , Number (..)@@ -100,6 +101,12 @@ -- See <https://www.lua.org/manual/5.4/manual.html#pdf-warn warn> for -- more details about warnings. type WarnFunction = FunPtr (Ptr () -> CString -> LuaBool -> IO ())++-- | Type of Haskell functions that can be turned into a WarnFunction.+--+-- This is the same as a dereferenced 'WarnFunction'.+type PreWarnFunction = Ptr () -> CString -> LuaBool -> IO ()+ -- | The type of integers in Lua. --
src/Lua/Userdata.hs view
@@ -1,9 +1,9 @@ {-# LANGUAGE CPP #-} {-| Module : Lua.Userdata-Copyright : © 2017-2022 Albert Krewinkel+Copyright : © 2017-2023 Albert Krewinkel License : MIT-Maintainer : Albert Krewinkel <tarleb+hslua@zeitkraut.de>+Maintainer : Albert Krewinkel <tarleb@hslua.org> Stability : beta Portability : ForeignFunctionInterface
+ src/Lua/Warn.hs view
@@ -0,0 +1,28 @@+{-# LANGUAGE CPP #-}+{-|+Module : Lua.Warn+Copyright : © 2023 Albert Krewinkel+License : MIT+Maintainer : Albert Krewinkel <tarleb@hslua.org>++Simpler interface to the Lua warnings system.+-}+module Lua.Warn+ ( hsluaL_setwarnf+ ) where++import Lua.Types (State (State))++-- | Sets a warning function. This is a simplified version of+-- 'Lua.Primary.lua_setwarnf'. The function at the top of the stack is+-- set as the "warning hook", i.e., it is called with the concatenated+-- warning components as the single argument.+--+-- The hook function is popped of the stack.+--+-- The control messages @\@on@ and @\@off@ are still supported; as with+-- the default warning function, these commands can switch error+-- reporting to stderr on and off. The given Haskell function will be+-- called in either case, even when the error is not written to stderr.+foreign import ccall "hslwarn.c hsluaL_setwarnf"+ hsluaL_setwarnf :: State -> IO ()
test/Lua/ErsatzTests.hs view
@@ -1,8 +1,8 @@ {-| Module : Lua.ErsatzTests-Copyright : © 2021-2022 Albert Krewinkel+Copyright : © 2021-2023 Albert Krewinkel License : MIT-Maintainer : Albert Krewinkel <tarleb+hslua@zeitkraut.de>+Maintainer : Albert Krewinkel <tarleb@hslua.org> Stability : beta Tests for Lua bindings.
test/Lua/PrimaryTests.hs view
@@ -2,9 +2,9 @@ {-# OPTIONS_GHC -Wno-unused-do-bind #-} {-| Module : Lua.PrimaryTests-Copyright : © 2021-2022 Albert Krewinkel+Copyright : © 2021-2023 Albert Krewinkel License : MIT-Maintainer : Albert Krewinkel <tarleb+hslua@zeitkraut.de>+Maintainer : Albert Krewinkel <tarleb@hslua.org> Tests for bindings to primary API functions. -}
test/Lua/UnsafeTests.hs view
@@ -2,9 +2,9 @@ {-# OPTIONS_GHC -Wno-unused-do-bind #-} {-| Module : Lua.UnsafeTests-Copyright : © 2021-2022 Albert Krewinkel+Copyright : © 2021-2023 Albert Krewinkel License : MIT-Maintainer : Albert Krewinkel <tarleb+hslua@zeitkraut.de>+Maintainer : Albert Krewinkel <tarleb@hslua.org> Stability : beta Tests for bindings to unsafe functions.
test/test-lua.hs view
@@ -2,9 +2,9 @@ {-# LANGUAGE CPP #-} {-| Module : Main-Copyright : © 2021-2022 Albert Krewinkel+Copyright : © 2021-2023 Albert Krewinkel License : MIT-Maintainer : Albert Krewinkel <tarleb+hslua@zeitkraut.de>+Maintainer : Albert Krewinkel <tarleb@hslua.org> Stability : beta Tests for the raw Lua bindings.@@ -191,6 +191,8 @@ ("_LOADED" @=? loadedTableRegistryField) , "preloadTableRegistryField" =: ("_PRELOAD" @=? preloadTableRegistryField)+ , "LUA_VERSION" =:+ ("Lua 5.4" @=? LUA_VERSION) ] , testGroup "compare"