Sometimes Lua module is used with some obsolete parameters, and wants to create a category for all pages that use it in obsolete way. Other times Lua might simply want to add a category to the page. Regardless, adding "[[category:xxx]]" to the output is not ideal because there are many cases when it breaks final wiki markup (e.g. in the middle of the html atribute text.
I think there should be a frame::addCategory()
Feature summary (what you would like to be able to do and where):
I would like a method such as mw.addCategory(), etc. that adds categories to the page without relying on the frame output. This would be useful for emitting maintenance messages when parts of modules are used incorrectly in other modules.
Use case(s) (list the steps that you performed to discover that problem, and describe the actual underlying problem which you want to solve. Do not describe only a solution):
I created a module Module:Deprecated to emit a warning message in preview when a deprecated member of a module, or the entire deprecated module, is called. It uses a metatable wrapper in order to warn about deprecated methods. However there isn't a way to emit categories when non-string members are accessed, which would be very useful for meta-modules, i.e. modules used in other modules.
Benefits (why should this be implemented?):
The use of such a method would mean that there exists a way to add tracking and maintenance categories more easily without relying extensively on wikitext output. Currently there is only a way to add a single category, "Pages with script errors" etc., using the error() method.