GithubHelp home page GithubHelp logo

lunatic-fox / lext Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 1.0 209 KB

Extension methods to Lua language.

License: MIT License

Lua 100.00%
extension lua reduce reverse split string table replace slice array

lext's Introduction

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

lext's People

Contributors

lunatic-fox avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

panquesito7

lext's Issues

Add `string.contains`

Description

It'd be great if a string.contains function could be added.
This can be very useful in a lot of ways when checking if a string has a certain substring.

This is a very simple code that works, however, it could be improved.

--- @brief Checks if the given string
--- contains a certain substring.
--- @param str the string to check
--- @param substr the substring to check for
--- @returns true if `substr` was found in `str`
--- @returns false if `substr` was NOT found in `str`
function string.contains(str, substr)
    local substr_length = #substr
    for i = 1, #str do
        if str:sub(i, i + substr_length - 1) == substr then
            return true
        end
    end

    return false
end

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.