How can we easily use Lua tables with obs_data_array_t?

Stormin

New Member
I'm working on a Lua script that has a table that looks like:
Code:
local mode_options = {"Random Order", "Alphabetical Order", "Alphabetical Order, start on random", "Alphanumeric","Modified Order"}

That data array of mode_options needs to be assigned to a obs_data_array_t

I tried:
Lua:
obs.obs_data_set_array(slideSettings,"mode_options",mode_options)
and got the error:

Lua:
Error in obs_data_set_array (arg 3), expected 'obs_data_array_t *' got 'table'

First, I am unsure what obs_data_array_t actually is. What kind of array is it?

I appreciate that the table type supports a number of different types of array.

Sooo... what is obs_data_array_t expecting? The OBS API docs have zero information about that.

Now, I may of course be ignorant of a base type of some sort. So if I need to read elsewhere, please just ping me a URL.

Note that we want all the data contained in the slideSettings to be JSON compatible in order to export an import to JSON files.
 
When you get beyond primitive data, C and Lua have significant differences. A type ending in _t is a C datatype.
For some C types, OBS's Lua implementation does conversion to and from Lua datatypes. This one is sort of an abstract array, and you need to do the work - basically building the array one element at a time.

So call obs_data_array_create to make an empty array.
Then loop on the elements of mode_options, calling obs_data_create to make an element, obs_data_set_string (or whatever is appropriate to the element) to populate it, then obs_data_array_push_back or obs_data_array_insert to add the element to the array.

Once the array is built, you can pass it to obs_data_set_array
 
Top