I have a problem, i need to call a function with variable parameters that i get from a webservice... so for example:
I have a function:
function MyPrint(param1, param2)
print(param1, param2)
end
I save this function in an array of callbacks:
callback[1] = MyPrint
I get parameters from server:
params = "[2, 88]" --> JSON from server
I do:
params = json.decode(params)
-- so
-- params[1] = 2
-- params[2] = 88
I tried to pass this parameters to my callback as:
pcall(callback[1], unpack(params))
I got 2
and 88
on MyPrint function...
But if server sends "[null, 88]"
, I got nil
on both values... I have readed that unpack
function has problem with null values... but then... how can I call callback[1]
with some null
values?
Is there a way to pass an array of parameters directly to function without unpack it?
EDIT: I created MyPrint as an example... but really I don't know how many params needs the callback function, i only have a list of functions and needs to call them with a variable number of parameters that i got from server.