# How to extend index from hooks?

**URL:** https://community.silverbullet.md/t/how-to-extend-index-from-hooks/3060
**Category:** Lua
**Created:** [August 20, 2025, 1:38pm UTC](https://community.silverbullet.md/t/how-to-extend-index-from-hooks/3060 "2025-08-20T13:38:32Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![mjf](https://community.silverbullet.md/user_avatar/community.silverbullet.md/mjf/32/654_2.png) [@mjf](https://community.silverbullet.md/u/mjf)
#### Post date: [August 20, 2025, 1:38pm UTC](https://community.silverbullet.md/t/how-to-extend-index-from-hooks/3060/1 "2025-08-20T13:38:32Z")

</div>

Does any way exist to extend the index from appropriate hooks?

_TL;DR_

I am trying to extend index for pages with custom value. I dully hoped the following will work (intuitively):

````lua
```space-lua
event.listen {
  name = 'editor:pageSaved',
  run = function(e)
    e.testingVariable = e.lastModified
    print('Data', e.data)
    return e
  end
}
```

````

It seems the `e` is immutable or something because the `print()` call does not print the `testingVariable` at all.

---

<div class="post-metadata">

### Author: ![zef](https://community.silverbullet.md/user_avatar/community.silverbullet.md/zef/32/7_2.png) [@zef](https://community.silverbullet.md/u/zef)
#### Post date: [August 20, 2025, 1:41pm UTC](https://community.silverbullet.md/t/how-to-extend-index-from-hooks/3060/2 "2025-08-20T13:41:32Z")

</div>

You cannot extend page attributes, but you could create separate objects as part of the index process. The event to listen to is `page:index`.

You can then create new objects via the `index.indexObjects` API: [API/index](https://silverbullet.md/API/index#index.indexObjects(page,%20objects))

---

<div class="post-metadata">

### Author: ![mjf](https://community.silverbullet.md/user_avatar/community.silverbullet.md/mjf/32/654_2.png) [@mjf](https://community.silverbullet.md/u/mjf)
#### Post date: [August 21, 2025, 5:31am UTC](https://community.silverbullet.md/t/how-to-extend-index-from-hooks/3060/3 "2025-08-21T05:31:10Z")

</div>

OK, I will give it a try. But still, if the `e` in my example above is immutable, I should at least see some warning(s) in the console (which I don’t).

---

<div class="post-metadata">

### Author: ![zef](https://community.silverbullet.md/user_avatar/community.silverbullet.md/zef/32/7_2.png) [@zef](https://community.silverbullet.md/u/zef)
#### Post date: [August 21, 2025, 8:41am UTC](https://community.silverbullet.md/t/how-to-extend-index-from-hooks/3060/4 "2025-08-21T08:41:41Z")

</div>

There isn’t really such a thing as immutable data in Lua

---

<div class="post-metadata">

### Author: ![mjf](https://community.silverbullet.md/user_avatar/community.silverbullet.md/mjf/32/654_2.png) [@mjf](https://community.silverbullet.md/u/mjf)
#### Post date: [August 21, 2025, 11:13am UTC](https://community.silverbullet.md/t/how-to-extend-index-from-hooks/3060/5 "2025-08-21T11:13:04Z")

</div>

OOPS! My fault, there’s a typo in the code. 😉

> There isn’t really such a thing as immutable data in Lua

_TL;DR_

To explain more further… One can always play with table’s metamethods to gain _poor man’s_ sort of “immutability” as some sort of “safety net” (if needed)…

```lua
function immutable(tbl)
  return setmetatable({}, {
    __index = tbl,
    __newindex = function(tbl, key, val)
      error('Cannot modify read-only table')
    end,
    __metatable = false
  })
end

local t = immutable { x = 1, y = 2, z = 3 } -- new "immutable" table `t`

```

It’s a nice trick but **MUST NOT** be considered as a “security feature” or something like that because the `rawset()` call can still be used to override this!

So, yes, there is simply **no real immutability in Lua**. 🙂
