2

I did find a version of this for a string into a table that splits up the letters of the string, but I have a table, that I turn into a string to remove the first part of it, and now I want it back as a table so I can do a for loop through it to get the data inside.

This is the kind of table I'm talking about – the string currently looks something like this:

{
   Item1 = InstanceInput {
      Name = "Name",
      SourceOp = "SourceOp",
   },
   Item2 = InstanceInput {
      Name = "Name",
      SourceOp = "SourceOp",
   }
}

I'm scripting in Davinci Resolve, and I bet that relates to a small subset of you, but it has an operation to turn something into "userdata" and I tried that, but it returned it as nil.

I have tried to use the pretty.read() function. But I cannot use utils due to the way Davinci Resolve handles require.

1
  • Do you have access to dostring, loadstring or load in your environment? using one of those and prepending the text return to the table string will return the table as a table. Commented May 13, 2024 at 13:29

1 Answer 1

1

If you have access to the load function you can turn the string into a table (assuming the string will always be valid Lua syntax)

local importedTable = load("return " .. tableToImport:gsub("InstanceInput", ""))()

print(importedTable["Item1"].Name) --> "Name"

How it works is the string passed to load is compiled as a Lua function chunk, which you then can call like any other function which is why you prefix it with return so that when called it returns the Lua table.

Sign up to request clarification or add additional context in comments.

7 Comments

@shingo Yes, but not in davinci onecompiler.com/lua/42d4adv3e
That is doing something, but I forgot an important part of the table string. My Bad! it goes: ``` Item1 = InstanceInput {Rest of the info} ```
@AsherRoland would you mind updating the question with the full snippet of code just so I can see what you mean?
There you go! :)
@AsherRoland do you know what InstanceInput is doing and if you care about the changes it is making to the tables being passed to it?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.