mt-mods / pipeworks

Pipeworks is a mod for Minetest allowing the crafting and usage of pipes and tubes

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

expose sanitized item definition to lua tube

programmerjake opened this issue · comments

expose sanitized item definition to lua tube -- this would be really handy for e.g. filtering by groups.

by sanitized i assume you mean at least a basic table.copy so that a person in a lua tube cant end up modifying the actual registration def. however what further should be done to sanitize it, a predefined whitelist of keys that are passed over? blacklisting all keys that start with an underscore since those are from mods(not all mods follow this convention when they should), etc?

commented

I'd say no.

Useful feature sure but wrong place for implementation.

This should be implemented through (planned, not available yet) sandbox extensions to allow reading item definitions directly without having to actually add it as a feature for pipeworks (or luacontroller, or whatever scriptable in game lua thing).

Basically have someone provide API for it instead of throwing it into item info which would be bad for performance and useless in most use cases. For example, Lua tube code would be something like this:

if event.type == "item" then
    local registered_items = require("registered_items")
    local def = registered_items[event.item.name]
    if def and def.groups and def.groups.fluffy then
        return "black"
    else
        return "red"
    end
end

First: it wouldn't be a pipeworks issue. Second: it would be the same for other scriptable things. Third: it would likely fix every possible issue that falls into this category.

I'd say try push that thing forward before starting to throw workarounds directly into lua tube implementation.

The digiline_craftdb node already has a way to do this, with its search_items API: https://github.com/dennisjenkins75/digiline_craftdb/blob/main/README.md#search_items-api.

In the future, like SX said, this would be best to add via a sandbox extension or library, so that other Lua-controlled nodes have access to it as well.