直接上代码
//main.cpp
#include <iostream>
#include <lua.hpp>
#include <luabind/luabind.hpp>
extern "C"
{
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
}
bool LoadScript(lua_State* L, const std::string& fname)
{
if (luaL_dofile(L, fname.c_str()))
{
std::cerr << lua_tostring(L, -1) << std::endl;
return false;
}
return true;
}
class NumberPrinter
{
public:
NumberPrinter(int number) : m_number(number)
{
}
NumberPrinter()
{
m_number = 100;
}
void printNum()
{
std::cout << "C++ printNum" << std::endl;
std::cout << m_number << std::endl;
}
private:
int m_number;
};
int main(int argc, char* argv[])
{
lua_State* L = luaL_newstate();
luaL_openlibs(L);
luabind::open(L);
luabi