From 1397b6c2895c989b9acc96f913466db319e4d6f8 Mon Sep 17 00:00:00 2001 From: Erica Marigold Date: Mon, 8 Jul 2024 16:30:53 +0530 Subject: [PATCH] Add library structure to template --- .luaurc | 6 +++++- .nvim.lua | 2 ++ .vscode/settings.json | 6 ++++-- README.md | 2 +- lib/init.luau | 5 +++++ src/init.luau | 5 +++-- 6 files changed, 20 insertions(+), 6 deletions(-) create mode 100644 lib/init.luau diff --git a/.luaurc b/.luaurc index 3e8f1bc..50a5ce7 100644 --- a/.luaurc +++ b/.luaurc @@ -7,5 +7,9 @@ "lintErrors": true, "globals": [ "warn" - ] + ], + "aliases": { + "lib": "./lib", + "src": "./src" + } } diff --git a/.nvim.lua b/.nvim.lua index 91939df..4fdc181 100644 --- a/.nvim.lua +++ b/.nvim.lua @@ -6,6 +6,8 @@ require("luau-lsp").config({ mode = "relativeToFile", directoryAliases = { ["@lune"] = "~/.lune/.typedefs/0.8.6/", + ["@lib"] = "./lib", + ["@src"] = "./src", }, }, completion = { diff --git a/.vscode/settings.json b/.vscode/settings.json index 1e34534..6acbd92 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,6 +1,8 @@ { "luau-lsp.require.mode": "relativeToFile", "luau-lsp.require.directoryAliases": { - "@lune/": "~/.lune/.typedefs/0.8.6/" + "@lune/": "~/.lune/.typedefs/0.8.6/", + "@lib": "./lib", + "@src": "./src" } -} \ No newline at end of file +} diff --git a/README.md b/README.md index 52bbd97..91a9d32 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ This is a template for initializing [Luau](https://luau-lang.org) projects with ## What is included in this template? - A barebones structure for an executable hello world Lune script (src/) -- A barebones structure for a library (lib/) -- TODO +- A barebones structure for a library (lib/) - Configuration files for various tooling: - aftman for toolchain management (aftman.toml) - stylua for code formatting (stylua.toml, lune.yml) diff --git a/lib/init.luau b/lib/init.luau new file mode 100644 index 0000000..715b472 --- /dev/null +++ b/lib/init.luau @@ -0,0 +1,5 @@ +local function makeHello(name: string): string + return "Hello, " .. name .. "!" +end + +return makeHello diff --git a/src/init.luau b/src/init.luau index 56f6a5c..d786748 100644 --- a/src/init.luau +++ b/src/init.luau @@ -1,7 +1,8 @@ +local makeHello = require("@lib/") local process = require("@lune/process") -function main(_args: { string }): number? - print("Hello, world!") +function main(args: { string }): number? + print(makeHello(args[1] or "world")) return 0 end