However, the problem was that the functions that I was trying to make available from C++ to Lua weren't being made available, and consequently nothing happened. I decided to go back to a simpler program in order to discover the heart of the problem. Unlike the example given in the aforementioned link, the function that I was trying to export to Lua was also a member of a class. I have a suspicion that that might be the cause of the issue. My guess is that there is a way of exporting functions in a class that I do not fully understand. Naturally, I wrapped my Lua functionality within a class, so I would do something like
luabind::def("print_hello", &hellos::print_hello)
... instead of the...
luabind::def("print_hello", print_hello)
... that was given in the example code. I have tried replacing print_hello with a function pointer, but nothing happens still. Does anybody with experience with LuaBind know what I might be doing wrong? Below is my complete code.
#include "stdafx.h"
extern "C" {
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
}
#include "luabind/luabind.hpp"
#include <luabind/function.hpp>
using namespace std;
class hellos {
protected:
lua_State *myLuaState;
void print_hello();
public:
hellos();
~hellos();
int hi;
void run();
};
void hellos::print_hello() {
cout << "Hello!";
}
void hellos::run() {
myLuaState = lua_open();
luaL_openlibs(myLuaState);
luabind::open(myLuaState);
luaL_loadfile(myLuaState, "factorial.lua");
luabind::module(myLuaState) [
luabind::def("print_hello", &hellos::print_hello)
];
luaL_dostring(myLuaState,"print_hello()\n");
lua_close(myLuaState);
int wait; cin >> wait;
}
int main() {
hellos *h = new hellos();
h->run();
delete h;
}
Thank you for your assistance. I am also using Lua 5.1 with LuaBind 0.9.