Strange Error

Started by
3 comments, last by Krumble 19 years, 8 months ago
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
<Fish>{
Advertisement
What is the error message that you recieve? You won't be able to get much help unless you tell us that.

Chris 'coldacid' Charabaruk – Programmer, game designer, writer | twitter

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]
<Fish>{
Yeah, because I haven't a clue for what's at 0x00488be4. Sorry.

Chris 'coldacid' Charabaruk – Programmer, game designer, writer | twitter

Should you be deleting p?

I've never really used lua so I can't really be more help than that.
Kevin.

This topic is closed to new replies.

Advertisement