-- 获取源文件信息 local handle = io.popen("cd") local script_dir if handle then script_dir = handle:read("*a"):gsub("[\r\n]+$", "") handle:close() end print(jit and jit.arch or "unknown") -- 设置脚本目录 --package.path = package.path .. ";./bin/;./jx/?.lua;./jx_base/?.lua;./mobox_base/?.lua;./wms/?.lua;./wms_base/?.lua;" -- 动态获取当前脚本目录(关键!) --local script_dir = debug.getinfo(1, "S").source:match("@?(.*/)") print("当前脚本所在的目录是: " .. script_dir) -- 重置 package.path(避免旧路径干扰) package.path = "" package.path = package.path .. ";" .. script_dir .. "/?.lua" -- 添加必要路径(使用正确的模板格式) package.path = package.path .. ";" .. script_dir .. "/bin/?.lua" .. -- 子目录 bin ";" .. script_dir .. "/lualibs/?.lua" .. -- 子目录 bin ";" .. script_dir .. "/lua/00-Factory/?.lua" .. ";" .. script_dir .. "/wms/?.lua" .. ";" .. script_dir .. "/lualibs/xml2lua-master/?.lua" .. ";" .. script_dir .. "/wms_base/?.lua".. ";" .. script_dir .. "/mobox_base/?.lua" -- 添加 C 模块搜索路径(针对 Windows 的 .dll 文件) package.cpath = package.cpath .. ";" .. script_dir .. "/bin/clibs/?.dll".. ";" .. script_dir .. "/bin/clibs/socket/?.dll" local xml = require("LuaXML_lib") local xml_str = "test" local xml_tree = xml.eval(xml_str) print(getmetatable(xml_tree).__index.find) -- 若输出 nil,则元表未绑定方法 -- 获取 XML 树的元表 local mt = getmetatable(xml_tree) if mt then mt.__index.find = function(self, tag) -- 递归遍历 XML 树,查找指定标签 for i, child in ipairs(self) do if child.tag == tag then -- 假设标签名存储在 child.tag 字段 return child end -- 递归查找子节点 local found = child:find(tag) if found then return found end end return nil end end -- 获取根标签名 local root_tag = xml_tree[0] print("根标签名:", root_tag) -- 输出 "root" -- 获取根节点下的第一个子节点 local first_child = xml_tree[1] print("子节点标签:", first_child[0]) -- 输出 "item" print("子节点内容:", first_child[1]) -- 输出 "test" -- 通过 find 方法查询根节点 local root_node = xml_tree:find("root") if root_node then for i, child in ipairs(root_node:children()) do print("子节点内容:", child[1]) end end --local cjson = require("cjson") local json = require("json") -- 递归转换 XML 节点为 Lua 表 function xml_to_table(node) local result = {} -- 提取标签名(假设存储在索引0) result.tag = node[0] -- 提取属性(假设存储在 `.attr` 字段) if node.attr then result.attributes = node.attr end -- 处理子节点和文本内容 result.children = {} for i = 1, #node do local child = node[i] if type(child) == "table" then table.insert(result.children, xml_to_table(child)) else -- 处理文本内容 result.text = child end end return result end -- 示例:转换 XML 树为 JSON local lua_table = xml_to_table(xml_tree) local json_str = json.encode(lua_table) print(json_str) print("1") http = require("socket.http") print("2") ltn12 = require("ltn12") url = require("socket.url") print("3") -- 加载模块 wms = require ("OILua_WMS") mobox = require("OILua_JavelinExt") local wms_base = require("wms_base") -- 需要调试的脚本 require("Inbound_Sync") local strLuaDEID = "{8755C06B-CC0D-44FE-A62C-96954F3B716B}" local nRet -- 启动事务 mobox.startTransaction( strLuaDEID ) -- 调试脚本的入口函数 nRet = Inbound_Sync( strLuaDEID ) if ( nRet == 0 ) then mobox.commit(strLuaDEID) else mobox.abort(strLuaDEID) end print( "OK" )