Jump to content
  • Advertisement
Sign in to follow this  
beun

Luabind & return_stl_iterator

This topic is 3303 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I've been having some problems with Luabind and return_stl_iterator. Here's a sample:
std::vector<int> TestVector()
{
	std::vector<int> vec;
	vec.push_back(1);
	vec.push_back(5);
	vec.push_back(9);
	vec.push_back(7);
	return vec;
}

void Script::RegisterTypes() // Called when constructing the Script class, which holds lua_State* etc.
{
    using namespace luabind;
    module(m_state)
    [
        def("TestVector", &TestVector, return_stl_iterator)
    ];
}

test.lua:
testIt = TestVector()

for item in testIt do
	print(item)
end

When I run this normally, the program crashes (both the Release and the Debug version). However, when I run the program from MSVC (2008) with F5 (Start debugging) or Ctrl+F5 (Start without debugging), the program runs and exits normally, but the breakpoint in TestVector is never triggered, so Lua never calls that function. (Again, both in the Release and the Debug version.) EDIT: I forgot that MSVC changes the current directory, so the script file was never executed.[ignore] Lua doesn't give an error, and Luabind doesn't throw an exception. I don't know what's causing the problem. I could always use a wrapper function for Lua which puts the vector in a table, but then Luabind would be useless anyway. Does someone know what's causing this? EDIT 2: Apparently return_stl_iterator only works with references (although returning values doesn't give a compile error): Luabind only stores the iterator, not the vector itself. So I wanted to allocate a new vector with new, and use the adopt(result) policy, but the adopt policy only accepts pointers, so I can't use the result_stl_iterator and the adopt policy together. Maybe someone can provide a fix, because now there's apparently no way to pass a vector to Lua without a wrapper function? [Edited by - beun on September 10, 2009 12:53:40 PM]

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!