diff options
| author | Bruce Hill <bitbucket@bruce-hill.com> | 2017-11-01 15:58:19 -0700 |
|---|---|---|
| committer | Bruce Hill <bitbucket@bruce-hill.com> | 2017-11-01 15:58:19 -0700 |
| commit | cbd876673a4accc23aca16c015c20b819a2685b5 (patch) | |
| tree | b8f8e2a5ed6e92affc52a08f8c01b8b7a463f919 /lib | |
| parent | 8c7915e466e3bd8499c00fce6d6ffd2bebf310f5 (diff) | |
Added gsub.
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/utils.nom | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/lib/utils.nom b/lib/utils.nom index c65ac2a..b398827 100644 --- a/lib/utils.nom +++ b/lib/utils.nom @@ -22,6 +22,11 @@ parse [join %strs] as: join %strs with glue "" compile [capitalize %str, %str capitalized] to: "(\(%str as lua)):gsub('%l', string.upper, 1)" +compile [%str with %patt replaced with %sub, %str s/%patt/%sub] to: + "((\(%str as lua)):gsub(\(%patt as lua), \(%sub as lua)))" +compile [%str with %patt replaced with %sub %n times, %str s/%patt/%sub/%n] to: + "((\(%str as lua)):gsub(\(%patt as lua), \(%sub as lua), \(%n as lua)))" + compile [say %str] to: ".." |nomsu:writeln(nomsu:stringify(\(%str as lua))) @@ -42,6 +47,7 @@ rule [random choice from %elements, random choice %elements, random %elements] = =lua "\(%elements)[math.random(#\(%elements))]" # Math functions +compile [% as number] to: "tonumber(\(% as lua))" compile [abs %, absolute value of %, | % |] to: "math.abs(\(% as lua))" compile [sqrt %, square root of %] to: "math.sqrt(\(% as lua))" compile [sin %, sine %] to: "math.sin(\(% as lua))" |
