Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Current »

You may need to call a function from a different component for various reasons, such as reducing code duplication and promoting reusability.

You can use component.call to pass data to and call a function from a different component.

Here’s an example which uses component.call to call the main function in the target “ComponentB”:

function callComponentB()
   local Data = "some string data"
   -- Call the main function of Other and wait to hear back
   local Result = component.call{name="ComponentB", data=Data, func="main", async=false}
   return Result
end
  • name of the target component. This component must be running.

  • data you need to send to the target component function. This is placed in the target component’s queue. If you target component is busy, this can take additional time to execute. To pass multiple data arguments, serialize a lua table to JSON.

  • func name of the target component function.

  • async boolean used to determine whether the current component Lua script should wait until it receives a response from the function that was called or continue immediately. Default is set to false.

  • No labels