Add custom operators (Part 2)

This commit is contained in:
Jean-Patrick Guerrero
2021-11-29 02:47:36 +01:00
parent 34548d8509
commit eaf7c486b8
5 changed files with 21 additions and 16 deletions

View File

@ -1,6 +1,5 @@
local fmt = string.format
local _loadfile = loadfile
local var = "[%w%.%[%]_]"
local var = "[%w%.%[%]\"\'_]"
local operators = {
["([%+%-%*%^/&|])="] = function(a, b, c)
@ -26,6 +25,14 @@ local operators = {
[">>"] = function(a, b)
return fmt("bit.rshift(%s, %s)", a, b)
end,
["<<="] = function(a, b)
return fmt("%s = bit.lshift(%s, %s)", a, a, b)
end,
[">>="] = function(a, b)
return fmt("%s = bit.rshift(%s, %s)", a, a, b)
end,
}
local function compile(data)
@ -61,6 +68,6 @@ local function _load(path, line, data)
return l, err
end
function loadfile(path)
return _load(path) or _loadfile(path)
return function(path)
return _load(path) or loadfile(path)
end