Skip to content

Commit

Permalink
More docs cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Danielkonge committed Dec 4, 2023
1 parent c0c3df4 commit 796ea5f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
12 changes: 6 additions & 6 deletions docs/config/lua/wezterm.table/get.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ assert(wezterm.table.get(tbl, key) == tbl[key])
```
You may pass a sequence of keys that will be used to successively resolve
nested tables:
```
wezterm.table.get(tbl, 'a', 'b', 'c') == tbl['a']['b']['c']
```lua
local tbl = { a = { b = { c = true } } }
assert(wezterm.table.get(tbl, 'a', 'b', 'c') == tbl['a']['b']['c'])
```

*Note:*

* In the above `tbl['a']['b']['c']` might cause an error, since we might be indexing a nil value,
but `wezterm.table.get(tbl, 'a', 'b', 'c')` won't error in this case; instead it will return `nil`.
* This function can also be used on `Userdata` objects that implement an `__index`
metamethod.
* In the above `tbl['a']['a']['a']` would cause an error, since we are indexing a nil value,
but `wezterm.table.get(tbl, 'a', 'a', 'a')` won't error in this case; instead it will return `nil`.
* This function can also be used on `Userdata` objects that implement an `__index` metamethod.


```lua
Expand Down
25 changes: 14 additions & 11 deletions docs/config/lua/wezterm.table/has_key.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,23 @@

{{since('nightly')}}

This function accepts a Lua table `table` and an arbitrary number of keys `keys..`.
It returns `true` if `table` contains a non-nil value at the position specified by
`keys..` and `false` otherwise.

The arbitrary number of extra arguments will all be intepreted as extra keys to check
for recursively in the table. I.e., to check whether `table` has any non-nil value at
`table['a']['b']['c']`, we can use `wezterm.table.has_key(table, 'a', 'b', 'c')`.
This function can be used to check if a key in a table has a non-nil value. In its most
basic form it is equivalent to:
```lua
assert(wezterm.table.has_key(tbl, key) == (tbl[key] ~= nil))
```
You may pass a sequence of keys that will be used to successively check nested tables:
```lua
local tbl = { a = { b = { c = true } } }
assert(wezterm.table.has_key(tbl, 'a', 'b', 'c') == (tbl['a']['b']['c'] ~= nil))
```

*Note:*

* In the above `table['a']['b']['c']` might cause an error, since we might be indexing a nil value,
but `wezterm.table.has_key(table, 'a', 'b', 'c')` won't error in this case; instead it will return `false`.
* This function can also be used on `Userdata` objects that implement an `__index`
metamethod.
* In the above `tbl['a']['a']['a']` would cause an error, since we are indexing a nil value,
but `wezterm.table.has_key(tbl, 'a', 'a', 'a')` won't error in this case; instead it will return
`false`.
* This function can also be used on `Userdata` objects that implement an `__index` metamethod.

```lua
local wezterm = require 'wezterm'
Expand Down

0 comments on commit 796ea5f

Please sign in to comment.