mirror of
https://github.com/edubart/otclient.git
synced 2025-10-15 12:04:55 +02:00
Refactoring and flexibility changes
* Split game module into game and game_interface * Move core_lib to corelib * Move miniwindow to corelib * Introduce init.lua script for initializing the client, giving much more flexibility * OTClient is no longer Application derived and is much simpler
This commit is contained in:
6
modules/corelib/ext/os.lua
Normal file
6
modules/corelib/ext/os.lua
Normal file
@@ -0,0 +1,6 @@
|
||||
function os.execute(command)
|
||||
local f = assert(io.popen(command, 'r'))
|
||||
local data = assert(f:read('*a'))
|
||||
f:close()
|
||||
print(data)
|
||||
end
|
45
modules/corelib/ext/string.lua
Normal file
45
modules/corelib/ext/string.lua
Normal file
@@ -0,0 +1,45 @@
|
||||
function string.split(s, delim)
|
||||
local start = 1
|
||||
local results = {}
|
||||
while true do
|
||||
local pos = string.find(s, delim, start, true)
|
||||
if not pos then
|
||||
break
|
||||
end
|
||||
table.insert(results, string.sub(s, start, pos-1))
|
||||
start = pos + string.len(delim)
|
||||
end
|
||||
table.insert(results, string.sub(s, start))
|
||||
table.removevalue(results, '')
|
||||
return results
|
||||
end
|
||||
|
||||
function string.starts(s, start)
|
||||
return string.sub(s, 1, #start) == start
|
||||
end
|
||||
|
||||
function string.trim(s)
|
||||
return string.match(s, '^%s*(.*%S)') or ''
|
||||
end
|
||||
|
||||
function string.explode(str, sep, limit)
|
||||
if(type(sep) ~= 'string' or tostring(str):len() == 0 or sep:len() == 0) then
|
||||
return {}
|
||||
end
|
||||
|
||||
local i, pos, tmp, t = 0, 1, "", {}
|
||||
for s, e in function() return string.find(str, sep, pos) end do
|
||||
tmp = str:sub(pos, s - 1):trim()
|
||||
table.insert(t, tmp)
|
||||
pos = e + 1
|
||||
|
||||
i = i + 1
|
||||
if(limit ~= nil and i == limit) then
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
tmp = str:sub(pos):trim()
|
||||
table.insert(t, tmp)
|
||||
return t
|
||||
end
|
57
modules/corelib/ext/table.lua
Normal file
57
modules/corelib/ext/table.lua
Normal file
@@ -0,0 +1,57 @@
|
||||
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.selectivecopy(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
|
||||
|
||||
function table.find(t, value)
|
||||
for k,v in pairs(t) do
|
||||
if v == value then return k end
|
||||
end
|
||||
end
|
||||
|
||||
function table.removevalue(t, value)
|
||||
for k,v in pairs(t) do
|
||||
if v == value then
|
||||
table.remove(t, k)
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function table.compare(t, other)
|
||||
if #t ~= #other then return false end
|
||||
for k,v in pairs(t) do
|
||||
if v ~= other[k] then return false end
|
||||
end
|
||||
return true
|
||||
end
|
Reference in New Issue
Block a user