You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在DaVinci Resolve中将类表格式字符串转换为Lua表?

DaVinci Resolve脚本:字符串转Lua表解决方案

你可以用Lua的load()函数处理这个字符串——你的目标字符串本身是合法的Lua表语法,只要提前处理好InstanceInput的定义就能解析。具体步骤如下:

1. 提前定义InstanceInput构造逻辑

字符串里的InstanceInput是自定义构造函数,DaVinci Resolve环境里没有这个全局函数,直接解析会报错。如果不需要保留原构造的特殊逻辑,直接把它转成普通表即可:

local function InstanceInput(tbl)
    return tbl -- 直接返回传入的键值对表
end

如果InstanceInput是DaVinci Resolve API里的实际类,替换成对应的全局构造函数即可。

2. 用load()解析字符串转表

把目标字符串包装成返回表的Lua代码,编译后执行就能得到原表结构:

-- 假设你的目标字符串存在str变量中
local str = [[{
   Item1 = InstanceInput {
      Name = "Name",
      SourceOp = "SourceOp",
   },
   Item2 = InstanceInput {
      Name = "Name",
      SourceOp = "SourceOp",
   }
}]]

-- 编译并执行字符串,用pcall避免解析错误崩溃
local success, result = pcall(load("return " .. str))
if success then
    -- 遍历表获取数据
    for key, item in pairs(result) do
        print(key, item.Name, item.SourceOp)
    end
else
    print("解析失败:", result)
end

内容的提问来源于stack exchange,提问作者Asher Roland

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.24 08:23:19