Style guidelines, scopes, Logger and more#23
Merged
Conversation
Using scopes for various groups of functions simulating files. Allows for use of some local functions and better organization. Using a editor which is capable of folding this huge file gets way easier to navigate.
created a init function, creating a logger and calling main
Merge upstream branch 'upstream/master'
though most of those debug messages could probably be removed.
they are an endangered species 😁
when displaying big tables they often got cut off before their end. This is avoided by splitting log messages at the 4000th char.
mrSkortch
added a commit
that referenced
this pull request
Jan 18, 2016
Style guidelines, scopes, Logger and more
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes
All changes shouldn't affect anything that worked with MIST 4.1. There were no (external) API changes.
do ... endscopes to simulate single files. Using a editor capable of code folding it gets a LOT easier navigating through the huge file. Also this allows for local functions beeing local only to the parts of mist which need them.function a.b() ... endWith this style of defining functions we'll never run in problems with recursive functions. See recursive local functions at http://www.lua.org/pil/6.2.html.camelCase. Except allmist.flagFuncfunctions.camelCase.table['field']withtable.fieldto save some brackets and quotes.mist.init()function as central entry point. Initializing database, creating logger instance, adding event handlers and finally callingmist.main()for the first time.mist.Loggerclass for easy logging with some nice features. More info see belowmist.Logger
Using this logger you get log levels (no more inline checks, whether to log or not, cluttering your code anymore) and, where possible, calling function and line number. E.g.
generates the following log entry in
%HOMEPATH%\Saved Games\DCS<.openbeta>\Logs\dcs.logMISTbeeing the tag,initthe name of the function in whichmyLog:msgwas called. And983the line at which the log function was called.The logger functions accept everything as parameter and try their best to put out a string representation of what you throw at them. In other words you can just
myLog:info(myTable)and you'll get a single line serialization of the table.Dumping big tables, returned by let's say
mist.utils.serialize, often ended up with overflowing theenv.infofunction. The logger automatically works around that by just splitting log messages longer than 4000 chars into multiple messages. You'll never loose those precious debug info again. 😉 See here for API documentation.Ideas & suggestions
I'd suggest to drop the changes file and just commit changes to git with a descriptive commit message. Also I would recommend to remove the
mist_version_number_here.luafile and rely on tags and releases alone, as it's already the case. This keeps the repository clean. Using a development branch is already a way of keeping WIP out of the master branch.Some functions names seem unclear/misleading to me e.g.
mist.goRoute,mist.groupToRandomZone,mist.groupRandomDistSelf. Maybe we could rename those functions to be more descriptive of what they are doing. I know there is already a really good documentation in PDF form and if one reads the description he knows what the function does. It's just an observation of mistakes I made while using MIST the first time in a script.Many functions use a table of vars as parameters. This could make debugging harder and I don't see the benefit from it. I'd suggest to deprecate those. Function signature still there, calling the new function with vars unpacked and logging a warning message that this function is deprecated.