I write my own log module and have a problem. When i'm trying to open file, LOVE crashes, and i got Windows message "checks for a solution" (or some about, i have russian locale) and no LOVE errors. I put "--" before lines and fugure that LOVE crashes at love.filesystem.newFile in logger.lua. I tryed different file names, project names, LOVE versions... I don't know what's wrong. Please, help.
main.lua
Code: Select all
--
function love.load(arg)
log=require("luas.logger")
log.init("109",2) -- i tryed log.txt, log and 109
log.start()
log.add("eng","Engine",1)
log.put("eng","Hello World!")
log.stop()
--screen prepare
game=require("luas.game")
game:init()
love.mousepressed = game.mousepressed
love.mousereleased = game.mousereleased
love.mousemoved = game.mousemoved
love.keypressed = game.keypressed
love.keyreleased = game.keyreleased
love.update = game.update
love.draw = game.draw
end
Code: Select all
local log={}
local file=nil
local level=0 -- 0 - no log, 1 - engine msgs 2 - modes msgs, 3 - container msgs, 4+ - objs msgs
local enabled=false
local list={}
function log.init(fn,l)
file=love.filesystem.newFile(fn) -- HERE I GOT CRASH
file:open("w")
level=l
log.add(log,"Logger",1)
end
function log.start()
enabled=level>0 and file
if enabled then
log.put(log,"Started")
end
end
function log.stop()
enabled=false
log.put(log,"Stoped")
end
function log.add(obj,name,lvl)
if lvl>=1 and lvl<=level and type(name)=="string" then
list[obj]=name
end
end
function log.del(obj)
list[obj]=nil
end
function log.put(obj,...)
if enabled and list[obj] then
s=os.date("%T").." "..list[obj]..":"
for i,v in ipairs(...) do
s=s.." "..tostring(v)
end
s=s.."\n"
file:write(s)
end
end
return log