mirror of
https://github.com/edubart/otclient.git
synced 2025-10-14 11:34:54 +02:00
reorganize some stuff
This commit is contained in:
26
modules/core_lib/ext/string.lua
Normal file
26
modules/core_lib/ext/string.lua
Normal file
@@ -0,0 +1,26 @@
|
||||
function string:split(sep)
|
||||
local t = { }
|
||||
local function helper(word)
|
||||
table.insert(t, word)
|
||||
return ""
|
||||
end
|
||||
if not self:gsub("%w+", helper):find("%S") then
|
||||
return t
|
||||
end
|
||||
end
|
||||
|
||||
function string:starts(start)
|
||||
return self:sub(1, #start) == start
|
||||
end
|
||||
|
||||
function string:trim()
|
||||
return self:match('^%s*(.*%S)') or ''
|
||||
end
|
||||
|
||||
function toboolean(str)
|
||||
str = str:trim()
|
||||
if str == '1' or str == 'true' then
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
34
modules/core_lib/ext/table.lua
Normal file
34
modules/core_lib/ext/table.lua
Normal file
@@ -0,0 +1,34 @@
|
||||
function table.dump(t, depth)
|
||||
if not depth then depth = 0 end
|
||||
for k,v in pairs(t) do
|
||||
str = (' '):rep(depth * 2) .. k .. ': '
|
||||
if type(v) ~= "table" then
|
||||
print(str .. tostring(v))
|
||||
else
|
||||
print(str)
|
||||
table.dump(v, depth+1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function table.copy(t)
|
||||
local res = {}
|
||||
for k,v in pairs(t) do
|
||||
res[k] = v
|
||||
end
|
||||
return res
|
||||
end
|
||||
|
||||
function table.selective_copy(t, keys)
|
||||
local res = { }
|
||||
for i,v in ipairs(keys) do
|
||||
res[v] = t[v]
|
||||
end
|
||||
return res
|
||||
end
|
||||
|
||||
function table.merge(t, src)
|
||||
for k,v in pairs(src) do
|
||||
t[k] = v
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user