Luabind
Posted: Mon Nov 29, 2010 10:48 am
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
Its a singelton because I remember having issues wrapping static members to lua.
And this will compile AND run perfectly fine
However if I uncomment this^ then I get a error ( at runtime of course ) saying MSVCR71.DLL is missing
Also these warnings appear
.....And I honestly thought it coudn't be much harder than tolua :/
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;
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)
];*/
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'