Sign in to follow this  
TonyFish

Strange Error

Recommended Posts

Hi, Could someone help me out here? I'm using luabind for the first time and despite that fact that my little test app works fine, I get a weird error message at the very end of the program (whilst returning 0). Am I missing something?
extern "C"
{
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
}
#include <luabind\luabind.hpp>
#include <luabind\adopt_policy.hpp>
#include <iostream>

using namespace std;
using namespace luabind;

lua_State* L_;

class baseclass
{
public:
	baseclass(const char* s)	{ std::cout << s << "\n"; }
	virtual void f(int a) { std::cout << "-f(" << a << ")\n"; }
};

struct baseclass_wrapper: baseclass
{
	luabind::object m_l;
	baseclass_wrapper(luabind::object l, const char* s): baseclass(s), m_l(l) {}

	virtual void f(int a) { call_member<void>(m_l, "f", a); }
	static void f_static(baseclass* ptr, int a)
	{
		return ptr->baseclass::f(a);
	}
};

int main()
{
    // Open Lua

    L_ = lua_open();
    
    // Prepare Luabind

    luabind::open(L_);
	luabind::module(L_)
	[
	class_<baseclass, baseclass_wrapper>("baseclass")
		.def(constructor<const char*>())
		.def("f", &baseclass_wrapper::f_static)
	];

    // Load required Lua libraries (optional)

    lua_baselibopen(L_);
    lua_iolibopen(L_);
    lua_strlibopen(L_);
    lua_mathlibopen(L_);
    
	// Invoke script (error handling omitted)
	lua_dofile(L_, "test.lua");
	/*
		class 'derived' (baseclass)

		function derived:__init() super('derived name')
		end

		function derived:f(num)
		print('overwritten');
		end

		function derived:print()
			print(30)
		end
	*/
	lua_dofile(L_, "test2.lua");
	/*
		d = derived('Hello');
		d:print();
		d:f(3);
	*/

	luabind::object my_class(luabind::get_globals(L_)["derived"]); 
	baseclass* p = luabind::object_cast<baseclass*>(my_class(), adopt(return_value)); 
	p->f(1);
    delete p;

	// Close Lua (Luabind shutsdown automatically)

    lua_close(L_);
	cin.get();
    return 0;
}
It seems to be connected somehow to the following statements although they do produce the desired effect.
luabind::object my_class(luabind::get_globals(L_)["derived"]);
baseclass* p = luabind::object_cast<baseclass*>(my_class(), adopt(return_value));
Many Thanks

Share this post


Link to post
Share on other sites
God I'm such a moron at times:

"Unhandled exception at 0x00488be4 in test.exe: 0xC0000005: Access violation reading location 0xfeeeff26." @ line 68 of ref.hpp

ew...

looks like I'm not going to get much help anyway..

[Edited by - TonyFish on August 5, 2004 11:40:37 AM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this