Eliot’s Tips and Tricks

Calling functions with {}

Some functions in the Translator API are called using curly braces {}. This is because the function takes a single table as an argument. Lua supplies some syntactic sugar here – allowing us to omit the implicit brackets (). The following code shows several equivalent ways of calling a function that takes a Lua table:

The reason for using this format in many of the Translator APIs is to give the flexibility to introduce new parameters and deprecate older ones – without breaking backward compatibility. It is a technique often used with dynamic languages like Lua and Javascript to future proof APIs.


One Comment

  1. Pingback: Will You Share Your Code? - iNTERFACEWARE Inc.

Leave A Comment?

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.