Skip to content

Instantly share code, notes, and snippets.

@0riginaln0
Created January 31, 2026 07:39
Show Gist options
  • Select an option

  • Save 0riginaln0/b34f8ef2c2d98aa3b12aec5642ff7fca to your computer and use it in GitHub Desktop.

Select an option

Save 0riginaln0/b34f8ef2c2d98aa3b12aec5642ff7fca to your computer and use it in GitHub Desktop.
Get values from deeply nested tables
x = {
a = {
b = {
c = ";)"
}
}
}
print(x.a.b.c)
function get_in(tbl, keys)
local current = tbl
for _, key in ipairs(keys) do
if type(current) == "table" then
current = current[key]
else
return nil
end
end
return current
end
print(get_in(x, {"a", "b", "c"}))
function get_in_(t, ...)
for _, k in ipairs({...}) do
t = type(t) == "table" and t[k] or nil
end
return t
end
print(get_in_(x, "a", "b", "c"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment