Luabind
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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