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.
Debug and production release
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: Debug and production release
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
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 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.
-
- Prole
- Posts: 4
- Joined: Thu Nov 22, 2018 9:19 pm
Re: Debug and production release
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
- zorg
- Party member
- Posts: 3465
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: Debug and production release
My solution might not be safer or better by any standard, but i'd still do it like this:
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.
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.
Me and my stuff True 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.
Re: Debug and production release
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
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
-
- Prole
- Posts: 4
- Joined: Thu Nov 22, 2018 9:19 pm
Re: Debug and production release
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.pgimeno wrote: ↑Thu Apr 18, 2019 7:10 pm If you're concerned about performance, you can use ReFreezed's LuaPreprocess.
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
Who is online
Users browsing this forum: Ahrefs [Bot], Google [Bot], Semrush [Bot] and 4 guests