diff options
| author | ruki <[email protected]> | 2025-11-15 21:46:29 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2025-11-15 21:46:29 +0800 |
| commit | b250c84aee0072ff92b73fe41403d364f95a03d5 (patch) | |
| tree | 594f1d0be9df3618b48cf734286998483f0895f0 | |
| parent | 88b0fb7c39cd6b867cdde29fd195f5f2c49b62d7 (diff) | |
update xml api
| -rw-r--r-- | tests/modules/xml/test.lua | 4 | ||||
| -rw-r--r-- | xmake/core/base/xml.lua | 8 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/base/xml.lua | 8 |
3 files changed, 10 insertions, 10 deletions
diff --git a/tests/modules/xml/test.lua b/tests/modules/xml/test.lua index 41c56c867..4358762fd 100644 --- a/tests/modules/xml/test.lua +++ b/tests/modules/xml/test.lua @@ -80,8 +80,8 @@ function test_load_save(t) attrs = {id = "1"}, children = {xml.text("hello")} }) - assert(xml.save(filepath, doc, {pretty = true})) - local reloaded = xml.load(filepath) + assert(xml.savefile(filepath, doc, {pretty = true})) + local reloaded = xml.loadfile(filepath) t:are_equal(reloaded.name, "root") t:are_equal(xml.text_of(reloaded), "hello") os.tryrm(filepath) diff --git a/xmake/core/base/xml.lua b/xmake/core/base/xml.lua index 7dc0025b8..5e7282e97 100644 --- a/xmake/core/base/xml.lua +++ b/xmake/core/base/xml.lua @@ -781,13 +781,13 @@ function xml.encode(node, opt) end -- load xml file --- e.g. `local doc, err = xml.load("foo.xml")` +-- e.g. `local doc, err = xml.loadfile("foo.xml")` -- -- @param filepath file path -- @param opt read/decode options -- @return node or nil + error -- -function xml.load(filepath, opt) +function xml.loadfile(filepath, opt) local data, err = io.readfile(filepath, opt) if not data then return nil, err @@ -796,14 +796,14 @@ function xml.load(filepath, opt) end -- save xml node to file --- e.g. `assert(xml.save("foo.xml", node, {pretty = true}))` +-- e.g. `assert(xml.savefile("foo.xml", node, {pretty = true}))` -- -- @param filepath destination file -- @param node xml node -- @param opt encode/write options -- @return true on success or nil + error message -- -function xml.save(filepath, node, opt) +function xml.savefile(filepath, node, opt) local data = xml.encode(node, opt) if not data then return nil, "failed to encode xml" diff --git a/xmake/core/sandbox/modules/import/core/base/xml.lua b/xmake/core/sandbox/modules/import/core/base/xml.lua index 1aed8b159..fdfe8318a 100644 --- a/xmake/core/sandbox/modules/import/core/base/xml.lua +++ b/xmake/core/sandbox/modules/import/core/base/xml.lua @@ -55,8 +55,8 @@ function sandbox_core_base_xml.scan(data, callback, opt) end -- load xml file to the lua table -function sandbox_core_base_xml.load(filepath, opt) - local node, errors = xml.load(filepath, opt) +function sandbox_core_base_xml.loadfile(filepath, opt) + local node, errors = xml.loadfile(filepath, opt) if not node then raise(errors) end @@ -64,8 +64,8 @@ function sandbox_core_base_xml.load(filepath, opt) end -- save xml node to the file -function sandbox_core_base_xml.save(filepath, node, opt) - local ok, errors = xml.save(filepath, node, opt) +function sandbox_core_base_xml.savefile(filepath, node, opt) + local ok, errors = xml.savefile(filepath, node, opt) if not ok then raise(errors) end |
