#include <iostream>
#include <stdlib.h>
#include <string>
extern "C"
{
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
}
#include <luabind/luabind.hpp>
#pragma comment(lib,"lua51.lib")
#pragma comment(lib,"luabind_debug.lib")
using namespace std;
void Output(int number)
{
cout << "hello world " << number << endl;
}
int main()
{
lua_State *myLuaState = lua_open();
luabind::open(myLuaState);
// 添加函数到Lua环境中
luabind::module(myLuaState) [
luabind::def("hello", Output)
];
luaL_dostring(
myLuaState,
"hello(123) "
);
lua_close(myLuaState);
_sleep(1234);
}
使用lua绑定c++函数