C

Lua Modules

Extending Qt 3D Studio

The Qt 3D Studio Runtime can easily be integrated with existing hardware and software by means of modules. Modules are a standard feature of the Lua language that allow new C bindings to be added with a DLL or shared library.

The diagram above shows multiple Lua Modules extending the capabilities of the Runtime scripting to allow access to low level calls controlling hardware such as music, navigation, and general CAN Bus communication.

Binding Code to Lua

Lua Bindings are a well-documented topic online. A nice reference for implementation can be found on the Lua wiki. Additionally, a simple sample of a CAN module that works with CarConnection behavior is provided with your installation of Qt 3D Studio at INSTALL_DIRECTORY/Runtime/Plugins/Bindings/CAN/....

To call functions in your module, place the .dll (Windows) or .so (Linux/Android) directly next to the Qt 3D Studio Viewer executable. At the top of a script where you would like to call your custom bindings, use the Lua require function.

-- Load the CAN module and output any errors in the process
require("CAN")

The use of require() will produce helpful error strings if the module cannot be found. Once the system is in place, however it is often preferable to control the resulting errors. For this, you can use the built-in Lua function pcall():

-- Instead, one can use pcall to hide errors and control the program flow
if not pcall( require, "CAN" ) then
   output( "Could not locate CAN module." )
end

-- Call a function in our Lua binding
if CAN then
   self.catalog = CAN.getCatalog()
end

Available under certain Qt licenses.
Find out more.