pax_global_header00006660000000000000000000000064143023474010014510gustar00rootroot0000000000000052 comment=45a3057e68c52b34ab59ef167efeb2340e356661 say-1.4.1/000077500000000000000000000000001430234740100123075ustar00rootroot00000000000000say-1.4.1/.busted000066400000000000000000000001101430234740100135660ustar00rootroot00000000000000return { default = { verbose = true, output = "gtest", }, } say-1.4.1/.editorconfig000066400000000000000000000004771430234740100147740ustar00rootroot00000000000000root = true [*] end_of_line = lf insert_final_newline = true trim_trailing_whitespace = true charset = utf-8 [*.lua] indent_style = space indent_size = 2 [Makefile] indent_style = tab [*.bat] end_of_line = crlf say-1.4.1/.github/000077500000000000000000000000001430234740100136475ustar00rootroot00000000000000say-1.4.1/.github/workflows/000077500000000000000000000000001430234740100157045ustar00rootroot00000000000000say-1.4.1/.github/workflows/busted.yml000066400000000000000000000022461430234740100177210ustar00rootroot00000000000000name: Busted on: [ push, pull_request ] jobs: busted: strategy: fail-fast: false matrix: luaVersion: [ "5.4", "5.3", "5.2", "5.1", "luajit" ] # , "luajit-openresty" ] runs-on: ubuntu-22.04 steps: - name: Checkout uses: actions/checkout@v3 - name: Setup ‘lua’ uses: leafo/gh-actions-lua@v9 with: luaVersion: ${{ matrix.luaVersion }} - name: Setup ‘luarocks’ uses: leafo/gh-actions-luarocks@v4 - name: Setup dependencies run: | luarocks install busted luarocks install luacov-coveralls - name: Replace system say with self run: | luarocks remove say --force luarocks make - name: Run regression tests # disable project-local path prefixes to force use of system installation run: busted --coverage --lpath="" --cpath="" -Xoutput --color - name: Report test coverage if: ${{ success() && github.repository == 'lunarmodules/say' }} continue-on-error: true run: luacov-coveralls -i src -e .luarocks env: COVERALLS_REPO_TOKEN: ${{ github.token }} say-1.4.1/.github/workflows/deploy.yml000066400000000000000000000023241430234740100177240ustar00rootroot00000000000000name: Deploy on: [ push, workflow_dispatch ] jobs: affected: uses: lunarmodules/.github/.github/workflows/list_affected_rockspecs.yml@main build: needs: affected if: ${{ needs.affected.outputs.rockspecs }} uses: lunarmodules/.github/.github/workflows/test_build_rock.yml@main with: rockspecs: ${{ needs.affected.outputs.rockspecs }} upload: needs: [ affected, build ] # Only run upload if: # 1. We are on the canonical repository (no uploads from forks) # 2. The current commit is either tagged or on the default branch (the workflow will upload dev/scm rockspecs any # time they are touched, tagged ones whenever the edited rockspec and tag match) # 3. Some rockspecs were changed — this implies the commit changing the rockspec is the same one that gets tagged if: >- ${{ github.repository == 'lunarmodules/say' && ( github.ref_name == 'master' || startsWith(github.ref, 'refs/tags/') ) && needs.affected.outputs.rockspecs }} uses: lunarmodules/.github/.github/workflows/upload_to_luarocks.yml@main with: rockspecs: ${{ needs.affected.outputs.rockspecs }} secrets: apikey: ${{ secrets.LUAROCKS_APIKEY }} say-1.4.1/.github/workflows/luacheck.yml000066400000000000000000000003311430234740100202030ustar00rootroot00000000000000name: Luacheck on: [push, pull_request] jobs: luacheck: runs-on: ubuntu-20.04 steps: - name: Checkout uses: actions/checkout@v3 - name: Luacheck uses: lunarmodules/luacheck@v0 say-1.4.1/.gitignore000066400000000000000000000000261430234740100142750ustar00rootroot00000000000000*.swp *.rock luacov.* say-1.4.1/.luacheckrc000066400000000000000000000007121430234740100144140ustar00rootroot00000000000000std = "max+busted" unused_args = false redefined = false max_line_length = false globals = { "randomize", "match", "async", "done", "busted", --"ngx.IS_CLI", } not_globals = { "string.len", "table.getn", } ignore = { --"6.", -- ignore whitespace warnings } exclude_files = { ".install", ".lua", ".luarocks", "spec/insulate-expose_spec.lua", "spec/cl_compile_fail.lua", } say-1.4.1/CONTRIBUTING.md000066400000000000000000000030701430234740100145400ustar00rootroot00000000000000Contributing to Say =================== So you want to contribute to luassert? Fantastic! Here's a brief overview on how best to do so. ## What to change Here's some examples of things you might want to make a pull request for: * New features * Bugfixes * Inefficient blocks of code If you have a more deeply-rooted problem with how the program is built or some of the stylistic decisions made in the code, it's best to [create an issue](https://github.com/lunarmodules/say/issues) before putting the effort into a pull request. The same goes for new features - it might be best to check the project's direction, existing pull requests, and currently open and closed issues first. ## Style * Two spaces, not tabs * Variables have_underscores, classes are Uppercase * Wrap everything in `local`, expose blocks of code using the module pattern Look at existing code to get a good feel for the patterns we use. ## Using Git appropriately 1. [Fork the repository](https://github.com/lunarmodules/say/fork_select) to your Github account. 2. Create a *topical branch* - a branch whose name is succint but explains what you're doing, such as "klingon-translations" 3. Make your changes, committing at logical breaks. 4. Push your branch to your personal account 5. [Create a pull request](https://help.github.com/articles/using-pull-requests) 6. Watch for comments or acceptance Please note - if you want to change multiple things that don't depend on each other, make sure you check the master branch back out before making more changes - that way we can take in each change separately. say-1.4.1/LICENSE000066400000000000000000000021271430234740100133160ustar00rootroot00000000000000MIT License Terms ================= Copyright (c) 2012 Olivine Labs, LLC. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. say-1.4.1/README.md000066400000000000000000000027361430234740100135760ustar00rootroot00000000000000# Say [![Busted](https://img.shields.io/github/workflow/status/lunarmodules/say/Busted?label=Busted&logo=Lua)](https://github.com/lunarmodules/say/actions?workflow=Busted) [![Luacheck](https://img.shields.io/github/workflow/status/lunarmodules/say/Luacheck?label=Luacheck&logo=Lua)](https://github.com/lunarmodules/say/actions?workflow=Luacheck) [![GitHub tag (latest SemVer)](https://img.shields.io/github/v/tag/lunarmodules/say?label=Tag&logo=GitHub)](https://github.com/lunarmodules/say/releases) [![Luarocks](https://img.shields.io/luarocks/v/lunarmodules/say?label=Luarocks&logo=Lua)](https://luarocks.org/modules/lunarmodules/say) say is a simple string key/value store for i18n or any other case where you want namespaced strings. Check out [busted](https://lunarmodules.github.io/busted/) for extended examples. ```lua s = require("say") s:set_namespace("en") s:set('money', 'I have %s dollars') s:set('wow', 'So much money!') print(s('money', {1000})) -- I have 1000 dollars s:set_namespace("fr") -- switch to french! s:set('so_much_money', "Tant d'argent!") print(s('wow')) -- Tant d'argent! s:set_namespace("en") -- switch back to english! print(s('wow')) -- So much money! ``` NOTE: the parameters table can have `nil` values, but in that case it must have an `n` field to indicate table size. ```lua s = require("say") s:set('money', 'I have %s %s') print(s('money', {1000, "dollars"})) -- I have 1000 dollars print(s('money', {nil, "euros", n = 2})) -- I have nil euros ``` say-1.4.1/rockspecs/000077500000000000000000000000001430234740100143035ustar00rootroot00000000000000say-1.4.1/rockspecs/say-1.3-1.rockspec000066400000000000000000000007441430234740100172740ustar00rootroot00000000000000package = "say" version = "1.3-1" source = { url = "https://github.com/Olivine-Labs/say/archive/v1.3-1.tar.gz", dir = "say-1.3-1" } description = { summary = "Lua String Hashing/Indexing Library", detailed = [[ Useful for internationalization. ]], homepage = "http://olivinelabs.com/busted/", license = "MIT " } dependencies = { "lua >= 5.1" } build = { type = "builtin", modules = { ["say.init"] = "src/init.lua" } } say-1.4.1/rockspecs/say-1.4.0-1.rockspec000066400000000000000000000014561430234740100174340ustar00rootroot00000000000000local package_name = "say" local package_version = "1.4.0" local rockspec_revision = "1" local github_account_name = "lunarmodules" local github_repo_name = package_name package = package_name version = package_version .. "-" .. rockspec_revision source = { url = "git+https://github.com/"..github_account_name.."/"..github_repo_name..".git" } if package_version == "scm" then source.branch = "master" else source.tag = "v" .. package_version end description = { summary = "Lua string hashing/indexing library", detailed = [[ Useful for internationalization. ]], homepage = "https://lunarmodules.github.io/busted/", license = "MIT " } dependencies = { "lua >= 5.1" } build = { type = "builtin", modules = { ["say.init"] = "src/say/init.lua" } } say-1.4.1/rockspecs/say-1.4.1-1.rockspec000066400000000000000000000015051430234740100174300ustar00rootroot00000000000000package = "say" local rock_version = "1.4.1" local rock_release = "1" local namespace = "lunarmodules" local repository = package version = ("%s-%s"):format(rock_version, rock_release) source = { url = ("git+https://github.com/%s/%s.git"):format(namespace, repository), branch = rock_version == "scm" and "master" or nil, tag = rock_version ~= "scm" and rock_version or nil, } description = { summary = "Lua string hashing/indexing library", detailed = [[ Useful for internationalization. ]], homepage = ("https://%s.github.io/%s"):format(namespace, repository), issues_url = ("https://github.com/%s/%s/issues"):format(namespace, repository), maintainer = "Caleb Maclennan ", } dependencies = { "lua >= 5.1", } build = { type = "builtin", modules = { say = "src/say/init.lua" } } say-1.4.1/rockspecs/say-1.4.1-2.rockspec000066400000000000000000000014061430234740100174310ustar00rootroot00000000000000package = "say" local rock_version = "1.4.1" local rock_release = "2" local namespace = "lunarmodules" local repository = package version = ("%s-%s"):format(rock_version, rock_release) source = { url = ("git+https://github.com/%s/%s.git"):format(namespace, repository), branch = rock_version == "scm" and "master" or nil, tag = rock_version ~= "scm" and rock_version or nil, } description = { summary = "Lua string hashing/indexing library", detailed = [[ Useful for internationalization. ]], license = "MIT", homepage = ("https://%s.github.io/%s"):format(namespace, repository), maintainer = "Caleb Maclennan ", } dependencies = { "lua >= 5.1", } build = { type = "builtin", modules = { say = "src/say/init.lua" } } say-1.4.1/rockspecs/say-1.4.1-3.rockspec000066400000000000000000000014131430234740100174300ustar00rootroot00000000000000package = "say" local rock_version = "1.4.1" local rock_release = "3" local namespace = "lunarmodules" local repository = package version = ("%s-%s"):format(rock_version, rock_release) source = { url = ("git+https://github.com/%s/%s.git"):format(namespace, repository), branch = rock_version == "scm" and "master" or nil, tag = rock_version ~= "scm" and "v"..rock_version or nil, } description = { summary = "Lua string hashing/indexing library", detailed = [[ Useful for internationalization. ]], license = "MIT", homepage = ("https://%s.github.io/%s"):format(namespace, repository), maintainer = "Caleb Maclennan ", } dependencies = { "lua >= 5.1", } build = { type = "builtin", modules = { say = "src/say/init.lua" } } say-1.4.1/say-scm-1.rockspec000066400000000000000000000016701430234740100155600ustar00rootroot00000000000000package = "say" local rock_version = "scm" local rock_release = "1" local namespace = "lunarmodules" local repository = package rockspec_format = "3.0" version = ("%s-%s"):format(rock_version, rock_release) source = { url = ("git+https://github.com/%s/%s.git"):format(namespace, repository), branch = rock_version == "scm" and "master" or nil, tag = rock_version ~= "scm" and "v"..rock_version or nil, } description = { summary = "Lua string hashing/indexing library", detailed = [[ Useful for internationalization. ]], license = "MIT", homepage = ("https://%s.github.io/%s"):format(namespace, repository), issues_url = ("https://github.com/%s/%s/issues"):format(namespace, repository), maintainer = "Caleb Maclennan ", } dependencies = { "lua >= 5.1", } test_dependencies = { "busted", } test = { type = "busted", } build = { type = "builtin", modules = { say = "src/say/init.lua" } } say-1.4.1/spec/000077500000000000000000000000001430234740100132415ustar00rootroot00000000000000say-1.4.1/spec/say_spec.lua000066400000000000000000000044321430234740100155550ustar00rootroot00000000000000local s describe("Tests to make sure the say library is functional", function() setup(function() -- busted loads say internally, force reload in case the sources we're -- expected to test (via LUA_PATH) aren't the ones busted found earlier package.loaded['say'] = false s = require('say') end) it("tests the set function metamethod", function() s:set('herp', 'derp') assert(s._registry.en.herp == 'derp') end) it("tests the __call metamethod", function() s:set('herp', 'derp') assert(s('herp') == 'derp') s:set('herp', '%s') assert(s('herp', {'test'}) == 'test') s:set('herp', '%s%s') assert(s('herp', {'test', 'test'}) == 'testtest') end) it("tests the substitution of variable types; boolean, number, string and table", function() s:set('substitute_test', 'boolean = %s, number = %s, string = "%s", table = %s') local atable = {} assert(s('substitute_test', {true, 100, 'some text', atable}) == 'boolean = true, number = 100, string = "some text", table = ' .. tostring(atable)) end) it("tests the substitution of variable types; nil", function() s:set('substitute_test', 'boolean = %s, nil = %s, number = %s, string = "%s", table = %s') local atable = {} assert(s('substitute_test', {true, nil, 100, 'some text', atable, n = 5}) == 'boolean = true, nil = nil, number = 100, string = "some text", table = ' .. tostring(atable)) end) it("tests the set_fallback method", function() s:set_namespace('en') s:set('herp', 'derp') s:set_namespace('not-en') s:set('not-herp', 'not-derp') assert(s('not-herp') == 'not-derp') assert(s('herp') == 'derp') end) it("errors on bad type of param table", function() s:set_namespace('en') s:set('herp', 'derp %s') assert.has.error(function() s('herp', 1000) end, "expected parameter table to be a table, got 'number'") end) it("tests missing elements returns nil", function() assert(s('this does not exist') == nil) end) it("tests the wrong arg count", function() -- backward compatibility after the nil-safe fix, in which the 'n' field got precendence over # s:set('substitute_test', '1 = %s, 2 = %s') -- two arguments, but "n = 1" assert(s('substitute_test', {"one", "two", n = 1}) == '1 = one, 2 = two') end) end) say-1.4.1/src/000077500000000000000000000000001430234740100130765ustar00rootroot00000000000000say-1.4.1/src/say/000077500000000000000000000000001430234740100136725ustar00rootroot00000000000000say-1.4.1/src/say/init.lua000066400000000000000000000030111430234740100153330ustar00rootroot00000000000000local unpack = table.unpack or unpack local registry = { } local current_namespace local fallback_namespace local s = { _COPYRIGHT = "Copyright (c) 2012 Olivine Labs, LLC.", _DESCRIPTION = "A simple string key/value store for i18n or any other case where you want namespaced strings.", _VERSION = "Say 1.3", set_namespace = function(self, namespace) current_namespace = namespace if not registry[current_namespace] then registry[current_namespace] = {} end end, set_fallback = function(self, namespace) fallback_namespace = namespace if not registry[fallback_namespace] then registry[fallback_namespace] = {} end end, set = function(self, key, value) registry[current_namespace][key] = value end } local __meta = { __call = function(self, key, vars) if vars ~= nil and type(vars) ~= "table" then error(("expected parameter table to be a table, got '%s'"):format(type(vars)), 2) end vars = vars or {} vars.n = math.max((vars.n or 0), #vars) local str = registry[current_namespace][key] or registry[fallback_namespace][key] if str == nil then return nil end str = tostring(str) local strings = {} for i = 1, vars.n or #vars do table.insert(strings, tostring(vars[i])) end return #strings > 0 and str:format(unpack(strings)) or str end, __index = function(self, key) return registry[key] end } s:set_fallback('en') s:set_namespace('en') s._registry = registry return setmetatable(s, __meta)