How to add attribute or tag from lua to a task

Turns out Zef’s metatable trick from the previous post does indeed work. Somehow I couldn’t get it to work last time..!!!

local mt = { 
  __index = function(self, attr) 
    if attr == "extraAttrs" then 
      return { extraName = self.name .. "-extra-" } 
    end 
  end 
}
index.defineTag { name = "task", metatable = mt }

and try

${query [[from index.tag "task" select {name=name, extra=_.extraAttrs.extraName}]]} 

Does indeed inject the extra attribute into the task object - this might just be what we need…!!!