You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
lunarium_OLD/src/scripting/coreAPI.cpp

61 lines
1.6 KiB
C++

/******************************************************************************
* File - coreAPI.cpp
* Author - Joey Pollack
* Date - 2021/09/23 (y/m/d)
* Mod Date - 2021/09/23 (y/m/d)
* Description - class with all static methods that expose core functionality to LUA
* Need an init function that takes a reference to a LUA state so that it
* can expose the static functions to LUA.
******************************************************************************/
#include "coreAPI.h"
#include "scriptManager.h"
#include <core/core.h>
#include <utils/logger.h>
namespace lunarium
{
CoreAPI* CoreAPI::mpInstance = nullptr;
CoreAPI& CoreAPI::GetInstance()
{
if (mpInstance == nullptr)
{
mpInstance = new CoreAPI;
}
return *mpInstance;
}
void CoreAPI::FreeInstance()
{
delete mpInstance;
mpInstance = nullptr;
}
OpRes CoreAPI::Initialize(ScriptManager& sman)
{
mCat = sman.mCat;
// Register methods
sman.mState["SetWindowSize"] = &CoreAPI::SetWindowSize;
sman.mState["Log"] = &CoreAPI::Log;
// return OpRes::Fail("CoreAPI::Initialize not implemented yet!");
return OpRes::OK();
}
////////////////////////////////////////////////////////////
// API
////////////////////////////////////////////////////////////
void CoreAPI::SetWindowSize(int w, int h)
{
Core::MainWindow().Resize(w, h);
}
void CoreAPI::Log(int level, const char* msg)
{
Logger::Log(mpInstance->mCat, level, msg);
}
}