Luabind

Anything related in any way to game development as a whole is welcome here. Tell us about your game, grace us with your project, show us your new YouTube video, etc.

Moderator: PC Supremacists

Post Reply
N64vSNES
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 632
Joined: Thu Aug 12, 2010 11:25 am

Luabind

Post 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 :/
User avatar
Trask
ES Beta Backer
ES Beta Backer
Posts: 738
Joined: Wed Oct 29, 2008 8:17 pm
Current Project: Building a 2D Engine
Favorite Gaming Platforms: Sega Genesis and Xbox 360
Programming Language of Choice: C/C++
Location: Pittsburgh, PA
Contact:

Re: Luabind

Post 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.
MarauderIIC wrote:You know those people that are like "CHECK IT OUT I just made Linux run on this piece of celery [or other random object]!!"? Yeah, that's Falco, but with ES.
Dear god, they actually ported ES to a piece of celery!
Martin Golding wrote: "Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live."
N64vSNES
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 632
Joined: Thu Aug 12, 2010 11:25 am

Re: Luabind

Post 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....
User avatar
Trask
ES Beta Backer
ES Beta Backer
Posts: 738
Joined: Wed Oct 29, 2008 8:17 pm
Current Project: Building a 2D Engine
Favorite Gaming Platforms: Sega Genesis and Xbox 360
Programming Language of Choice: C/C++
Location: Pittsburgh, PA
Contact:

Re: Luabind

Post 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.
MarauderIIC wrote:You know those people that are like "CHECK IT OUT I just made Linux run on this piece of celery [or other random object]!!"? Yeah, that's Falco, but with ES.
Dear god, they actually ported ES to a piece of celery!
Martin Golding wrote: "Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live."
Post Reply