Giter Site home page Giter Site logo

joshuavandaele / lua-utilities-snippets Goto Github PK

View Code? Open in Web Editor NEW
9.0 2.0 1.0 54 KB

Useful Utilities/Snippets for Lua!

License: The Unlicense

Lua 100.00%
lua free-to-use utility-library utility-function snippets utils utility toolkit utility-scripts string

lua-utilities-snippets's Introduction

Utils

Useful Utilities for Lua!

This file was made firstly for myself, but then I wanted to share it with people, so here it is!

Utilities avaible:

String

  • string.random(count,min,max) "count, min, max" are not required, this function returns a random string
  • string.split(str,split) this function splits a string to a table
  • string.mix(str) see mix
  • string.startswith(str,pattern) verify if a string starts with the pattern
  • string.endswith(str,pattern) same as above but for the end of the string
  • string.encode table for encoding
  • string.decode table for decoding
  • string.encode.hex(str) encode a string into hex
  • string.decode.hex(str) decode a string into hex
  • string.encode.b64(str) encode a string into base64
  • string.decode.b64(str) decode a string into base64
  • string.totable transforms a string to a table

I/O

  • io.readfile(path/to/file.txt) reads a file
  • io.store(file,content,true) stores data into a file, the "true" mean we do a new line at the end of the file for future storing

Math

  • math.mix see mix
  • math.calc Calculator sandboxed (You can't inject code)

OS

  • os.find("file","dir") search for a file in a directory
  • os.clear() clear the terminal, works with all OS
  • os.getOS() returns the current OS
  • os.getArch() get if the arch is 64 bits or 32 bits
  • os.outputexec
    Get the output of a system command
  • os.splitpath(path) Splits the path

Table

  • table.merge(t1,t2) merges two tables
  • table.to2D(str) returns a 2D table version of the string you sent
  • table.tostring(tbl) returns a string of the table you sent
  • table.list(tbl) return in a string a list of elements of a table, also returns count
  • table.head(tbl) returns first value
  • table.tail(tbl) returns the tail of the table
  • table.find(tbl) find a value in a table
  • table.reverse(tbl) reverses a table. Warning: only works with normal keys (1,2,3..)

Console

  • console.log(str) logs something with time and date
  • console.slowPrint(str) prints something slowly
  • console.slowWrite(str) writes something slowly (using io.write)
  • console.error(error type, error message, additional infos) advanced erroring
  • console.update(bool,str...) Will update the console, bool: is the text slowly appearing.

Others

  • sleep(t) will wait the amount of time given
  • operator Operators, can always be useful
  • morse A table with char for morse in it
  • chars a string with all chars, used for string.encode.b64(str)
  • mix mix a string or ints
  • dostring a remake of the old loadstring for Lua 5.3 - execute a string as a piece of code
  • isType Shorter for type(obj) == "obj"

lua-utilities-snippets's People

Contributors

joshuavandaele avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

hya1109

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.