Edit: An early version is ready for download. Pls post your suggetions.
http://www.artminusart.com/downloads/ofLua-test.zip
Edit2: Please look at the bottom of this page for a modified version download provided by Otherside.
Hello All,
I have asked this same question in a lua forum and got no answer. So sorry if it is cross posting.
I am trying to wrap a c++ class from openframeworks using swig. This is a part from the oftexture.
class ofTexture {
public :
ofTexture();
~ofTexture();
void allocate(int w, int h, int internalGlDataType);
void clear();
void loadData(unsigned char * data, int w, int h, int glDataType);........};
I have got it wrapped by including the whole header file in the swig … .i file.
I have some functions working now in lua.
The lua script file looks something like this
texColor=Example.ofTexture()--create a texture
w=250
h=200
colorPixels={}--create an array
texColor:allocate(w,h,6407)--allocate the texture
----------------fill the table array
for i=0,w do
for j=0,h do
colorPixels[(j*w+i)*3 + 0] = i -- r
colorPixels[(j*w+i)*3 + 1] = j -- g
colorPixels[(j*w+i)*3 + 2] = 0 -- b
end
end
--------------
texColor:loadData(colorPixels, w,h,6407 );--GL_RGB
The loadData function won’t take a table array for unsigned char*. What am I doing wrong?
How do I use a table to pass a char* value as a function argument. Is it necessary? Or how do I do it? Please point me in the right direction.Thank you.
The following code is from the swig wrapper.
static int _wrap_ofTexture_loadData(lua_State* L) {
int SWIG_arg = -1;
ofTexture *arg1 = (ofTexture *) 0 ;
unsigned char *arg2 = (unsigned char *) 0 ;
int arg3 ;
int arg4 ;
int arg5 ;
if(!lua_isuserdata(L,1)) SWIG_fail_arg(1);
if(!lua_isuserdata(L,2)) SWIG_fail_arg(2);
if(!lua_isnumber(L,3)) SWIG_fail_arg(3);
if(!lua_isnumber(L,4)) SWIG_fail_arg(4);
if(!lua_isnumber(L,5)) SWIG_fail_arg(5);
arg1=(ofTexture *)SWIG_MustGetPtr(L,1,SWIGTYPE_p_ofTexture,0,1,"ofTexture_loadData");
arg2=(unsigned char *)SWIG_MustGetPtr(L,2,SWIGTYPE_p_unsigned_char,0,2,"ofTexture_loadData");
arg3 = (int)lua_tonumber(L, 3);
arg4 = (int)lua_tonumber(L, 4);
arg5 = (int)lua_tonumber(L, 5);
(arg1)->loadData(arg2,arg3,arg4,arg5);
SWIG_arg=0;
return SWIG_arg;
fail:
lua_error(L);
return SWIG_arg;
}
Thanks again
Sajith