Use builtin version when available

This commit is contained in:
Danielv123 committed 2024-12-01 09:14:04 +00:00
1 parent 85cdbb1185
commit 54411bc327
1 file changed
+14 -11
+14 -11
View File
@@ -146,18 +146,21 @@ end
--- Select the appropriate polyfill implementation --- Select the appropriate polyfill implementation
if major_v1_1 then if major_v1_1 then
-- Game is not always available so it needs to be called within another function compat.table_to_json = function(tbl)
-- Can not use ... here because of luals type suggestion breaking when it is used if game then
-- TODO maybe include a version that does not require game? compat.table_to_json = game.table_to_json
return game.table_to_json(tbl)
if game ~= nil then end
compat.table_to_json = function(tbl) return game.table_to_json(tbl) end return json.encode(tbl)
compat.json_to_table = function(json) return game.json_to_table(json) end
compat.write_file = function(filename, data, append, for_player) return game.write_file(filename, data, append, for_player) end
else
compat.table_to_json = json.encode
compat.json_to_table = json.decode
end end
compat.json_to_table = function(json)
if game then
compat.json_to_table = game.json_to_table
return game.json_to_table(json)
end
return json.decode(json)
end
compat.write_file = function(filename, data, append, for_player) return game.write_file(filename, data, append, for_player) end
elseif major_v2 then elseif major_v2 then
compat.table_to_json = helpers.table_to_json compat.table_to_json = helpers.table_to_json
compat.json_to_table = helpers.json_to_table compat.json_to_table = helpers.json_to_table