我正在开发一个项目,最终用户将运行 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/