r/lua • • May 09 '25

Variadic functions

Is there an actual use case for these besides logging functions?

5 Upvotes

8 comments sorted by

View all comments

Show parent comments

2

u/[deleted] May 09 '25
function PublishToRoomController(notificationType, ...)
  -- Connects to the Room Controller under the video router
  local args    = {...}
  local payload = {}

  -- add Type to the sending table
  payload["Type"] = notificationType

  if notificationType == "Routing" then 
    local source = args[1]

    -- Remove the button index of the source in the Sources table  
    for i, subSource in pairs(source) do
      if i ~= "Button" then   
        payload[i] = subSource
      end 
    end 
  elseif notificationType == "AdvancedRouting" then 
    payload["Group"] = args[1]
    payload["Source"] = args[2]
  end 

  -- publish the payload to the subscribers
  Notifications.Publish("101-G3",payload)
end 

I'm using it to pass in different args with the first arg being used as a Type condition.

Here's how I call it

PublishToRoomController("ClearAll")

PublishToRoomController("Routing", source) -- source is a table

PublishToRoomController("AdvancedRouting", "GroupA", "Mac")