cinvoke-dev
[Top][All Lists]
Advanced

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

RE: [cinvoke-dev] Question: cinv.string_to_chararray lua binding


From: Will Weisser
Subject: RE: [cinvoke-dev] Question: cinv.string_to_chararray lua binding
Date: Thu, 3 Aug 2006 12:09:35 -0500

Yes, string_to_chararray is broken, the below patch fixes it.  There is
also another patch for ptr_to_string:

@@ -1359,7 +1359,7 @@
 int _cinv_ptr_to_string(lua_State *l) {
        char *ptr;
        int len = -1;
-       if (lua_gettop(l) != 1 || lua_gettop(l) != 2) {
+       if (lua_gettop(l) != 1 && lua_gettop(l) != 2) {
                lua_pushstring(l, "usage: cinv.ptr_to_string(cptr[,
len])");
                lua_error(l);
        }

Or you can grab the latest source out of subversion which has several
Lua fixes not in the 0.9 release.

The reason I mention ptr_to_string is that I think to do what you're
trying to do you'll probably need to use it, assuming the char ** is an
"out" parameter:

address@hidden test]$ cat test.c
void foo(char **c) {
        *c = "hello";
}
address@hidden test]$ gcc -shared -o test.so test.c
address@hidden test]$ cat test.lua
require("cinvoke_lua")

lib = clibrary.new("./test.so")

foo = lib:get_function(Cvoid, "foo", cinv.array(Cptr))

ptr_arr = { "0" } -- initialize with null pointer
foo(ptr_arr)
print(cinv.ptr_to_string(ptr_arr[1]))
address@hidden test]$ lua test.lua
Hello
address@hidden test]$

        -W.W.

-----Original Message-----
From: address@hidden
[mailto:address@hidden On Behalf Of
Shmuel Zeigerman
Sent: Thursday, August 03, 2006 2:03 PM
To: address@hidden
Subject: Re: [cinvoke-dev] Question: cinv.string_to_chararray lua
binding

This patch should help:

cinvoke_lua.c, line 1295.
-  lua_settable(l, 1);
+  lua_settable(l, -3);

Arjen P. de Vries wrote:

> I was trying to use cinvoke, and first experiment worked fine,
> but now I want to call a function with parameter char** and have not
> been successful so far.
> 
> I ended up doing:
>   require("cinvoke_lua")
>   c = cinv.string_to_chararray("Test", true)
>   print("c[1] = " .. c[1])
> 
> which gives the error message:
>   lua: attempt to index a string value
>   stack traceback:
>           [C]: in function 'string_to_chararray'
>           t.lua:2: in main chunk
>           [C]: ?
> 
> Am I doing something wrong?



_______________________________________________
cinvoke-dev mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/cinvoke-dev




reply via email to

[Prev in Thread] Current Thread [Next in Thread]