[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: use cases of getuservalue and setuservalue?
- From: Albert Krewinkel <albert+lua@...>
- Date: Tue, 27 Sep 2022 09:27:04 +0200
"ubq323" <email@example.com> writes:
> what is the purpose of the lua_setuservalue and lua_getuservalue
> (or in lua 5.4, getiuservalue and setiuservalue) functions?
> what's the intended use case of being able to associate arbitrary lua
> values with full userdata?
> and does anyone know of any notable or interesting uses of this
One use-case is to implement lazy loading of attributes and to "cache"
values: Marshaling values can be somewhat expensive, so a large value
can be turned into a userdata object, and attributes get marshaled on
demand. Once marshaled, attributes are kept around in a uservalue table,
so they won't have to be marshaled again.
We're using this in HsLua, a Haskell-to-Lua bridge: https://hslua.org
GPG: 8eed e3e2 e8c5 6f18 81fe e836 388d c0b2 1f63 1124