Skip to main content
GameDev.net gamedev.net
🔒 Locked

luabind does not work with classes

Started by Filami Sep 18, 2005 at 11:25 AM 1 replies 1.6k views
Original Post
Filami
Filami
Hello ppl. I have just downloaded and builded luabind beta 6 in VS.NET2003. There was some errors abound the apply_if that was corrected by changing them to eval_if. But, when I test the lib to see if everything is fine, it just craches when I try to use classes. Can anyone tell me what is going on? here it is the test code that craches:

#include <string>
#include <iostream>
using namespace std;
extern "C"{
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
}
#include <luabind/luabind.hpp>
using namespace luabind;
#pragma comment(lib, "lualib.lib")
#pragma comment(lib, "luabind.lib")



string GetCommand(){
	char s[513];
	cin.getline(s, 512);
	return s;
}


string Escrever(int a){
	cout<<"Funcao ligada a lua atravez do luabind "<<a<<endl;
	return "Funcao ligada a lua atravez do luabind\n";
}

class testclass
{
public:
	testclass(const std::string& s): m_string(s) {}
	void print_string() { std::cout << m_string << "\n"; }
private:
	std::string m_string;
};


int main(){
	lua_State* vm = lua_open();
	lua_baselibopen(vm);
	lua_iolibopen(vm);
	lua_strlibopen(vm);
	lua_mathlibopen(vm);

	function(vm, "Escrever", &Escrever);
	class_<Vector>(vm, "testclass").def(constructor<>());

	do{
		cout<<"  > ";
		string command = GetCommand();
		lua_dostring(vm, command.c_str());
	}while(true);

	lua_close(vm);
	return 0;
}
and it craches here: "Unhandled exception at 0x0041ec97 in LuaBindTest.exe: 0xC0000005: Access violation reading location 0x00000010." class_rep.cpp : ln 88
Techno Grooves
Ludi83
Ludi83
Take a look at here: http://www.lunaticsystems.com/index.php?module=articles&func=display&aid=45&ptid=2

A little introduction to Luabind and precompiled libs.

Perhaps this can help you.


You forgot to bind luabind to lua (lol, great sentence :))

luabind::open(vm)
Filami
Filami
Really thanks. I thinck I'm done. Seems I will like this lib a lot :)
Techno Grooves

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.