diff options
author | Nat Goodspeed <nat@lindenlab.com> | 2024-09-04 09:15:10 -0400 |
---|---|---|
committer | Nat Goodspeed <nat@lindenlab.com> | 2024-09-04 09:15:10 -0400 |
commit | d67ad5da3b5a37f7b4cb78e686ae36f31c513153 (patch) | |
tree | 5175159479d797101bfebd738d9c55d0f5b457f2 /indra | |
parent | 35c3f0227c334e059abdc36c36cc942a517d92ec (diff) |
`result_view()`'s table's `close()` method need not be further wrapped.
`LL.setdtor(desc, table, func)` eventually calls `func(table)`. So the
`close()` method on the table returned by `result_view()` can be directly
passed to `setdtor()`, instead of wrapped in a new anonymous function whose
only job is to pass the table to it.
Moreover, there's no need for the table returned by LLInventory.lua's
`result()` function to lazily instantiate the `result_view()` for `categories`
or `items`: neither `result_view` will fetch a slice unless asked. Just return
`{categories=result_view(...), items=result_view(...), close=...}`. This
dramatically simplifies the `result()` function.
Since that table also defines a `close()` function, that too can be passed
directly to `setdtor()` without being wrapped in a new anonymous function.
Diffstat (limited to 'indra')
-rw-r--r-- | indra/newview/scripts/lua/require/LLInventory.lua | 52 | ||||
-rw-r--r-- | indra/newview/scripts/lua/require/UI.lua | 5 |
2 files changed, 12 insertions, 45 deletions
diff --git a/indra/newview/scripts/lua/require/LLInventory.lua b/indra/newview/scripts/lua/require/LLInventory.lua index 9cf72a8678..2c80a8602b 100644 --- a/indra/newview/scripts/lua/require/LLInventory.lua +++ b/indra/newview/scripts/lua/require/LLInventory.lua @@ -3,48 +3,18 @@ local mapargs = require 'mapargs' local result_view = require 'result_view' local function result(keys) - return LL.setdtor( - 'LLInventory result', - setmetatable( - -- the basic table wrapped by setmetatable just captures the int - -- result-set {key, length} pairs from 'keys', but with underscore - -- prefixes - { - _categories=keys.categories, - _items=keys.items, - -- call result:close() to release result sets before garbage - -- collection or script completion - close = function(self) - result_view.close(self._categories[1], self._items[1]) - end - }, - -- The caller of one of our methods that returns a result set - -- isn't necessarily interested in both categories and items, so - -- don't proactively populate both. Instead, when caller references - -- either 'categories' or 'items', the __index() metamethod - -- populates that field. - { - __index = function(t, field) - -- we really don't care about references to any other field - if not table.find({'categories', 'items'}, field) then - return nil - end - -- We cleverly saved the result set {key, length} pair in - -- a field with the same name but an underscore prefix. - local view = result_view(t['_' .. field]) - -- cache that view for future reference - t[field] = view - return view - end - } - ), - -- When the table-with-metatable above is destroyed, tell LLInventory - -- we're done with its result sets -- whether or not we ever fetched - -- either of them. - function(res) - res:close() + -- capture result_view() instances for both categories and items + local result_table = { + categories=result_view(keys.categories), + items=result_view(keys.items), + -- call result_table:close() to release result sets before garbage + -- collection or script completion + close = function(self) + result_view.close(keys.categories[1], keys.items[1]) end - ) + } + -- When the result_table is destroyed, close its result_views. + return LL.setdtor('LLInventory result', result_table, result_table.close) end local LLInventory = {} diff --git a/indra/newview/scripts/lua/require/UI.lua b/indra/newview/scripts/lua/require/UI.lua index aa64c0c7f9..73a76fa6b8 100644 --- a/indra/newview/scripts/lua/require/UI.lua +++ b/indra/newview/scripts/lua/require/UI.lua @@ -237,10 +237,7 @@ end function UI.getFloaterNames() local key_length = leap.request("LLFloaterReg", {op = "getFloaterNames"}).floaters local view = result_view(key_length) - return LL.setdtor( - 'registered floater names', - view, - function(self) view:close() end) + return LL.setdtor('registered floater names', view, view.close) end return UI |