From 44ad494d99d20f759c52f15d9d69855d9951c813 Mon Sep 17 00:00:00 2001 From: Lars Mueller Date: Thu, 22 Apr 2021 11:54:25 +0200 Subject: [PATCH] Lua log files: Fix infinities --- persistence.lua | 3 ++- test.lua | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/persistence.lua b/persistence.lua index 15512f7..2a23886 100644 --- a/persistence.lua +++ b/persistence.lua @@ -13,7 +13,8 @@ end function lua_log_file:load() -- Bytecode is blocked by the engine local read = assert(loadfile(self.file_path)) - local env = {} + -- math.huge is serialized to inf + local env = {inf = math.huge} setfenv(read, env) read() env.R = env.R or {{}} diff --git a/test.lua b/test.lua index f158540..00a3cc7 100644 --- a/test.lua +++ b/test.lua @@ -196,10 +196,10 @@ local logfile = persistence.lua_log_file.new(mod.get_resource"logfile.test.lua", logfile:init() logfile.root = {} logfile:rewrite() -logfile:set_root({a = 1}, {b = 2, c = 3}) +logfile:set_root({a = 1}, {b = 2, c = 3, d = _G.math.huge, e = -_G.math.huge}) logfile:close() logfile:init() -assert(table.equals(logfile.root, {[{a = 1}] = {b = 2, c = 3}})) +assert(table.equals(logfile.root, {[{a = 1}] = {b = 2, c = 3, d = _G.math.huge, e = -_G.math.huge}})) -- in-game tests & b3d testing local tests = {