python - Python list.pop() 的 lua 等价物是什么?

标签 python list lua equivalent

我正在开发一个项目,最终用户将运行 Lua,并与用 Python 编写的服务器进行通信,但我找不到在 Lua 中完成我需要做的事情的方法。

我给程序输入:

recipient command,argument,argument sender

我得到一个列表的输出,其中包含:

{"recipient", "command,argument,argument", "sender"}

然后,将这些项目分成单独的变量。之后,我将命令、参数、参数分离到另一个列表中,并再次将它们分离到变量中。

我是如何用 Python 做到这一点的:

test = "server searching,123,456 Guy" #Example
msglist = test.split()
recipient = msglist.pop(0)
msg = msglist.pop(0)
id = msglist.pop(0)

cmdArgList = cmd.split(',')
cmd = cmdArgList.pop(0)
while len(cmdArgList) > 0:
    argument = 1
    locals()["arg" + str(argument)]
    argument += 1

最佳答案

你的标题中的问题要求一些非常具体的东西:Lua相当于从数组中获取一个值并将其删除。那将是:

theTable = {};  --Fill this as needed
local theValue = theTable[1];  --Get the value
table.remove(theTable, 1);     --Remove the value from the table.

您在帖子中提出的问题似乎非常开放。

关于python - Python list.pop() 的 lua 等价物是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7493923/

相关文章:

lua - 罗技脚本结合击键和鼠标点击

python - Selenium Geckodriver Firefox 在 CRONTAB 中不工作,在终端上工作

python - 如何跳过超出范围的索引?

c++ - 使用tolua++时如何让lua获得返回值的所有权?

Python 从 CSV 创建嵌套列表

list - 指定位置可以采用的元素的情况下,生成所有可能列表的列表的函数

C++ Lua用户数据与Mathfu浮点值混淆

python - Jenkins 不在控制台中打印 python 脚本的输出

python - 使用 pandas,如果另一列不为空,如何使用 dataframe 查找列值?

python - 迭代列表的所有子组