[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
FW: [cinvoke-dev] Pointer to pointer as ingoing parameters?
From: |
Will Weisser |
Subject: |
FW: [cinvoke-dev] Pointer to pointer as ingoing parameters? |
Date: |
Fri, 7 Sep 2007 09:45:04 -0700 |
Oops, forgot to cc the list for the archives.
-----Original Message-----
From: Will Weisser
Sent: Friday, September 07, 2007 12:43 PM
To: 'Michael Zedeler'
Subject: RE: [cinvoke-dev] Pointer to pointer as ingoing parameters?
Michael --
The way to do this is to use an array of pointers, e.g.:
apr_allocator_create = apr:get_function( Cint, "apr_allocator_create",
cinv.array(Cptr) )
allocator_array = { nil }
apr_allocator_create(allocator_array)
allocator = allocator_array[1]
Unfortunately I'm in a rush and don't have time to test the
above, so let me know if it's total crap that doesn't work at all.
-W.W.
-----Original Message-----
From: address@hidden
[mailto:address@hidden On Behalf Of
Michael Zedeler
Sent: Friday, September 07, 2007 8:31 AM
To: address@hidden
Subject: [cinvoke-dev] Pointer to pointer as ingoing parameters?
Hi C/Invoke users.
For various reasons I am trying to interface with Apache Portable
Runtime (apr) using C/Invoke from lua. It doesn't quite pan out the way
I was expecting to.
I have to call the function apr_allocator_create in apr which has been
defined as this:
apr_status_t
<http://www.schumann.cx/docs/apr/group__APR__Error__Codes.html#a0>
apr_allocator_create ( apr_allocator_t
<http://www.schumann.cx/docs/apr/group__APR__Pool__allocator.html#a0>
** /allocator/ )
apr_status_t is just an integer and I presume that apr_allocator_t is
supposed to be a pointer to a pointer that apr_allocator_create will
then modify for me in order to return the newly created allocator.
This is how I do it:
require("cinvoke_lua")
apr = clibrary.new("libapr-1.so.0")
strnatcasecmp = apr:get_function(Cint, "apr_strnatcasecmp", Cstring,
Cstring)
print("Casecmp(hello, car) = " .. strnatcasecmp("hello", "car"))
print("Casecmp(hello, hello) = " .. strnatcasecmp("hello", "hello"))
apr_allocator_create = apr:get_function( Cint, "apr_allocator_create",
Cptr )
allocator = {{}} -- my best take, but probably wrong
apr_allocator_create( allocator )
The script produces this output:
Casecmp(hello, car) = 1
Casecmp(hello, hello) = 0
Segmentation fault (core dumped)
When looking in the manual at Cptr, I can see that Cptr is not really
intended to be used as ingoing value, except when passing null values,
so thats problably where the problem is. Is there any way that I can
call functions using pointers to pointers like apr_allocator_create from
Lua using C/Invoke?
Regards,
Michael.
_______________________________________________
cinvoke-dev mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/cinvoke-dev