Skip to content

Latest commit

 

History

History
152 lines (107 loc) · 4.67 KB

README.md

File metadata and controls

152 lines (107 loc) · 4.67 KB

Lua extensions  

Install

Step 1

 Download the install.tar file (Lua extensions directory), extract to your LUA_PATH (path where Lua is installed).

 Or you can also open a terminal in the same path where you downloaded install.tar and run the command line below to unzip to your <LUA_PATH>.

tar -xf install.tar -C "<LUA_PATH>"

install.tar

SHA256: cb4df36c5d5f86f92cc27d72b8e5b3c4e7fe7b7c8181a1e9d66f5968bef1032f
MD5: bf6f95cd6d895dc0a5150ec738ad94eb

Content

  • lext.lua
  • lua-extensions/dependencies/erros.lua
  • lua-extensions/dependencies/short-methods.lua
  • lua-extensions/docs/extlib.lua
  • lua-extensions/array.lua
  • lua-extensions/string.lua
  • lua-extensions/LICENSE.lua

Step 2

 On VSCode you will need Lua Language Server extension installed.

Step 3

 Still on VSCode open Preferences: Open User Settings (JSON) with the command:

  • On Windows: Ctrl + Shift + P or F1
  • On MacOS: ⇧⌘P or F1

 Inside the main object of settings.json add the code below changing <LUA_PATH> to the path where Lua is installed on your machine.

"Lua.workspace.library": [
  "<LUA_PATH>/lua-extensions/docs"
]

 All set! You're ready to go! 🚀

Usage

 Require Lua extensions module in whatever lua file you want with the code below.

require 'lext'

 Let's see an example with array.reduce().

require 'lext'
local t = array{1, 2, 3, 4, 5}.reduce'+'

print(t) -- 15

UTF8 terminal

 If your terminal isn't displaying utf8 characters correctly, use the utf8 option after the filename, just once. This argument triggers the chcp 65001 command in the console.

-- heart.lua
print 'Coração' -- Cora├º├úo
> lua heart.lua utf8

 Now let's take a look at some brief explanations about the powerful Lua extensions. You can also click on the method to see some examples in documentation.

  • :split()
    Splits a string into a string table.

  • :slice()
    Splices the string with UTF8 support.

  • :replace()
    Replaces a string substring with no magic symbols.

  • :tolowercase()
    Lowercase all with UTF8 support.

  • :touppercase()
    Lowercase all with UTF8 support.

  • :reverse()
    Reverses the string with UTF8 support.

  • :contains()
    Checks if the given string contains a certain substring.

  • :trim()
    Removes the leading and trailing white space line terminator characters from a string.

  • :trimstart()
    Removes the leading white space characters from a string.

  • :trimend()
    Removes the trailing white space line terminator characters from a string.

  • .join()
    Joins the table into a string.

  • .slice()
    Slices the table.

  • .filter()
    Returns a table with items that meet a specified condition passed by a callback function.

  • .map()
    Modifies each item of the table by a callback function.

  • .reduce()
    Returns the accumulated result of all the elements in the array.

  • .reverse()
    Reverses the order of the elements in the array.

  • .flat()
    Returns a new array with all sub-array elements concatenated into it recursively up to the specified depth.

Made with ❤️

Lunatic Fox - Josélio Júnior - 2023