The Helm Table control is designed to display JSON data. In this example we show how to enter and retrieve Table data using lua script. So to begin with let’s look at how Tables exchange data with the world.

JSON data format for Tables

The JSON data has two parts:

columns – a list of the column headers

data – a list of lists comprising each row of the table

{
 "columns": [
 "First",
 "Second",
 "Third"
 ],
 "data" :
 [
 ["A","B","C"],
 ["AA","BBB","CCC"]
 ]
 }

How that looks

media_1445184114346.png

Just for now let’s paste that JSON data into the TableData property and see what happens. Immediately the table displays the data. So all we have to do then to display whatever data we want in table is to create the necessary JSON string and set the TableData property with that value.

Piece of cake? Almost.

Using JSON in lua

media_1445235179329.png

Manipulating JSON strings directly in lua would be fairly tedious, and of course there’s a better way. We use a lua module JSON.lua (get it from here http://regex.info/blog/lua/json by Jeffrey Friedl) which provides JSON:encode and JSON:decode functions to convert between lua tables and JSON strings.

So our first task is to download this file and install it as shown above in C:\Program Files (x86)\Rascular\HELM Designer\lua

Loading the JSON lua module

media_1445235263149.png

This simple one-line script in RootPanel.OnStartup makes sure that the JSON module is loaded.

JSON = require("JSON")

Add a button to load new data

media_1445235658984.png

Now we’re ready to try and load panel data programmatically.

Drag a new button onto the panel and set its OnClick script as follows:

--lua
local d = {columns = {"Name","Food","Drink"}, data = {{"Joe Blogger","burgers","coke"},{"Fred Blogger","hot dogs","beer"}}}
local json_txt = JSON:encode(d) -- encode it -- convert to a Lua table to JSON.
H.TABLE_1.TableData = json_txt;

So how does this work?
We store our data in a local lua table – d.
At the top level d has two key/value pairs:

  • columns = a list of the column headers,
  • data = a list of rows, each row itself being a list of the row’s data items.

We encode the lua table as a JSON string using the function JSON:encode (from the JSON.lua module)
Then finally we set the Table data to this JSON string.

Lets see that in action

media_1445239555043.png

Press the button and the table data is replaced by the contents of the lua table in our script.

Going the other way

When a table is property-linked to a device for example to a Harmonic server timeline, we might want to grab that data to use it in other panel functions. So here’s how to do that.

Add 3 text labels and a button to the panel

media_1445240174285.png

We create:

  1. a button that will get a row from the table
  2. three text labels display the row data

Get Data button script

media_1445241307807.png

We put the following script to the OnClick script property of the button:

--lua
local json_txt = helm.get("TABLE_1","TableData") -- fetch JSON from Helm Table
local d = JSON:decode(json_txt) -- decode it -- convert to a Lua table.
helm.set("LABEL_1","Text", d.data[1][1]) -- row 1 col 1
helm.set("LABEL_2","Text", d.data[1][2]) -- row 1 col 2
helm.set("LABEL_3","Text", d.data[1][3]) -- row 1 col 3

How the script works

First we get the TableData as a JSON string:

local json_txt = helm.get("TABLE_1","TableData") -- fetch JSON from Helm Table

Then we decode the string into a lua table ‘d’

local d = JSON:decode(json_txt) -- decode it -- convert to a Lua table.

Then we use the ‘data’ part of the table d.data to set the text for each of the TextLabels

helm.set("LABEL_1","Text", d.data[1][1]) -- row 1 col 1
helm.set("LABEL_2","Text", d.data[1][2]) -- row 1 col 2
helm.set("LABEL_3","Text", d.data[1][3]) -- row 1 col 3

The result

media_1445241460873.png

Clicking the ‘Get Data’ button loads the three text labels with the data from the first row of our Table.

Where to go from here

This opens a lot of possibilities. Lua has many libraries that implement communication to other systems over the local network and even over the internet. And there are interfaces to access files in different formats e.g. xml or SQL databases. And from within Helm you can access data from broadcast devices too. The tools we have shown you give you a powerful way to manipulate that data within Helm, display it and use it in your broadcast control system.