krieselreihe / litr

Litr (Language Independent Task Runner) lets you configure and then run any tasks you want for any language.
MIT License
8 stars 0 forks source link

Functions inside command scripts #24

Open MartinHelmut opened 3 years ago

MartinHelmut commented 3 years ago

Description

As mentioned in the wiki (https://github.com/krieselreihe/litr/wiki/Quick-Setup#parameter-functions) parameter values can be manipulated via a set of functions (e.g. camel_case). This issue shall serve to explore how this will be implemented, as well as what functions should be built-in.

Ideas

Base

Basic set of built-in functions are:

The way they are written is to give them context (case_*). Not final.

There could also be a lua/run function to execute a Lua file through Litrs Lua version, this could be Lua's dofile function e.g.:

[commands]
build = "${dofile('some/file.lua')}"

Extend

It could be possible for users to define more of those functions via a scripting language (e.g. Lua). Some ideas to this:

Example

There can be one or more Lua files containing functions. All function names will be exposed as Litr script functions.

-- scripts/some_functions.lua
function something_special(value)
  if(value == "special")
  then
    return "yes"
  else
    return "no"
  end
end

Configure this as global option inside Litr config file. The function name will then be available through the user module usr, marking it a user defined function (this will avoid a clash with built-in functions or changes to those in the future).

# litr.toml

[options]
scripts = ["scripts/*.lua"]

[commands]
build = "cmake -DIS_SPECIAL=${usr.something_special(something)}"

[params]
something = "..."

Utilising direnv and LUA_INIT could give the user support for own Lua modules.