Page 1 of 1

Luabind

Posted: Mon Nov 29, 2010 10:48 am
by N64vSNES
Well I've played with tolua++ and lua so I decided its time to play with luabind :D ( yay )

Anywayz the problem is I'm basicly trying to wrap what 'would' be a player class

Code: Select all

class Player {

public:

	~Player(){}

	static Player *GetInstance() {
		if ( MyInstance == NULL ) {
			MyInstance = new Player;
		}
		return MyInstance;
	}

	int GetHP(){ return HP; }
	void SetHP(int amount) { HP = amount; }

private:
	static Player* MyInstance;
	int HP;
	Player(){HP=0;}

};

Player *Player::MyInstance = NULL;
Its a singelton because I remember having issues wrapping static members to lua.

And this will compile AND run perfectly fine

Code: Select all

extern "C" {
   #include "lua.h"
   #include "lualib.h"
   #include "lauxlib.h"
}

#include <luabind/luabind.hpp>
#include <iostream>
#include <string>

class Player {

public:

	~Player(){}

	static Player *GetInstance() {
		if ( MyInstance == NULL ) {
			MyInstance = new Player;
		}
		return MyInstance;
	}

	int GetHP(){ return HP; }
	void SetHP(int amount) { HP = amount; }

private:
	static Player* MyInstance;
	int HP;
	Player(){HP=0;}

};

Player *Player::MyInstance = NULL;

int main() {

	lua_State *MyState;

	luaL_openlibs(MyState);
	luabind::open(MyState);

	using namespace std;

	/*luabind::module(MyState) [

		luabind::class_ <Player>("Player")
		.def("SetHP",&Player::SetHP)
		.def("GetHP",&Player::GetHP)

	];

	luabind::module(MyState) [

		luabind::def("GetPlayer",&Player::GetInstance)

	];*/

	std::string text;
	while(1) {
		system("cls");
		cout << Player::GetInstance()->GetHP();
		std::cin >> text;
		luaL_dostring(MyState,text.c_str());
	}

	return 0;
}

Code: Select all

/*luabind::module(MyState) [

		luabind::class_ <Player>("Player")
		.def("SetHP",&Player::SetHP)
		.def("GetHP",&Player::GetHP)

	];

	luabind::module(MyState) [

		luabind::def("GetPlayer",&Player::GetInstance)

	];*/
However if I uncomment this^ then I get a error ( at runtime of course ) saying MSVCR71.DLL is missing

Also these warnings appear

Code: Select all

Unknown compiler version - please run the configure tests and report the results
C:\Program Files\Microsoft Visual Studio 9.0\VC\include\luabind/detail/primitives.hpp(68) : warning C4996: 'std::copy': Function call with parameters that may be unsafe - this call relies on the caller to check that the passed values are correct. To disable this warning, use -D_SCL_SECURE_NO_WARNINGS. See documentation on how to use Visual C++ 'Checked Iterators'
        C:\Program Files\Microsoft Visual Studio 9.0\VC\include\xutility(2576) : see declaration of 'std::copy'
.....And I honestly thought it coudn't be much harder than tolua :/

Re: Luabind

Posted: Mon Nov 29, 2010 7:57 pm
by Trask
Not sure if this would help, but try going here: http://www.dll-files.com/msvcr71.zip?0VLdXGVDjT and extract the dll to your c:\windows\system32 directory. I've had that same error when trying to run various games and that seems to help. I've gotten the file from this same site as well, no viruses or anything of the sort.

Re: Luabind

Posted: Tue Nov 30, 2010 6:36 am
by N64vSNES
Trask wrote:Not sure if this would help, but try going here: http://www.dll-files.com/msvcr71.zip?0VLdXGVDjT and extract the dll to your c:\windows\system32 directory. I've had that same error when trying to run various games and that seems to help. I've gotten the file from this same site as well, no viruses or anything of the sort.
Thanks for the relpy.

I have been to that exact site to tried to add the DLL to both my system32 and my project directory, if I put it in my system32 then it can't find it at all, if I put it in my project directory then it complains its not got a valid windows signiture. :/

I'm going to keep trying though, any ideas about the warnings I'm getting?

EDIT:
Aparantly others have had issues with this too, boost dosen't like visual 2008 express....

Re: Luabind

Posted: Tue Nov 30, 2010 11:13 am
by Trask
Hm, trying going to your Start Menu -> Run and type in regsvr32 MSVCR71.DLL and hitting ok... it should pop up a message that it registered the DLL. You may have to reboot, but I don' t think it matters.