This commit is contained in:
aozhiwei 2023-03-04 12:09:37 +08:00
parent f1902a4289
commit e161c89e03
3 changed files with 33 additions and 6 deletions

View File

@ -16,12 +16,12 @@ public:
"getSkillNumber", "getSkillNumber",
[this] (const a8::lisp::List& params) -> std::shared_ptr<a8::lisp::Value> [this] (const a8::lisp::List& params) -> std::shared_ptr<a8::lisp::Value>
{ {
a8::lisp::Atom result; double result = 0;
if (params->size() != 1) { if (params->size() != 1) {
abort(); abort();
} }
result.val = context_.skill_meta->_number_meta->_float_speed; result = context_.skill_meta->_number_meta->_float_speed;
return std::make_shared<a8::lisp::Value>(result); return std::make_shared<a8::lisp::Value>(a8::lisp::Atom(result));
}); });
} }
@ -32,8 +32,19 @@ public:
context_.c = c; context_.c = c;
context_.skill_meta = skill_meta; context_.skill_meta = skill_meta;
auto result = a8::lisp::Expr::Eval(expr, shared_from_this());
context_.c = nullptr; context_.c = nullptr;
context_.skill_meta = nullptr; context_.skill_meta = nullptr;
if (!result) {
abort();
}
if (!result->IsType(a8::lisp::ValueType::kAtom)) {
abort();
}
auto&& atom = std::any_cast<a8::lisp::Atom>(result->value);
return atom.val;
} }
std::shared_ptr<a8::lisp::Value> Compile(const std::string& script) std::shared_ptr<a8::lisp::Value> Compile(const std::string& script)
@ -58,6 +69,18 @@ public:
abort(); abort();
} }
auto func_call_exprs = std::make_shared<a8::lisp::List::element_type>(); auto func_call_exprs = std::make_shared<a8::lisp::List::element_type>();
{
auto cproc = Find("getSkillNumber");
if (!cproc) {
abort();
}
if (!cproc->IsType(a8::lisp::ValueType::kCProc)) {
abort();
}
func_call_exprs->push_back(cproc);
func_call_exprs->push_back
(std::make_shared<a8::lisp::Value>(a8::lisp::Atom(idx)));
}
node->Assign(func_call_exprs); node->Assign(func_call_exprs);
} else if (node->IsType(a8::lisp::ValueType::kList)) { } else if (node->IsType(a8::lisp::ValueType::kList)) {
@ -79,7 +102,8 @@ private:
void LispEnv::Init() void LispEnv::Init()
{ {
skill_env_ = std::make_shared<SkillScope>();
skill_env_->Init();
} }
void LispEnv::UnInit() void LispEnv::UnInit()

View File

@ -112,7 +112,10 @@ namespace mt
int SkillNumber::GetAttrIdxByName(const std::string& name) int SkillNumber::GetAttrIdxByName(const std::string& name)
{ {
if (name == "${skillNumber.speed}") {
return 0;
}
return -1;
} }
} }

2
third_party/a8 vendored

@ -1 +1 @@
Subproject commit b075c000c2c52a674bb7c27a398dc3a795b40d8f Subproject commit 24625f05d1636709680b03de74b60d2b4736d7d5