0

我需要在参数中传递数据。

哪个可以

1) A Single String -> 'StringData'
2) Multiple Strings -> 'StringData0', 'StringData1', 'StringData2'
3) Single Numeric data -> 10 OR 30.22
4) Multiple Numeric data -> 10, 20, 30 OR 30.22, 12.01, 1.4  
5) Mix of String, bool, int, double -> 'StringData', true, 10, 45.33, false

有什么方法可以创建一个可以接受上述任何可能性的变量

ui.InvokeFunction(parameter1, parameter2, ArgumentList)

我想在 ArgumentList 变量中填充数据,该变量可以是上述 5 种可能性中的任何一种。我没有找到在 ArgumentList 中插入多种数据类型的任何方法

4

2 回答 2

1

我没有看到任何问题,因为您可以将 Lua 中的任何值作为参数传递并使用type函数检查其类型。此外,如果您需要传递多个值,您可以传递一个表(它可以具有不同类型的值)。

ArgumentList = {'StringData', true, 10, 45.33, false}
-- type(ArgumentList[1]) == 'string'
-- type(ArgumentList[2]) == 'boolean'
-- and so on...
于 2021-12-09T06:52:46.660 回答
0

我不是 lua 专家,但我认为这样做:



Argument_List = {
  1 = {
   boolean = true
   string = ""
   other = 69
   table = nil
  }
}

valid_types = {
 "string" = true
 "boolean" = true
 "number" = false
 "table" = false
}

filtered_list = {}

for _,v in pairs(Argument_List) do 
 for x in v._ do 
  if valid_types[type(x)] then 
   table.insert(filtered_list._, {type(x) = valid_types[type(x)]})
  else
   table.insert(filtered_list._, {type(x) = false})
  end
 end
end

我假设这将是您需要的一种低效方式,但希望这会有所帮助。

于 2021-12-09T17:09:32.880 回答