Skip to content

Commit

Permalink
feat: support pass parameter to new function
Browse files Browse the repository at this point in the history
  • Loading branch information
Crazyokd committed Feb 23, 2025
1 parent d91562d commit a5bf67e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 4 additions & 1 deletion luaxml.lua
Original file line number Diff line number Diff line change
Expand Up @@ -526,13 +526,16 @@ end

-- public API
-- alloc a new luaxml object
function luaxml.new()
function luaxml.new(str)
local lx = {}
lx.mememto = {}
setmetatable(lx, luaxml)
-- for anyone who want to use lx as a metatable
lx.__index = luaxml
lx.xt = {}
if str then
lx:load(str)
end
return lx
end

Expand Down
3 changes: 1 addition & 2 deletions test2.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ local xml = f:read("a")
f:close()

local lxml = require "luaxml"
local lx1 = lxml.new()
local lx1 = lxml.new(xml)

lx1:load(xml)
-- print_r(lx1.xt)
print(lx1)
lx1:save('test2.xml')

0 comments on commit a5bf67e

Please sign in to comment.