Skip to content

Instantly share code, notes, and snippets.

@xkyii
Created November 25, 2011 04:00
Show Gist options
  • Save xkyii/1392781 to your computer and use it in GitHub Desktop.
Save xkyii/1392781 to your computer and use it in GitHub Desktop.
Luabind
#include <luabind/luabind.hpp>
#pragma comment(lib,"libluabindd.lib")
#pragma comment(lib,"lua51.lib")
#include <iostream>
using namespace std;
using namespace luabind;
class testlua
{
public:
testlua(std::string s):m_str(s){};
void myprint()
{
cout << m_str << endl;
}
void setstr(std::string s){ m_str = s;};
private:
std::string m_str;
};
int _tmain(int argc, _TCHAR* argv[])
{
lua_State *L = luaL_newstate();
luabind::open(L);
module(L)
[
class_<testlua>("testlua")
.def(constructor<const std::string>())
.def("myprint",&testlua::myprint)//开放这两个函数给lua使用
.def("setstr", &testlua::setstr)
];
luaL_dofile(L,"test.lua");
lua_close(L);
getchar();
return 0;
}
local a = testlua("hello lua!");
a:myprint();
a:setstr("yes lua!");
a:myprint();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment