LuaZDF - Lua Zero Dependency Functions

Related tags

Miscellaneous luazdf
Overview

LuaZDF - Lua Zero Dependency Functions

LuaZDF is a collection of independet functions that have zero dependencies among themselves. A function in LuaZDF can be based on lpeg, LuaFileSystem or other Lua modules but each function inside LuaZDF works on its own. That means you can copy the source code and run it in your project without the need to include LuaZDF for this functionality.

Motivation

Lua itself has just a little standard library without many small utility functions that you know from other languages and envoirments. For example has Lua no trim function for strings, no trunc function for numbers and no slice function for tables in the standard library. This are not complicated functions that you are able to write yourself without much effort, find an implementation on the internet or you can include a utility library that has this functions, but each of the three possibilities has a drawback.

  • Simple functions that you write yourself can have flavours that you miss and not test.

  • A solution that you find in the internet can be outdated for the current version.

  • Sometimes you don’t want to add additional dependencies just to get one or two simple functions.

LuaZDF has the goal to collect and provide this kind of functions.

Approach

The LuaZDF approach to solve this problem differs to existing solution like npm. Instead of adding dependencies that need to be maintained follows LuaZDF a paradigm that is like the Go Programming Language proverb:

A little copying is better than a little dependency.

You still need to maintain your code, but not the dependencies. A small looking difference but hugh difference how your workflow will work.

License

LuaZDF uses the BSD 0-Clause License (0BSD) from the Toybox project.

More Stuff

You can explore and use existing functions as a consumer or you can add new functions as a creator.

You can explore all functions on the website.

Check the information about contribution if you want to add or modify a function.

For both use cases is it recommended to use to the command line tool lzt.

The user discussion about LuaZDF in general and the functions takes place on reddit.

Comments
  • TAP-compatible test function

    TAP-compatible test function

    This time should work. I re-inited the fork repo to keep the history clean. Some note on the code:

    • I changed the one-argument mode to implement the "Tap diagnostic" since Tap have not the concept of "Suite". However, in my previous implementation, Suite was just logging so, you can reproduce it with Tap diagnostic.
    • Using taptest to test itself make the example a bit confusing. I tryed as much ad possible to clearify the example. Maybe it is better to write a simplier one?
    • For now, no argument type check are performed
    • I put it in the sys directory, maybe you have some better solution
    opened by pocomane 7
  • logline

    logline

    I am a little irritated about the order of the error level. My natural assumption would be reverse.

    ERROR > 75 DEBUG > 50 INFO > 25 VERBOSE > 0

    It feels more natural for me if a more important case has a higher number.

    opened by aiq 3
  • escapeshellarg improvements

    escapeshellarg improvements

    escapeshellarg (and so shelljoin) does not handle some cases. At my understanding these functions aim to produce strings that can be passed to os.execute bypassing all the shell pre-parsing. If this is the intent, the following example gives a wrong output:

    print(require 'shelljoin' {' a\\"',' b\\', 'c $PATH'})
    

    Indeed:

    • '\' should be escaped to avoid unwanted escapes
    • '$' should be escaped to avoid variable expansion

    Moreover these functions work only with a posix shell. I think at least windows should be supported. Maybe you could use something like:

    local function posix_quote_argument(str)
      -- if not str:match("'") then
      --   return "'" .. str .. "'"
      -- end
      str = str:gsub("[$`\"\\]", "\\%1") 
      return '"' .. str .. '"'
    end
    
    local function windows_quote_argument(str)
      -- str = str:gsub('["\\]', '\\%1')
      -- return '"'..str..'"'
      str = str:gsub('[%%&\\^<>|]', '^%1')
      str = str:gsub('"', "\\%1")
      str = str:gsub('[ \t][ \t]*', '"%1"')
      return str
    end
    
    local function detect_the_shell()
      local shell = os.getenv('SHELL')
      if shell then
        if '/' == shell:sub(1,1) and 'sh' == shell:sub(-2, -1) then
          return posix_quote_argument
        end
      end
      return windows_quote_argument
    end
    

    (actually this came from some my old code that was also tested a bit). I did not a comit+pull request since I do not know if this is the desired behaviour.

    opened by pocomane 2
  • TAP-compatible test function

    TAP-compatible test function

    Some note on the code:

    • I changed the one-argument mode to implement the "Tap diagnostic" since Tap have not the concept of "Suite". However, in my previous implementation, Suite was just logging so, you can reproduce it with Tap diagnostic.

    • Using taptest to test itself make the example a bit confusing. I tryed as much ad possible to clearify the example. Maybe it is better to write a simplier one?

    • The example write another 'ok X' line after ending plan summary. This is not allowed in standard TAP, but for now I can not guess how get rid of it. IIt is just an issue of the example, I hope your CI scripts will accept it.

    • For now, no argument type check are performed

    • I put it in the sys directory, maybe you have some better solution

    opened by pocomane 2
  • Feature request: text template

    Feature request: text template

    I can not find any text-template function. Sorry if I missed it, however I attached a very simple exmple, in case you want to include it into the collection.

    It use %b{} to separate verbatim text from template code. Then text and code are merged into a lua script and it is passed to load(). It can:

    • Mixing template statement and text
    • Quick print the result of expressions
    -- MIN-imal T-emplate
    
    local function generate_mint(str, expansion_funcname)
      local script = ''
      str:gsub('(.-)@(%b{})', function(a,b)
        b = b:sub(2,#b-1)
        if b:match('^{.*}$') then
          b = b:sub(2,#b-1)
        else
          b = expansion_funcname..'(' .. b .. ')'
        end
        script = script .. expansion_funcname .. '(' .. string.format('%q', a) .. ') ' .. b .. ' '
      end)
      local verbatim_ending = str:match('^.*@%b{}(.-)$')
      if verbatim_ending then
        script = script .. expansion_funcname .. '(' .. string.format('%q', verbatim_ending) .. ')'
      end
      return script
    end
    
    local function mint(str, sandbox, expansion_funcname)
      if not expansion_funcname then expansion_funcname = 'o' end
      local script = generate_mint(str, expansion_funcname)
      print('EXAMPLE generated script:', script) -- todo : remove!
      local result = ''
       if 'table' ~= type(sandbox) then
        sandbox = {}
        for k,v in pairs(_ENV) do sandbox[k] = v end -- todo : better selection?
      end
      sandbox[expansion_funcname] = function(a) result = result .. a end
      load(script,'template','t', sandbox)()
      return result
    end
    
    -- Usage example
    -- @{expression} will print the result of the lua expression
    -- @{{statement}} let you to mix text and lua statement.
    -- in statements you can use o() to output text
    
    print(mint(
      "@{{for i=1,10 do}} hello @{item} @{{for j=1,2 do o'!' end}} \[email protected]{{ end }} .", 
      {item='world'}
    ))
    
    opened by pocomane 2
  • This is a great collection

    This is a great collection

    I stumbled across this collection of routines while looking for a base85 codec. This is a great set of tools, and I've already learned something new: luhn

    Who knew?

    opened by Wiladams 1
  • Feature request: Lambda and Test

    Feature request: Lambda and Test

    I think a good addition to LuaZDF is a compact function definition module (lambda like). I can contribute with a small function (<20 loc) that let you to:

    local l = require 'lambda'
    
    assert( 1 == l'x|x+1'(0) )
    
    -- additional statement, only the last expression is returned
    assert( 2 == l'x|print("c",x);x+1'(1) )
    
    -- default args are a,b,c,d,e,f,...(vararg)
    assert( 1 == l'a+1'(0) )
    
    -- complex lua code (also if this does not really match the use case)
    assert( 550 == l[[ x, y |
      local z = 0
      for i = 1, x do
        z = z + i
      end
      ; z * y
    ]](10,10))
    

    Moreover I have a single function test module, with tap output. I think it has an acceptable usability when used togeter with the previous lambda function:

    local t = require 'tiptap'
    
    t( 'Metatest' ) -- suite name (just output)
    t( 1, 1 ) -- plain comapare
    t( 1, 2 ) -- generic error message
    t( 1, 2, '1 should be equal to 2' ) -- custom error message
    
    -- custom compare function
    empty_table = function(a,b) return #a==#b, "the tables should have  the same number of items" end
    t( {}, {}, empty_table)
    
    -- compact custom compare function
    local l = require 'lambda'
    t( {}, {}, l'#a==#b, "the tables should have the same number of items"')
    t( {}, {}, l'empty_table(a,b), "THE TABLES SHOULD HAVE THE SAME NUMBER OF ITEMS"')
    
    -- test error throw
    local function err() error() end
    t( 1, err, l'not pcall(b), "It should throw an error"' )
    
    t() -- done, print summary
    

    Note that for now only fail message are reported. The successful test just write "ok" and the test number (while for tap a test description could be added).

    Tapered can still be used in the LuaZDF tests. However if internal dependency can be tolerated (just for the tests!), I think this function can substitute tapered.

    If you are interested, I can adapt this two functions to luaZDF standard and make a pull request. Suggestions are welcome to improve the interface of this two functions. E.g. It is better to protect the globals of the lambdas? The multi-use test function API is too confusing?

    PS. Sorry for using the term "Module", but since I was talking about "Function definition" and "Test function", the term "Function" became a bit overused :)

    opened by pocomane 1
Owner
null
Source code for the data dependency part of Jan Kossmann's PhD thesis "Unsupervised Database Optimization: Efficient Index Selection & Data Dependency-driven Query Optimization"

Unsupervised Database Optimization: Data Dependency-Driven Query Optimization Source code for the experiments presented in Chapter 8 of Jan Kossmann's

Jan Koßmann 4 Apr 24, 2022
PikaScript is an ultra-lightweight Python engine with zero dependencies and zero-configuration, that can run with 4KB of RAM (such as STM32G030C8 and STM32F103C8), and is very easy to deploy and expand.

PikaScript 中文页| Star please~ 1. Abstract PikaScript is an ultra-lightweight Python engine with zero dependencies and zero-configuration, that can run

Lyon 906 Dec 29, 2022
oZKS (Ordered Zero-Knowledge Set) is a library that provides an implementation of an Ordered (and Append Only) Zero-Knowledge Set.

Ordered Zero-Knowledge Set - oZKS Introduction oZKS is a library that provides an implementation of an Ordered (and Append Only) Zero Knowledge Set. A

Microsoft 11 Dec 20, 2022
Embed read-only filesystems into any C++11 program w. a single header, zero dependencies and zero modifications to your code

c-embed Embed read-only filesystems into any C++11 program w. a single header, zero dependencies and zero modifications to your code. Usage c-embed al

Nick McDonald 9 Dec 29, 2022
The Lua development repository, as seen by the Lua team. Mirrored irregularly

The Lua development repository, as seen by the Lua team. Mirrored irregularly

Lua 6.4k Jan 5, 2023
Lua functions, recreated

Remade-Lua during 4th August 2021, Roblox decided to use __inline on their lua functions which has destroyed the usage of the addresses, this repo is

Rexi 23 Nov 22, 2022
Libft is an individual project at 42 that requires us to re-create some standard C library functions including some additional ones that can be used later to build a library of useful functions for the rest of the program.

Libft is an individual project at 42 that requires us to re-create some standard C library functions including some additional ones that can be used later to build a library of useful functions for the rest of the program.

Paulo Rafael Ramalho 0 Jan 1, 2023
🦘 A dependency injection container for C++11, C++14 and later

kangaru ?? Kangaru is an inversion of control container for C++11, C++14 and later. It provides many features to automate dependency injection and red

Guillaume Racicot 368 Jan 3, 2023
A small, dependency-free node editor extension for dear imgui.

imnodes A small, dependency-free node editor extension for dear imgui. Features: Create nodes, links, and pins in an immediate-mode style Single heade

Johann Muszynski 1.3k Dec 28, 2022
Because why not? Pi Zero bare metal project that ends in an RTOS implementation

PiZeroRTOS Because why not? This repo starts out as a Pi Zero bare metal project and it could very well end up as a viable RTOS implementation with a

null 7 Feb 13, 2022
Jimp-native is a fast C++ re-implementation of Jimp with zero system dependencies and minimal overhead!

Jimp native Make your sever-side Jimp code run 10x faster! Jimp-native is a fast C++ re-implementation of Jimp with zero system dependencies and minim

Sjoerd 17 Oct 10, 2022
"Zero setup" cross-compilation for a wide variety of architectures.

"Zero setup" cross-compilation for a wide variety of architectures. xcross includes compact docker images and a build utility for minimal setup C/C++ cross-compiling, inspired by rust-embedded/cross

Alexander Huszagh 29 Nov 10, 2022
Zerobug is a 3D-printed micro-servo hexapod robot powered by a Raspberry Pi Zero and a STM32F103

ZeroBug - DIY Hexapod Robot Zerobug is a 3D-printed micro-servo hexapod robot powered by a Raspberry Pi Zero and a STM32F103. The Pi Zero is in charge

Max K 179 Dec 22, 2022
A simpler version of the infamous zero kb virus written in C++.

A simpler version of the infamous zero kb virus written in C++. A few years back I was struck by the 'zero kb' virus, and so i decide to write my own zero kb virus as an act of vengeance (

vincent laizer 3 Sep 19, 2021
Experiments using the RPI Zero GPU for FFT (1D and 2D)

RPI0_GPU_FFT Experiments using the RPI Zero GPU for FFT/IFFT 1D/2D For an input 4194304 (1D), the GPU was around 7X faster than np.fft.fft and np.fft.

Ricardo de Azambuja 30 Nov 15, 2022
My bachelor thesis: Zero-Knowledge Proofs of Innocence From Deterministic Wallets.

This repository contains two programs that implement concepts described in my bachelor thesis. The repository also contains the thesis as a PDF. Use m

null 2 Oct 28, 2021
Ziggified GLFW bindings with 100% API coverage, zero-fuss installation, cross compilation, and more.

mach/glfw - Ziggified GLFW bindings Ziggified GLFW bindings that Mach engine uses, with 100% API coverage, zero-fuss installation, cross compilation,

Hexops 201 Dec 27, 2022
Classic iPod mod with Raspberry Pi Zero and color screen

ipodrpi Classic iPod mod with Raspberry Pi Zero and color screen. Suitable for OSMC and plain Raspbian install. Install OSMC: Burn SD card with Raspbe

null 26 Nov 25, 2022
Side panels for the Voron Zero printer that has 16 WS2812 RGB LED's per side.

Voron Zero RGB Side Panels Side panels for the Voron Zero printer with 16 WS2812 RGB LED's per side. The build below has some 3mm TAP Plastic black LE

Tim Abraham 3 Jul 22, 2022