Zepha/zeus/lua_api/LuaParser.cpp
aurailus 67b3a5086e LuaParser class which loads a Lua File.
LuaApiInterface header that is overrided by Lua api functions
l_Average class to test LuaApiInterface
2018-12-17 20:05:00 -08:00

42 lines
923 B
C++

//
// Created by aurailus on 17/12/18.
//
#include <iostream>
#include "LuaParser.h"
#include "apis/l_Average.h"
LuaParser::LuaParser(std::string luaFileLoc) {
L = luaL_newstate();
luaL_openlibs(L);
regGlobalModule();
int err = luaL_dofile(L, luaFileLoc.c_str());
if (err != 0) {
std::cerr << "Failed to compile " << luaFileLoc << " with error code " << err << "." << std::endl;
std::cerr << lua_tostring(L, -1) << std::endl;
luaL_traceback(L, L, nullptr, 1);
std::cerr << lua_tostring(L, -1) << std::endl;
}
getchar(); // Just to pause
}
void LuaParser::regFunc(const char *functionName, lua_CFunction any) {
lua_pushcfunction(L, any);
lua_setfield(L, -2, functionName);
}
void LuaParser::regGlobalModule() {
lua_newtable(L);
l_Average().bind_methods(this);
lua_setglobal(L, "zeus");
}
LuaParser::~LuaParser() {
lua_close(L);
}