资讯详情

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

📅 2026/11/2 10:42:18 | 华诺云谱 👁 阅读
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; }创作不易小小的支持一下吧
📝

华诺云谱内容团队

资深建站顾问 · 行业研究员

10年+企业数字化服务经验,专注智能建站、SEO优化与品牌营销,持续输出建站技巧、行业洞察与营销干货,已帮助5000+企业实现数字化增长。

你可能需要的服务

订阅华诺云谱资讯周报

每周一封,精选建站技巧、SEO与营销干货,直达邮箱。已有 8,000+ 企业主订阅,助你少走弯路。

↑