Lua スクリプトから C++ の関数を使うサンプル
#include <string>
#include <iostream>
#include <lua.hpp>
#include <luabind/luabind.hpp>
using namespace luabind;
using namespace std;
int main(int argc, char *argv[])
{
static_cast<void>(argc);
static_cast<void>(argv);
lua_State* lua = luaL_newstate();
luaL_openlibs(lua);
luabind::open(lua);
if (luaL_dofile(lua, "hello_function.lua")) {
string error_message = lua_tostring(lua, -1);
cout << "loadL_dofile: " << error_message << endl;
return 1;
}
try {
call_function<void>(lua, "hello");
} catch (const error &e) {
static_cast<void>(e);
cout << "hello(): " << lua_tostring(lua, -1) << endl;
}
return 0;
}