Skip to content

Commit bb24943

Browse files
author
Hisham Muhammad
committed
Improve compatibility with FILE* metatype on LuaJIT
Fixes #70.
1 parent dfd83b4 commit bb24943

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

compat53/module.lua

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,20 @@ if lua_version < "5.3" then
826826
end
827827
end -- not luajit
828828

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
830843
local compat_file_meta = {}
831844
local compat_file_meta_loaded = 0
832845

0 commit comments

Comments
 (0)