Skip to content

Commit

Permalink
Use fusion.util.unpack instead of a ternary
Browse files Browse the repository at this point in the history
Files changed:
- fusion/core/compilers/source.lua
- fusion/stdlib/functiona.lua
- fusion/stdlib/iterable.lua
- fusion/stdlib/table.lua
- spec/class_spec.lua
  • Loading branch information
RyanSquared committed Jun 8, 2017
1 parent 8e69ba9 commit b86ccd5
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 18 deletions.
26 changes: 13 additions & 13 deletions fusion/core/compilers/source.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@

local parser = require("fusion.core.parser")
local lfs = require("lfs")
local unpack = unpack or table.unpack -- luacheck: ignore 113 143
local unpack = require("fusion.util").unpack

local compiler = {}
local handlers = {}

--- Initialize a compiler state
function compiler:new()
self = setmetatable({}, {__index = compiler})
self.indent = 0
self.last_node = {}
return self
function compiler:new() -- luacheck: ignore 212
local new_self = setmetatable({}, {__index = compiler})
new_self.indent = 0
new_self.last_node = {}
return new_self
end

--- Transform a node using the registered handler.
Expand Down Expand Up @@ -110,7 +110,7 @@ function compiler:transform_class_function(node)
}
end

handlers['re'] = function(self, node)
handlers['re'] = function(self, node) -- luacheck: ignore 212
return 're.compile(' .. ("%q"):format(node[1]) .. ')'
end

Expand Down Expand Up @@ -222,11 +222,11 @@ handlers['table'] = function(self, node)
return table.concat(output, "\n")
end

handlers['boolean'] = function(self, node)
handlers['boolean'] = function(self, node) -- luacheck: ignore 212
return tostring(node[1])
end

handlers['break'] = function(self, node)
handlers['break'] = function(self, node) -- luacheck: ignore 212
return node.type
end

Expand Down Expand Up @@ -464,7 +464,7 @@ handlers['expression'] = function(self, node)
end
end

handlers['number'] = function(self, node)
handlers['number'] = function(self, node) -- luacheck: ignore 212
local is_negative = node.is_negative and "-" or ""
if node.base == "10" then
if math.floor(node[1]) == node[1] then
Expand Down Expand Up @@ -593,15 +593,15 @@ handlers['variable'] = function(self, node)
return table.concat(name)
end

handlers['sqstring'] = function(self, node)
handlers['sqstring'] = function(self, node) -- luacheck: ignore 212
return ("%q"):format(node[1]:gsub("\\", "\\\\")) -- \ is ignored in '' strings
end

handlers['dqstring'] = function(self, node)
handlers['dqstring'] = function(self, node) -- luacheck: ignore 212
return ('"%s"'):format(node[1])
end

handlers['blstring'] = function(self, node)
handlers['blstring'] = function(self, node) -- luacheck: ignore 212
local eq = ("="):rep(#node.eq)
return ("[%s[%s]%s]"):format(eq, node[1], eq)
end
Expand Down
2 changes: 1 addition & 1 deletion fusion/stdlib/functional.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
--- Module for "functional" iterators and functions.
-- @module fusion.stdlib.functional
local unpack = unpack or table.unpack -- luacheck: ignore 113 143
local unpack = require("fusion.util").unpack

--- Iterate over a table's keys and values
-- @tparam table input
Expand Down
3 changes: 1 addition & 2 deletions fusion/stdlib/iterable.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
-- @module fusion.stdlib.iterative
local fnl = require("fusion.stdlib.functional")
local table = require("fusion.stdlib.table")

local unpack = unpack or table.unpack -- luacheck: ignore 113
local unpack = require("fusion.util").unpack

local iter, mk_gen = fnl._iter, fnl._mk_gen

Expand Down
2 changes: 1 addition & 1 deletion fusion/stdlib/table.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ function table.slice(t, start, stop)
end)
end

table.unpack = unpack or table.unpack -- luacheck: ignore 113 143
table.unpack = require("fusion.util").unpack

return table
2 changes: 1 addition & 1 deletion spec/class_spec.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
local class = require("fusion.stdlib.class")
local unpack = require("fusion.util").unpack

local unpack = unpack or table.unpack -- luacheck: ignore 113 143
describe("class", function()
it("can make a simple class", function()
local x = class({}, {}, "Test")
Expand Down

0 comments on commit b86ccd5

Please sign in to comment.