From 16d9c94822376de1f0d5732b46e906dfd496c1d7 Mon Sep 17 00:00:00 2001 From: Filip Tibell Date: Mon, 6 Feb 2023 13:10:52 -0500 Subject: [PATCH] Update hello lune example --- .lune/hello_lune.luau | 48 ++++++++++++++++++++++++--------------- .lune/modules/module.luau | 2 +- luneDocs.json | 14 ++++++++++-- luneTypes.d.luau | 6 +++-- 4 files changed, 47 insertions(+), 23 deletions(-) diff --git a/.lune/hello_lune.luau b/.lune/hello_lune.luau index 4251038..0cf8484 100644 --- a/.lune/hello_lune.luau +++ b/.lune/hello_lune.luau @@ -14,19 +14,35 @@ module.sayHello() --[==[ EXAMPLE #2 + Using the stdio library to prompt for input +]==] + +local text = stdio.prompt("text", "Please write some text") +print("You wrote '" .. text .. "'!\n") + +local confirmed = stdio.prompt("confirm", "Please confirm that you wrote some text") +if confirmed == false then + error("You didn't confirm!") +else + print("Confirmed!") +end + +--[==[ + EXAMPLE #3 + Using arguments given to the program ]==] if #process.args > 0 then print("\nGot arguments while running hello_lune:") - console.log(process.args) + print(process.args) if #process.args > 3 then error("Too many arguments!") end end --[==[ - EXAMPLE #3 + EXAMPLE #4 Spawning tasks ]==] @@ -46,7 +62,7 @@ task.delay(5, function() end) --[==[ - EXAMPLE #4 + EXAMPLE #5 Get & set environment variables @@ -67,7 +83,7 @@ for key, value in process.env do end --[==[ - EXAMPLE #5 + EXAMPLE #6 Read files in the current directory @@ -110,7 +126,7 @@ end -- since the ping command does not work in azure if not process.env.GITHUB_ACTIONS then --[==[ - EXAMPLE #6 + EXAMPLE #7 Call out to another program / executable @@ -125,7 +141,7 @@ if not process.env.GITHUB_ACTIONS then }) --[==[ - EXAMPLE #7 + EXAMPLE #8 Using the result of a spawned process, exiting the process @@ -152,7 +168,7 @@ if not process.env.GITHUB_ACTIONS then end --[==[ - EXAMPLE #8 + EXAMPLE #9 Using the built-in networking library ]==] @@ -189,19 +205,17 @@ assert(apiResponse.body == "bar", "Invalid json response") print("Got valid JSON response with changes applied") --[==[ - EXAMPLE #9 + EXAMPLE #10 - Using the console library to print pretty + Using the stdio library to print pretty ]==] print("\nPrinting with pretty colors and auto-formatting 🎨") -console.setColor("blue") -print(string.rep("—", 22)) -console.resetColor() +print(stdio.color("blue") .. string.rep("—", 22) .. stdio.color("reset")) -console.info("API response:", apiResponse) -console.warn({ +info("API response:", apiResponse) +warn({ Oh = { No = { TooMuch = { @@ -213,12 +227,10 @@ console.warn({ }, }) -console.setColor("blue") -print(string.rep("—", 22)) -console.resetColor() +print(stdio.color("blue") .. string.rep("—", 22) .. stdio.color("reset")) --[==[ - EXAMPLE #10 + EXAMPLE #11 Saying goodbye 😔 ]==] diff --git a/.lune/modules/module.luau b/.lune/modules/module.luau index c64e8a7..47d38ba 100644 --- a/.lune/modules/module.luau +++ b/.lune/modules/module.luau @@ -1,7 +1,7 @@ local module = {} function module.sayHello() - print("\nHello from a module! 🧩") + print("\nHello from a module! 🧩\n") end return module diff --git a/luneDocs.json b/luneDocs.json index e110bba..88a0f6c 100644 --- a/luneDocs.json +++ b/luneDocs.json @@ -347,11 +347,16 @@ "name": "color" } ], - "returns": [] + "returns": [ + "@roblox/global/stdio.color/return/0" + ] }, "@roblox/global/stdio.color/param/0": { "documentation": "The color to use" }, + "@roblox/global/stdio.color/return/0": { + "documentation": "A printable ANSI string" + }, "@roblox/global/stdio.ewrite": { "code_sample": "", "documentation": "Writes a string directly to stderr, without any newline.", @@ -426,11 +431,16 @@ "name": "style" } ], - "returns": [] + "returns": [ + "@roblox/global/stdio.style/return/0" + ] }, "@roblox/global/stdio.style/param/0": { "documentation": "The style to use" }, + "@roblox/global/stdio.style/return/0": { + "documentation": "A printable ANSI string" + }, "@roblox/global/stdio.write": { "code_sample": "", "documentation": "Writes a string directly to stdout, without any newline.", diff --git a/luneTypes.d.luau b/luneTypes.d.luau index 993ae85..ce07f27 100644 --- a/luneTypes.d.luau +++ b/luneTypes.d.luau @@ -305,8 +305,9 @@ declare stdio: { ``` @param color The color to use + @return A printable ANSI string ]=] - color: (color: "reset" | "black" | "red" | "green" | "yellow" | "blue" | "purple" | "cyan" | "white") -> (), + color: (color: "reset" | "black" | "red" | "green" | "yellow" | "blue" | "purple" | "cyan" | "white") -> string, --[=[ @within stdio @@ -324,8 +325,9 @@ declare stdio: { ``` @param style The style to use + @return A printable ANSI string ]=] - style: (style: "reset" | "bold" | "dim") -> (), + style: (style: "reset" | "bold" | "dim") -> string, --[=[ @within stdio