【问题标题】:How to create a list and append values as in python using lua如何使用 lua 在 python 中创建列表和附加值
【发布时间】:2020-09-30 13:53:03
【问题描述】:

我正在尝试使用本地目录中的文件名创建一个列表,并使用 lua 将其添加到 nginx 中的 http 请求正文。像下面的东西

filelist = [] #a list variable to hold the filenames
for file in f:lines() do
   #file i get my filename one by one
   filelist.append(file)
end

request_payload = {"somedata":"its key", "files": filelist}

假设我有请求正文,我需要使用新的文件列表变量值更新该 json。

我知道 lua 没有什么像列表对象,而是它具有表结构。但是有没有什么简单的技巧可以完成这项工作

【问题讨论】:

    标签: nginx lua openresty


    【解决方案1】:

    我可以使用 lua 数组

    local filelist = {} #lua table object
    for file in f:lines() do
       #file i get my filename one by one
       table.insert(filelist, file) #this will update the array
    end
    

    希望对某人有所帮助:)

    【讨论】:

      猜你喜欢
      • 2021-10-10
      • 2017-11-11
      • 2017-06-17
      • 1970-01-01
      • 2020-08-26
      • 1970-01-01
      • 2017-08-22
      • 2015-02-10
      • 2023-01-20
      相关资源
      最近更新 更多