Debug and production release

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
UnRealCloud
Prole
Posts: 4
Joined: Thu Nov 22, 2018 9:19 pm

Debug and production release

Post by UnRealCloud »

Hello,
I'm wondering if it's possible to have differents releases for your love2d game. I mean the main difference should be to remove all assert and print functions in your production release ( how to automate this part ) . In many other languages, the assert part seems to be something, but in lua I don't see anything about.
How do you handle that in yours projects?
Further more, is it smart to keep a log system in your production build ? Is it like keeping print function but redirected to a log file.
Xugro
Party member
Posts: 110
Joined: Wed Sep 29, 2010 8:14 pm

Re: Debug and production release

Post by Xugro »

You could wrap the print and assert functions, have a production flag and only execute print and assert in the development phase. Some pseudocode:

Code: Select all

function love.load()
    PRODUCTION = false
end

function wrapped_print(text)
    if PRODUCTION then
        log(text)
    else
        print(text)
    end
end
UnRealCloud wrote: Thu Apr 18, 2019 3:42 pmFurther more, is it smart to keep a log system in your production build ? Is it like keeping print function but redirected to a log file.
What do you want to do with the log files? It does not make sense to generate lots of big log files if you never analyze them.
UnRealCloud
Prole
Posts: 4
Joined: Thu Nov 22, 2018 9:19 pm

Re: Debug and production release

Post by UnRealCloud »

The log file could be send from the player to me if a bug happens. But at the same time if the assert functions are not use in production I don't know what could be usefull in this log file. I have no idea what is the best practise. If you have an advice
User avatar
zorg
Party member
Posts: 3441
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Debug and production release

Post by zorg »

My solution might not be safer or better by any standard, but i'd still do it like this:

Code: Select all

PRODUCTION = true
-- Monkeypatch the actual functions in a separate lua file, that only gets require'd in (and executed) if a flag is set, so:
function love.load(args)
    -- Let's say you only want debug mode if the release is not zipped into a .love file.
    if love.filesystem.isFused() then PRODUCTION == false end
    -- ...
    if PRODUCTION then require 'debugstuff.lua' end
end

-- meanwhile, in debugstuff.lua:

local _print = print
function print(...)
    -- do logging as well
    -- then call the actual print function; ... passes all arguments on.
    _print(...)
end
-- etc.
Monkeypatching like that makes the debug stuff isolated into one file, and you can keep using the same default function names without needing to define new ones everywhere else in your codebase.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
pgimeno
Party member
Posts: 3548
Joined: Sun Oct 18, 2015 2:58 pm

Re: Debug and production release

Post by pgimeno »

If you're concerned about performance, you can use ReFreezed's LuaPreprocess.

Personally I don't disable assertions in production code. It's important to be able to get useful bug reports when problems arise. I don't use the system's assert; instead I use a version that allows me to specify the message as a function, see http://lua.space/general/assert-usage-caveat
UnRealCloud
Prole
Posts: 4
Joined: Thu Nov 22, 2018 9:19 pm

Re: Debug and production release

Post by UnRealCloud »

pgimeno wrote: Thu Apr 18, 2019 7:10 pm If you're concerned about performance, you can use ReFreezed's LuaPreprocess.
That's awesome, it looks like what I was describing ! More than performance, it's the possibility to have multiple versions easily that seduce me.
And thanks for xassert too, I was using mine own assert functions but it has the same poor benchmark score as explained in the post

Your answers really helped me . You're awesomes guys :D
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 66 guests