Last active
April 17, 2022 19:04
-
-
Save b0mbie/6d08ed279e752bc7baf85813d0e8326a to your computer and use it in GitHub Desktop.
Library for creating printfln and debugfln functions
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
| local printDebug = { | |
| debug = false | |
| } | |
| --- Similar to printfln of C, but uses Lua's print (which usually appends a newline). | |
| function printDebug.printfln(fmt, ...) print(string.format(fmt, ...)) end | |
| --- Create a printfln and debugfln function for a named context. | |
| --- printfln message prefix: "[<ctx>] " | |
| --- debugfln message prefix: "[<ctx>-debug] " | |
| --- ctx: Context name to create for. | |
| --- Returns: printfln, debugfln | |
| function printDebug.createPrintDebug(ctx) | |
| ctx = '[' .. ctx | |
| local ctx_d = ctx .. "-debug] " | |
| ctx = ctx .. "] " | |
| local function cprintfln(fmt, ...) | |
| printDebug.printfln(ctx .. fmt, ...) | |
| end | |
| local function cdebugfln(fmt, ...) | |
| if not printDebug.debug then return end | |
| printDebug.printfln(ctx_d .. fmt, ...) | |
| end | |
| return cprintfln, cdebugfln | |
| end | |
| return printDebug |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment