Reputation: 43
I have a requirement of passing data in arguments.
Which can be
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
Is there any way that I can create a Variable that can accept any of the above possibility
ui.InvokeFunction(parameter1, parameter2, ArgumentList)
I want to fill the data in ArgumentList variable which can be any of the above 5 possibility. I did not find any way to insert multiple data types in ArgumentList
Upvotes: 0
Views: 499
Reputation: 11
I'm no expert at lua but I think that doing something like:
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
I'm assuming that would be an inefficient way of what you're requiring but hopefully that helped.
Upvotes: 0
Reputation: 26744
I don't see any problem, as you can pass any value in Lua as a parameter and check its type using type
function. Also, if you need to pass multiple values, you can pass a table (which can have values of different types).
ArgumentList = {'StringData', true, 10, 45.33, false}
-- type(ArgumentList[1]) == 'string'
-- type(ArgumentList[2]) == 'boolean'
-- and so on...
Upvotes: 1