112 lines
3.3 KiB
C++
112 lines
3.3 KiB
C++
#include <a8/a8.h>
|
|
#include <a8/pyengine.h>
|
|
#include <a8/udplog.h>
|
|
|
|
#include "scriptengine.h"
|
|
|
|
namespace f8
|
|
{
|
|
void ScriptEngine::Init()
|
|
{
|
|
#if 0
|
|
engine_ = new a8::PyEngine();
|
|
if (getenv("is_dev_env")) {
|
|
engine_->work_path = "/var/data/conf_test/game1008/res/pyscripts/";
|
|
} else {
|
|
engine_->work_path = "../config/res/pyscripts/";
|
|
}
|
|
engine_->Init();
|
|
if (!engine_->IsInitialized()) {
|
|
abort();
|
|
}
|
|
#endif
|
|
}
|
|
|
|
void ScriptEngine::UnInit()
|
|
{
|
|
#if 0
|
|
engine_->UnInit();
|
|
delete engine_;
|
|
engine_ = nullptr;
|
|
#endif
|
|
}
|
|
|
|
void ScriptEngine::Update()
|
|
{
|
|
}
|
|
|
|
bool ScriptEngine::LoadModule(const std::string& module_name)
|
|
{
|
|
#if 1
|
|
return false;
|
|
#else
|
|
bool ret = engine_->LoadModule(module_name.c_str());
|
|
if (!ret) {
|
|
a8::UdpLog::Instance()->Warning("load python module %s error %s\n",
|
|
{
|
|
module_name,
|
|
engine_->GetLastError()
|
|
});
|
|
assert(false);
|
|
}
|
|
return ret;
|
|
#endif
|
|
}
|
|
|
|
bool ScriptEngine::LoadString(const std::string& str)
|
|
{
|
|
#if 1
|
|
return true;
|
|
#else
|
|
bool ret = engine_->ExecString(str.c_str());
|
|
if (!ret) {
|
|
a8::UdpLog::Instance()->Warning("load python string %s error %s",
|
|
{
|
|
str,
|
|
engine_->GetLastError()
|
|
});
|
|
assert(false);
|
|
}
|
|
return ret;
|
|
#endif
|
|
}
|
|
|
|
std::tuple<bool, a8::XValue> ScriptEngine::CallGlobalFunc(const char* func_name,
|
|
std::initializer_list<a8::XValue> args)
|
|
{
|
|
#if 1
|
|
return std::tuple<bool, a8::XValue>();
|
|
#else
|
|
auto ret = engine_->CallGlobalFunc(func_name, args);
|
|
if (!std::get<0>(ret)) {
|
|
a8::UdpLog::Instance()->Warning("call global function %s error %s",
|
|
{
|
|
func_name,
|
|
engine_->GetLastError()
|
|
});
|
|
}
|
|
return ret;
|
|
#endif
|
|
}
|
|
|
|
std::tuple<bool, a8::XValue> ScriptEngine::CallModuleFunc(const char* module_name,
|
|
const char* func_name,
|
|
std::initializer_list<a8::XValue> args)
|
|
{
|
|
#if 1
|
|
return std::tuple<bool, a8::XValue>();
|
|
#else
|
|
auto ret = engine_->CallModuleFunc(module_name, func_name, args);
|
|
if (!std::get<0>(ret)) {
|
|
a8::UdpLog::Instance()->Warning("call module function [%s] %s error %s",
|
|
{
|
|
module_name,
|
|
func_name,
|
|
engine_->GetLastError()
|
|
});
|
|
}
|
|
return ret;
|
|
#endif
|
|
}
|
|
}
|