From: Mark G. <ma...@go...> - 2008-10-24 11:30:19
|
> hello, i got trouble binding and using function like > > void func(int* i); and void func(int& i); > > Main problem is, for int func(int& i), there is a call > to lua_isuserdata() > for my param, > so in lua script: > > < > > varA = 10 > > func(varA) -> fails because varA is not a user data but > a number > > > > > and for the int func(int* i), there is a call to isptrtype, > problem is, how > do i get a int * in LUA. > > < > > varA=10 > > func(&varA) ??? not working > > i do not even know, how, from a int / number lua variable, > can i get its > reference and its pointer adress > > Thank you for any help ! > > Thomas > Hello Thomas, What you have here is the standard SWIG attitude (everything else is a pointer). Given the functions: void func(int* i); void func(int& i); SWIG considers that both of them want an integer pointer (which is quite close, since references are wrapped as pointers). There are two issues to address: one if how to select which one to use, the second is to use it properly. I will look at the second issue: assuming that they are both output functions (ie the parameter i is meant to be returned) what you do is : #include <typemaps.i> %apply int* OUTPUT {int *i}; // int *i is output void func(int *i); Then when you call it in Lua, you get this effect. i=func() -- returns i If its really an input or input and output, then change the typemap to INPUT or INOUT accordingly. As for the issue of which function to use: if your typemaps make the function signature sufficiently different, then all is good. Otherwise you will need to rename them %rename(func_p) void func(int* i); %rename(func_ref) void func(int& i); Hope that helps, If you are still not sure, please let me know. Regards, Mark |