lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi, guys!
Is it any way to pass int to function, expecting *void?
I cannot change type in declaration to int*, because sometimes I need to pass strings instead of integers.

To explain what I mean. Right now I'm trying to wrap some of libssh's APIs, but I have the problem with function ssh_options_set:

    ffi.cdef[[
    int ssh_options_set(ssh_session session, int type, const void* value);
    ]]
    ssh = ffi.load(ssh)
    -- Assuming session is initialized with appropriate value
    -- ssh_option_set expects int* as third argument in following examples
    ssh.ssh_options_set(session, 1, 22) -- causes error "cannot convert 'int' to 'const void *"
    ssh.ssh_options_set(session, 1, ffi.new("int", 22)) -- the same error
    ssh.ssh_options_set(session, 1, ffi.cast("void *", ffi.new("int", 22))) -- causes segfault

With strings everything is fine.
I've tried a lot of strange and sometimes horrible constructions, but everything causes cast error or segfault. 

-- 
Thanks in advance,
Vladimir Protasov.