Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Jira Legacy
serverSystem Jira
serverId4917c5d3-f7c1-348a-87e1-71271a4d06b7
keyIX-3497

Make a remote call - ie. call a function within another component

component.call{}

...

The interface is table in, anything out. Only the first returned argument is captured, so to return multiple values a table must be used.

the target component must be running

...

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”:

Code Block
languagelua
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.