-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.lua
More file actions
62 lines (52 loc) · 939 Bytes
/
utils.lua
File metadata and controls
62 lines (52 loc) · 939 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
utils = utils or {}
local ffi = require 'ffi'
ffi.cdef[[
void Sleep(uint32_t dwMilliseconds);
]]
utils.sleep = function(ms)
ffi.C.Sleep(ms)
end
utils.bag = function()
local o = {}
local t = {}
local currentIndex = 0
local toBeRemoved = {}
o.insert = function(v)
t[currentIndex] = v
currentIndex = currentIndex + 1
end
o.iter = function()
local index, value
return function()
index, value = next(t,index)
return index, value
end
end
o.remove = function(i)
table.insert(toBeRemoved, i)
end
o.clear = function()
t = {}
toBeRemoved = {}
end
o.process = function()
for _, index in ipairs(toBeRemoved) do
t[index] = nil
end
toBeRemoved = {}
end
return o
end
local console = require 'console'
local con
function printC(color, fmt, ...)
if not con then
con = console.prepare()
end
con.attr(color or 0x07)
if #({...})>0 then
io.write(fmt:format(...))
else
io.write(fmt)
end
end