From 91af3b73d20fbc1102ba9c455c2cbb4cff2ceb1f Mon Sep 17 00:00:00 2001 From: Jean-Patrick Guerrero Date: Mon, 29 Nov 2021 15:51:12 +0100 Subject: [PATCH] More cleaning --- README.md | 2 +- src/operators.lua | 12 +++++++----- tests/test_operators.lua | 22 +++++++++++----------- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index c691510..4e8ec82 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # i3 -[![MIT License](https://img.shields.io/apm/l/atomic-design-ui.svg?)](https://github.com/tterb/atomic-design-ui/blob/master/LICENSEs) ![workflow](https://github.com/minetest-mods/i3/actions/workflows/luacheck.yml/badge.svg) [![GitHub Release](https://img.shields.io/github/release/minetest-mods/i3.svg?style=flat)]() [![ContentDB](https://content.minetest.net/packages/jp/i3/shields/downloads/)](https://content.minetest.net/packages/jp/i3/) [![PayPal](https://img.shields.io/badge/paypal-donate-yellow.svg)](https://www.paypal.me/jpg84240) +[![MIT License](https://img.shields.io/apm/l/atomic-design-ui.svg?)](https://github.com/tterb/atomic-design-ui/blob/master/LICENSEs) [![GitHub Release](https://img.shields.io/github/release/minetest-mods/i3.svg?style=flat)]() [![ContentDB](https://content.minetest.net/packages/jp/i3/shields/downloads/)](https://content.minetest.net/packages/jp/i3/) [![PayPal](https://img.shields.io/badge/paypal-donate-yellow.svg)](https://www.paypal.me/jpg84240) #### **`i3`** is a next-generation inventory for Minetest. diff --git a/src/operators.lua b/src/operators.lua index 06e9448..3320fea 100644 --- a/src/operators.lua +++ b/src/operators.lua @@ -43,11 +43,13 @@ local function compile(data) return data end -local function _load(path, line, data) +local function _load(path, line, data, t) if line then - data = data:split"\n" - data[line] = data[line]:gsub("(" .. var .. "+)%s?=%s?(" .. var .. "*)", function(_,b) return b end) - data = table.concat(data, "\n") + if not t then + t = data:split"\n" + end + t[line] = t[line]:gsub("(" .. var .. "+)%s?=%s?(" .. var .. "*)", "%2") + data = table.concat(t, "\n") else local file = assert(io.open(path, "r")) data = file:read"*a" @@ -61,7 +63,7 @@ local function _load(path, line, data) local err_line = tonumber(err:match(":(%d+):")) if line ~= err_line then - return _load(path, err_line, data) + return _load(path, err_line, data, t) end end diff --git a/tests/test_operators.lua b/tests/test_operators.lua index dc7981c..aeffc55 100644 --- a/tests/test_operators.lua +++ b/tests/test_operators.lua @@ -1,8 +1,6 @@ local a, b, c = 0, 0, 0 b+=1 c++; local foo = "bar"; -print(c-=1) -print(c++) local t = { a = a++, b = 2, @@ -11,16 +9,18 @@ local t = { e = 1, } t["b"] <<= 4 -print(dump(t)) +t.b >>= 2 +assert(t.b == 8) +--print(dump(t)) --c += 1 c*=2 local i = 16 i += i<<4 -print(i) -- 272 -print(a+=2) -- 2 -print(c++) -- 3 -print(a-=1) -- -1 -print(c^=4) -- 16 -print(a&b) -- 0 -print(c|=a) -- 2 -print(1<<8) -- 256 +assert(i == 272) +assert((a+=2) == 2) +assert(c++ == 3) +assert((a-=1) == -1) +assert((c^=4) == 16) +assert((a&b) == 0) +assert((c|=a) == 2) +assert((1<<8) == 256)