Closed a1tus closed 5 years ago
I have a function with several args any of which can be nil. Very simplified example.
nil
function test(arg1, arg2) if not arg2 then arg2 = 0 end return arg1 + arg2 end
While using it from LUA console like test(1) or test(1, nil) everything is fine.
test(1)
test(1, nil)
But when I try to call it from python I get error:
>> connection.call('test', [1, None]) DatabaseError: (32, '[string "function test(arg1, arg2)..."]:5: attempt to perform arithmetic on \'number\' and \'void *\'')
So arg2 is void * and its type in this case is not nil but cdata which evaluates to true.
void *
cdata
true
P.S. I know that I can use dict that will contains all params as single function arg but for API clarity it would be nice to solve this issue.
Please see https://github.com/tarantool/doc/issues/753
Don't use if not arg2 then, use if arg2 ~= nil then
if not arg2 then
if arg2 ~= nil then
I have a function with several args any of which can be
nil
. Very simplified example.While using it from LUA console like
test(1)
ortest(1, nil)
everything is fine.But when I try to call it from python I get error:
So arg2 is
void *
and its type in this case is notnil
butcdata
which evaluates totrue
.P.S. I know that I can use dict that will contains all params as single function arg but for API clarity it would be nice to solve this issue.