Lua调用脚本文件(不存在则新建脚本文件)
1.代码
local status, calParaFun = pcall(require, calParaFileName) if not status then -- 如果模块加载失败则创建脚本文件 local file = io.open(calParaFileName..".lua", "w") if file then file:write("-- 计算参数:"..name.."\n".. "local ModuleInputParas = require('InputPara/InputParas')\n".. "local ModulePublicParas = require('PublicPara/PublicParas')\n".. "local function exec()\n".. " return nil\n".. "end\n".. "return exec\n" ) file:close() else print("无法创建公共参数拟合算法文件") end else -- 如果模块加载成功则执行需要的操作 print("old", name, publicParas[name]) end
长风破浪会有时,直挂云帆济沧海!
可通过下方链接找到博主
https://www.cnblogs.com/judes/p/10875138.html