C++自定义脚本文件执行

发布时间:2026/11/2 10:42:19
C++自定义脚本文件执行 GitHub - Ma-Yuyao/Lexical-Analyzer-Syntactic-Analyzer: Lexical-Analyzer-Syntactic-Analyzer By C 编译原理C实现的词法分析器和语法分析器FunctionCall.h#include sstream #include string #include vector // 函数调用 class FunctionCall { public: FunctionCall(); ~FunctionCall(); std::string call(const std::string line); private: void parse(const std::string line); private: void call0(); void call1(); void call2(); void call3(); void call4(); void call5(); private: std::string funcname; std::vectorstd::string args; std::string result; };FunctionCall.cpp#include FunctionCall.h #include fstream #include iostream #include sstream #include vector FunctionCall::FunctionCall() {} FunctionCall::~FunctionCall() {} void PxxFunctionCall::parse(const std::string line) { std::istringstream iss(line); std::string tmp; bool isObject false; std::string objParam; while (std::getline(iss, tmp, ,)) { if (funcname.empty()) { funcname tmp; } else { while (!tmp.empty() tmp.front()) tmp.erase(tmp.begin()); while (!tmp.empty() tmp.back()) tmp.pop_back(); // obj{} 对象解析 if (tmp.starts_with(^)) { isObject true; // 进入对象解析 objParam tmp.substr(1); continue; } else if (isObject) { objParam , tmp; if (tmp.ends_with($)) { isObject false; objParam.pop_back(); tmp objParam; // 全部对象解析完成 } else { continue; } } args.emplace_back(tmp); } } } // 执行外部脚本 std::string FunctionCall::call(const std::string line) { parse(line); if(funcname.empty()) return invalid function; switch (args.size()) { case 0: { call0(); } break; case 1: { call1(); } break; case 2: { call2(); } break; case 3: { call3(); } break; case 4: { call4(); } break; case 5: { call5(); } break; default: { } break; } return result; } void FunctionCall::call0() { if(test funcname) std::cout run test std::endl; } void FunctionCall::call1() { } void FunctionCall::call2() { } void FunctionCall::call3() { } void FunctionCall::call4() { } void FunctionCall::call5() { }LocalScriptFile.h#include string class LocalScriptFile { public: bool doFile(const char *path); private: bool jumpComment(const std::string line); void doScript(const std::string line); private: bool m_isComment false; };LocalScriptFile.cpp#include LocalScriptFile.h #include FunctionCall.h #include fstream #include iostream #include sstream #include vector bool LocalScriptFile::jumpComment(const std::string line) { if(m_isComment) { if (-1 ! line.find(**/)) m_isComment false; return true; } else{ if (-1 ! line.find(/**)) m_isComment true; return m_isComment; } } bool LocalScriptFile::doFile(const char *path) { if (-1 ! std::string(path).rfind(.lua)) { std::ifstream file(path); if (!file.is_open()) { std::cerr Failed to open the file. std::endl; return false; } bool isComment false; std::string line; while (std::getline(file, line)) { // std::cout Read line: line std::endl; if(jumpComment(line)) continue; doScript(line); } file.close(); return true; } return false; } // 执行外部脚本 void LocalScriptFile::doScript(const std::string line) { FunctionCall call; std::stringstream logStream; logStream call.call(line) line; }test.luagetMissingListFont getFontMissingCount, PingFang SC, Medium missingFontListReplace, ^{newFont:{digests:[],family:Inter,style:Regular},oldFont:{digests:[],family:PingFang SC,style:Medium}}$使用示例#include LocalScriptFile.h void main() { PxxLocalScriptFile scriptFile; if(scriptFile.doFile(test.lua)) std::cout success std::endl; }创作不易小小的支持一下吧

关于本文作者

来自尧图内容编辑团队

尧图内容编辑团队 内容团队

尧图内容编辑团队

本文由尧图网络内容编辑团队执笔。团队由资深项目经理、前端工程师与设计师组成,所有内容均来自亲手交付的真实项目,先讲清问题、再给出可落地的解法。尧图深耕北京网站建设十年,服务过京华建材集团、智造科技等各行业客户,把一线经验沉淀为可复用的行业观察。

  • 十年建站经验,覆盖建材、制造、服务、文创等
  • 项目经理把关选题与事实准确性
  • 工程师与设计师联合撰写专业细节
  • 统一编辑规范,保证文风与排版一致
  • 每月复盘转化数据,迭代选题方向

延伸阅读

相关资讯与近期热门内容

深度阅读推荐

建站决策前值得细读的三篇

网站改版的5个关键决策
2024-08-12

网站改版的5个关键决策

什么时候该改版、改到什么程度、如何避免流量掉光,京华建材集团改版复盘给出答案。

获取专属建站方案

看完文章,把您的行业与预算告诉我们,免费获取一份量身定制的官网建设方案与报价。

立即免费咨询