math.randomseed(os.time()) env = {} env.cli = true function env.loop() local command = env.stringSplit(io.read()," ",3,"\\") env.run(command) print("") end function env.run(command) local func = loadfile(basepath .. "/cmd/" ..command[1].. ".lua") func = func() env.rtn = func(command) return env.rtn end function env.xmlFindTags(xml,tag) local rtn = {} for i,v in ipairs(xml["children"]) do if v.tag == tag then table.insert(rtn,v) end end return rtn end function env.stringDate(d) return d.year .. "." ..env.padNumber(d.month,2).. "." ..env.padNumber(d.day,2).. "_" ..env.padNumber(d.hour,2).. ":" ..env.padNumber(d.min,2).. ":" ..env.padNumber(d.sec,2) end function env.makeUUID() local template ='xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx' return string.gsub(template, '[xy]', function (c) local v = (c == 'x') and math.random(0, 0x0f) or math.random(8, 0x0b) return string.format('%x', v) end) end function env.stringSplit(str, sep, limit, esc) local length = string.len(str) local index = 1 local c local escaped = false local entry = "" local rtn = {} local rtnLength = 0 while index <= length do c = string.sub(str,index,index) if escaped == false then if esc ~= nil then if c == esc then escaped = true else if c == sep then if limit > -1 and rtnLength < limit then table.insert(rtn,entry) entry = "" rtnLength = rtnLength + 1 else entry = entry .. c end else entry = entry .. c end end end else entry = entry .. c end index = index + 1 end table.insert(rtn,entry) return rtn end function env.padNumber(nr,len) nr = tostring(nr) local curLen = string.len(nr) while curLen < len do nr = "0" .. nr curLen = curLen + 1 end return nr end function env.cliprint(text) if env.cli == true then print(text) end end