Skip to content

Commit

Permalink
feat(locals_access): add a function to get a list of all locals (#3031)
Browse files Browse the repository at this point in the history
This is useful for things like profiling all functions within a widget,
or otherwise inspecting the internal state of a widget when its
structure isn't known ahead of time.
  • Loading branch information
salinecitrine committed May 18, 2024
1 parent e1cbe10 commit 58841a7
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions common/testing/locals_access.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,25 @@ return __locals

local function generateLocalsAccessStr(localsNames)
local content = "\n__localsAccess = {\n"

content = content .. " getters = {\n"
for _, name in ipairs(localsNames) do
content = content .. " " .. name .. " = function() return " .. name .. " end,\n"
end
content = content .. " },\n"

content = content .. " setters = {\n"
for _, name in ipairs(localsNames) do
content = content .. " " .. name .. " = function(__value) " .. name .. " = __value end,\n"
end
content = content .. " },\n"

content = content .. " getAllLocals = function() return {\n"
for _, name in ipairs(localsNames) do
content = content .. " \"" .. name .. "\",\n"
end
content = content .. " } end,\n"

content = content .. "}\n"
return content
end
Expand Down

0 comments on commit 58841a7

Please sign in to comment.