Calling C++ functions in luawith objects as arguments

"[email protected]" <[email protected]>
Newsgroups gmane.comp.lang.lua.bind.user
Message-ID <[email protected]>
Hello folks,

i'm new to Lua/Luabind, i'm trying to call some C++ functions from a library with lua and i hope you can give me some help.

The C++ functions are in a namespace:

namespace ImageProcessor
{
void Invert(const CByteImage *pInputImage, CByteImage *pOutputImage)
{
//Function declaration here!
}

void Canny(const CByteImage *pInputImage, CByteImage *pOutputImage, int nLowThreshold, int nHighThreshold)
{
//Function declaration here!.
}

void Canny(const CByteImage *pInputImage, CVec2dArray &resultPoints, CVec2dArray &resultDirections, int nLowThreshold, int nHighThreshold)
{
//Function declaration here!.
}
...
... More functions here
...
}

As you can see, the functions take several arguments, for example objects of the class CByteImage.

In my C++ Code, I create these objects of the class CByteImage:

CByteImage *m_pInImage;
CByteImage *m_pOutImage;
m_pInImage = new CByteImage(int width, int height, CByteImage::eGrayScale);
m_pOutImage = new CByteImage(int width, int height, CByteImage::ImageType);

Later, i call for example the first two functions in my C++ code like this:

ImageProcessor::Invert(m_pInImage, m_pOutImage);
ImageProcessor::Canny(m_pInImage, m_pOutImage, 50, 50);

Now i want to call these two C++ functions in lua, and that's the point where my problems begin:
Nicolas told me, that i need to bind the functions in the namespace where they are defined.

Now the thing with the objects. I don’t really know how to handle these things. Do I have to bind the whole class CByteImage with the objects that I use as arguments of my function? Do I have to use the “user definded types” thing to tell lua how to handle these data types? Do I use pointers and make them available for lua?

What I’ve done so far:

lua_State* LuaState = lua_open();
// open the new state with luabind
luabind::open(LuaState);
// export the functions we want
luabind::module(LuaState)
[
// First Arg: Name of the function in Lua, Second Arg: Function in C++
luabind::def("Invert", &ImageProcessor::Invert)
//I don't know exactly how to bind the arguments of the Canny function
luabind::def("Canny", &ImageProcessor::Canny, (void), (const CByteImage *), (CByteImage *), (int), (int)),

//Binding of the CByteClass
luabind::class_<CByteImage>("CByteImage")
.def(luabind::constructor<>())
//Not sure how to binb objects
luabind::object global_vars = luabind::globals();
global_vars["a"] = a;

];

Now I have thought that I could call these two C++ functions in lua like this:

--Lua

test = Invert(m_pInImage, m_pOutImage)

test2 = Canny(m_pInImage, m_pOutImage, 50, 50)

Again, is this correct or how do I have to do this?

Thank you very much for your help

Greetz Janik

------------------------------------------------------------------------------
The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
Pinpoint memory and threading errors before they happen.
Find and fix more than 250 security defects in the development cycle.
Locate bottlenecks in serial and parallel code that limit performance.
http://p.sf.net/sfu/intel-dev2devfeb

_______________________________________________
luabind-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/luabind-user
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.