Skip to content

Commit 65af63b

Browse files
committed
Drop Penlight workarounds not needed with different class layout
1 parent 24f6565 commit 65af63b

File tree

3 files changed

+10
-13
lines changed

3 files changed

+10
-13
lines changed

fluent/_nodes.lua

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,25 +112,22 @@ FTL.Message = class(FluentNode)
112112
FTL.Message._name = "Message"
113113

114114
function FTL.Message:_init (ast, resource)
115-
self.attributes = setmetatable({}, {
116-
map = {}
117-
})
115+
self.attributes = setmetatable({}, { map = {} })
118116
self:super(ast, resource)
119-
-- Penlight bug #307, should be — self:catch(self.get_attribute)
120-
self:catch(function (_, attribute) return self:get_attribute(attribute) end)
117+
self:catch(self.get_attribute)
121118
end
122119

123120
function FTL.Message:set_attribute (attribute)
121+
local attributes = rawget(self, "attributes")
124122
local id = attribute.id.name
125-
local attributes = self.attributes
126123
local map = getmetatable(attributes).map
127124
local k = #attributes + 1
128125
attributes[k] = attribute
129126
map[id] = k
130127
end
131128

132129
function FTL.Message:get_attribute (attribute)
133-
local attributes = self.attributes
130+
local attributes = rawget(self, "attributes") or error ("No attributes")
134131
local map = getmetatable(attributes).map
135132
local k = map[attribute]
136133
return attributes[k]

fluent/init.lua

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ local FluentResource = require("fluent.resource")
99

1010
local FluentBundle = class()
1111
FluentBundle.locales = {}
12+
FluentBundle.locale = "und"
1213

1314
function FluentBundle:_init (locale)
1415
self:set_locale(locale)
15-
-- Penlight bug #307, should be — self:catch(self.get_message)
16-
self:catch(function(_, identifier) return self:get_message(identifier) end)
16+
self:catch(self.get_message)
1717
end
1818

1919
function FluentBundle:set_locale (locale)
@@ -24,9 +24,10 @@ function FluentBundle:set_locale (locale)
2424
end
2525

2626
function FluentBundle:get_message (identifier)
27-
local locales = rawget(self, "locales")
27+
local locales = self.locales
28+
local locale = self.locale
29+
local resource = locales[locale]
2830
-- TODO iterate over fallback locales if not found in current one
29-
local resource = rawget(locales, self.locale)
3031
return resource:get_message(identifier) or nil
3132
end
3233

fluent/resource.lua

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ function FluentResource:_init (ast)
4242
end
4343
end
4444
flush()
45-
-- Penlight bug #307, should be — self:catch(self.get_message)
46-
self:catch(function (_, identifier) return self:get_message(identifier) end)
45+
self:catch(self.get_message)
4746
end
4847

4948
function FluentResource:load_node (node)

0 commit comments

Comments
 (0)