I am calling a Lua script from nodejs. I want to pass an array as argument. I am facing problem to parse that array in Lua.
Below is an example:
var script = 'local actorlist = ARGV[1]
if #actorlist > 0 then
for i, k in ipairs(actorlist) do
redis.call("ZADD","key", 1, k)
end
end';
client.eval(
script, //lua source
0,
['keyv1','keyv2']
function(err, result) {
console.log(err+'------------'+result);
}
);
It gives me this error:
"ERR Error running script (call to f_b263a24560e4252cf018189a4c46c40ce7d1b21a): @user_script:1: user_script:1: bad argument #1 to 'ipairs' (table expected, got string)
You can do it just by using ARGV:
local actorlist = ARGV
for i, k in ipairs(actorlist) do
and pass arguments in console like this:
eval "_script_" 0 arg1 arg2 argN
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With