Page 1 of 1

simple log library crashes love without notice

Posted: Sun Jun 10, 2018 9:00 am
by uiblob
Hi,

just getting started with love, but I have an error I don't know how to debug. :|

The game simply crashes without any errors. How can I debug this? What am I doing wrong? :?

Greetings
Karl

Here is the code of my lib
dlog.love
(895 Bytes) Downloaded 149 times
debuglog.lua

Code: Select all

if ddebuglog then
   love.filesystem.write ("log", "Started")
end

local dlog = {}

local function logwrite (sign, message)
   if ddebuglog then
      local timestamp = os.date("%F-%R:%S")
      local msgstring = string.format ("(%s) %s %s", sign, timestamp, message)

      love.filesystem.append("log", msgstring)
   end
end

function dlog.error (message)
   logwrite("E", message)
end

function dlog.info (message)
   logwrite("I", message)
end

dlog.info("Log init done.")

return dlog
main.lua

Code: Select all

love.filesystem.createDirectory(love.filesystem.getSaveDirectory())

ddebuglog = true

local dlog = require "debuglog"

dlog.info("hi")

function love.draw()
	love.graphics.print("hi")
end
conf.lua

Code: Select all

function love.conf(t)
   t.identity = logtest          -- The name of the save directory (string)
   t.console = true
end

Re: simple log library crashes love without notice

Posted: Sun Jun 10, 2018 10:29 am
by MrFariator

Code: Select all

local timestamp = os.date("%F-%R:%S")
This particular line seems to be at fault; I checked the lua docs for the usage of os.date and it did not list %F or %R as legible arguments, which for a reason or another results in lua runtime to instantly hang up. I changed the line to something like the following, and there was no crashing.

Code: Select all

local timestamp = os.date("%c")
On another note, you may want to handle the save directory differently, because as it stands the log file will be written in to a folder titled "conf" under %appdata%\LOVE, as opposed to "dlog" or something along those lines.

Re: simple log library crashes love without notice

Posted: Sun Jun 10, 2018 11:29 am
by uiblob
MrFariator wrote: Sun Jun 10, 2018 10:29 am

Code: Select all

local timestamp = os.date("%F-%R:%S")
This particular line seems to be at fault; I checked the lua docs for the usage of os.date and it did not list %F or %R as legible arguments, which for a reason or another results in lua runtime to instantly hang up. I changed the line to something like the following, and there was no crashing.

Code: Select all

local timestamp = os.date("%c")
Thanks. I was somehow mixing it up with http://www.cplusplus.com/reference/ctime/strftime/
On another note, you may want to handle the save directory differently, because as it stands the log file will be written in to a folder titled "conf" under %appdata%\LOVE, as opposed to "dlog" or something along those lines.

Another thanks, I forgot the "" in the conf.lua there is no warning if the identity is not a string.