Basically, I just want to be able to have a clean Lua instance made inside of my Manager class, then export the functions in the class to Lua, so that I can call functions on the already created C++ class inside of Lua.
This is the current way I am looking at solving the issue. It compiles but nothing happens in Lua.
Does anyone know what I am doing wrong, or does anyone have any other suggestions?
Manager.lua
newObject("Object", 1234)
printAll()
Manager.h
#ifndef MANAGER_H
#define MANAGER_H
#include <iostream>
#include <vector>
#include <string>
extern "C"
{
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
}
#include "luabind/luabind.hpp"
#include "Object.h"
class Manager
{
private :
lua_State *L;
std::vector<Object> obj;
public :
Manager();
void newObject(std::string t, int nm);
void printAll();
};
#endif
Manager.cpp
#include "Manager.h"
Manager::Manager()
{
luabind::open(L);
luabind::module(L) [
luabind::class_<Manager>("Manager")
.def(luabind::constructor<>())
.def("newObject", &Manager::newObject)
];
luaL_dofile(L, "Manager.lua");
}
void Manager::newObject(std::string t, int nm)
{
if(t == "Object")
{
Object object(nm);
obj.push_back(object);
}
}
void Manager::printAll()
{
for(unsigned int i = 0; i < obj.size(); i++)
std::cout << obj[i].getNum() << std::endl;
}