Instead of having Lua return a table and converting that in C to an nvlist, why
not make the Lua code build the nvlist?
You can push in a C function (call it `NVList`) that returns a userdata
(pointing at a struct with an nvlist pointer in it) with a metatable that has
`__index` and `__newindex` set to C functions that switch on their argument
types and call `nvlist_add_*`. Then accept that userdata as the return type of
the Lua code. This would get rid of the doubled-up work with minimal change in
the Lua code -- it would just look like:
```lua
local foo = NVList()
foo["blah"] = ...
```
Instead of
```lua
local foo = {}
foo["blah"] = ...
```
And the C code would be free to validate keys for duplication and deal with
types as it sees fit. The errors would also point at the code that actually
generated the weird value, rather than just being a generic "your Lua returned
something wonky" error.
--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/openzfs/openzfs/pull/397#issuecomment-307889420
------------------------------------------
openzfs-developer
Archives:
https://openzfs.topicbox.com/groups/developer/discussions/Tffb276f83a8ecdd2-M3f5ef08b57b755a44e966a43
Powered by Topicbox: https://topicbox.com