aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHisham Muhammad <--unset>2026-02-01 17:31:55 -0300
committerHisham Muhammad <--unset>2026-02-01 17:31:55 -0300
commitbb24943ca32db3a901a837468f104dea78c9271c (patch)
tree84de7868f4e8726ebdf0e0dd61cc6a7998b41bee
parentdfd83b4930c8b85fd39d208523f7293cf469b205 (diff)
downloadlua-compat-5.3-bb24943ca32db3a901a837468f104dea78c9271c.tar.gz
lua-compat-5.3-bb24943ca32db3a901a837468f104dea78c9271c.tar.bz2
lua-compat-5.3-bb24943ca32db3a901a837468f104dea78c9271c.zip
Improve compatibility with FILE* metatype on LuaJIT
Fixes #70.
-rw-r--r--compat53/module.lua15
1 files changed, 14 insertions, 1 deletions
diff --git a/compat53/module.lua b/compat53/module.lua
index 52b1dd6..6133a34 100644
--- a/compat53/module.lua
+++ b/compat53/module.lua
@@ -826,7 +826,20 @@ if lua_version < "5.3" then
826 end 826 end
827 end -- not luajit 827 end -- not luajit
828 828
829 if is_luajit then 829 local is_full_compat = package.loaded["compat53"] or package.loaded["compat53.init"]
830
831 -- When using the full `compat53.init` module, we override the global state, so
832 -- we can patch the FILE metatable. When using `compat53.module` on its own, however,
833 -- we have to choose between being compatible with the Lua 5.3 API of the file metamethods,
834 -- or with the pointer identity of the original LuaJIT metatable in the C API (see issue #70).
835 -- We default to be Lua 5.3 API compatible, but we offer the user a choice to override this
836 -- by setting a special global `LUA_COMPAT53_NO_FILE_META_OVERRIDE` to `true`, prior to
837 -- requiring `compat53.module`.
838 local use_modular_compat_file_meta = is_luajit
839 and not is_full_compat
840 and not _G.LUA_COMPAT53_NO_FILE_META_OVERRIDE
841
842 if use_modular_compat_file_meta then
830 local compat_file_meta = {} 843 local compat_file_meta = {}
831 local compat_file_meta_loaded = 0 844 local compat_file_meta_loaded = 0
832 845