Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Functions inside command scripts #24

Open
MartinHelmut opened this issue Mar 15, 2021 · 0 comments
Open

Functions inside command scripts #24

MartinHelmut opened this issue Mar 15, 2021 · 0 comments
Labels
documentation Improvements or additions to documentation. feature Something new. question Further information is requested / general question.
Milestone

Comments

@MartinHelmut
Copy link
Member

MartinHelmut commented Mar 15, 2021

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:

  • case_pascal - Transform the value to PascalCase
  • case_camel - Transform the value to camelCase
  • case_snake - Transform the value to snake_case
  • case_kebab - Transform the value to kebab-case

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:

  • Lua as it is easy to integrate and small in size.
  • Functions cannot override built-in functions.
  • Functions can only return string or boolean values. Everything else will be cast to a string.
  • Script folder could be defined via a global option (global options do not exist, yet).
  • Built-in functions could be defined this way as well.

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.

@MartinHelmut MartinHelmut added documentation Improvements or additions to documentation. question Further information is requested / general question. feature Something new. labels Mar 15, 2021
@MartinHelmut MartinHelmut added this to the Version 1 milestone Mar 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation. feature Something new. question Further information is requested / general question.
Projects
None yet
Development

No branches or pull requests

1 participant